fix(compiler): add URL sanitization for SVG animation value attributes#67927
Closed
mohammadmseet-hue wants to merge 1 commit intoangular:mainfrom
Closed
fix(compiler): add URL sanitization for SVG animation value attributes#67927mohammadmseet-hue wants to merge 1 commit intoangular:mainfrom
mohammadmseet-hue wants to merge 1 commit intoangular:mainfrom
Conversation
The SVG animation elements (`<animate>`, `<set>`, `<animateMotion>`, `<animateTransform>`) have their `attributeName` binding correctly blocked via `SecurityContext.ATTRIBUTE_NO_BINDING` to prevent attackers from choosing which attribute to animate. However, the value attributes (`to`, `from`, `values`, `by`) that carry the actual data written to the animated attribute have `SecurityContext.NONE` — no URL sanitization is applied. When a developer uses `attributeName="href"` (statically) and binds the animation value to user-controlled data (e.g. `[attr.to]="url"`), an attacker can inject `javascript:` URIs that execute when the user clicks the animated SVG link. This is confirmed to execute in Chromium, Firefox, and Safari. This commit adds all SVG animation value attributes to the `SecurityContext.URL` section of the DOM security schema. The URL sanitizer only blocks dangerous schemes (`javascript:`, `vbscript:`, `data:`) — it will not break legitimate animation values such as colors, numbers, or transform strings.
Contributor
|
Duplicate of #67797 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The SVG animation elements (
<animate>,<set>,<animateMotion>,<animateTransform>) have theirattributeNamebinding correctly blocked viaSecurityContext.ATTRIBUTE_NO_BINDING(seeb/463880509#comment7). However, the value attributes (to,from,values,by) — which carry the actual data written to the animated attribute — haveSecurityContext.NONE. No URL sanitization is applied to them.When a developer uses a static
attributeName="href"and binds an animation value to user-controlled data (e.g.[attr.to]="url"), an attacker can injectjavascript:URIs that execute when the user clicks the animated SVG link.The Bug
Angular compiles
[attr.to]withSecurityContext.NONEbecauseset|tois not in the security schema:The
javascript:URI passes through unsanitized. The SVG animation engine writes it to the parent<a>element'shref.animVal. Clicking the link executes JavaScript.Compare with a standard
<a>element, which is correctly sanitized:<a [attr.href]="evil">javascript:alert(1)unsafe:javascript:alert(1)<set attributeName="href" [attr.to]="evil">javascript:alert(1)javascript:alert(1)Browser Verification
Confirmed in Chromium 136. Clicking an SVG
<a>element whosehrefwas set via<set attributeName="href" to="javascript:alert(document.domain)">triggered JavaScript execution, displaying"localhost".Both
<set>and<animate>vectors execute in Chrome, Firefox, and Safari.The Fix
This commit adds all SVG animation value attributes to the
SecurityContext.URLsection ofdom_security_schema.ts:The URL sanitizer only blocks dangerous schemes (
javascript:,vbscript:,data:) — it will not break legitimate animation values such as colors, numbers, or transform strings.References
http://b/463880509#comment7<set>spec: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/set<animate>spec: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/animate