Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix($sanitize): don't allow svg animation tags #11290

Closed

Conversation

rodyhaddad
Copy link
Contributor

After #11124 got merged, a security vulnerability got introduced.
Animation in SVG became tolerated by the sanitizer.

Exploit Example:

<svg>
  <a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?">
    <circle r="400"></circle>
    <animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" />
  </a>
</svg>

Here we are animating an anchor's href, starting from a value that's a javascript URI,
allowing the executing of arbitrary javascript in the process.

Preventing only the animation of links is tricky, as SVG is weird and namespaces aren't predictable.
We've decided to have the sanitizer filter out SVG animation tags instead.

Considering the sanitizer is commonly used to sanitize untrusted HTML code, this shouldn't affect
many apps in the wild. Also, no release has been with #11124 in it, but not this fix.

@rodyhaddad
Copy link
Contributor Author

/cc @sirdarckcat

"desc,ellipse,font-face,font-face-name,font-face-src,g,glyph,hkern,image,linearGradient," +
"line,marker,metadata,missing-glyph,mpath,path,polygon,polyline,radialGradient,rect,set," +
"stop,svg,switch,text,title,tspan,use");
var svgElements = makeMap("circle,defs,desc,ellipse,font-face,font-face-name,font-face-src,g,glyph," +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment that the animation related elements are intentionally omitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@IgorMinar
Copy link
Contributor

also the fix commit contains a breaking change that should be documented per our conventions.

otherwise this looks good for master branch.

for 1.3 we should just revert the other fix that adds case-sensitivity support.

@petebacondarwin
Copy link
Member

Do we need to block <animate> element altogether. I thought we were able to simply block attributeName and attributeType attributes (case-sensitive)?

If we did this, then we would not have a breaking change, since previously we were lowercasing those attributes, which was effectively blocking them anyway...

@lgalfaso
Copy link
Contributor

+1 to @petebacondarwin solution

@rodyhaddad
Copy link
Contributor Author

From my research the only way to animate something is using the attributeName attribute.

So blocking [attributeName] or blocking <animate /> has the same effect: preventing animation functionality from passing through the sanitizer.

I personally believe blocking the element is better than blocking the attribute. It's easier to "debug" for a developer imo.


I didn't mark it as a breaking change because animation were never possible in SVG before #11124, which has yet to be released in a version.

Adding the breaking change will just make it appear in the ChangeLog and our migration guide, and it will be "useless" because there is no prior angular version that allows SVG animations.

@rodyhaddad rodyhaddad force-pushed the fix/security-sanitize-svg branch 2 times, most recently from 3f6f561 to 91fd8b2 Compare March 11, 2015 21:40
After angular#11124 got merged, a security vulnerability got introduced.
Animation in SVG became tolerated by the sanitizer.

Exploit Example:
```
<svg>
  <a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?">
    <circle r="400"></circle>
    <animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" />
  </a>
</svg>
```

Here we are animating an anchor's href, starting from a value that's a javascript URI,
allowing the executing of arbitrary javascript in the process.

Preventing only the animation of links is tricky, as SVG is weird and namespaces aren't predictable.
We've decided to have the sanitizer filter out svg animation tags instead.

Considering the sanitizer is commonly used to sanitize untrusted HTML code, this shouldn't affect
many apps in the wild. Also, no release has been with angular#11124 in it, but not this fix.
@rodyhaddad
Copy link
Contributor Author

For now I've removed the following elements:
animate, animateColor, animateMotion, animateTransform, set

And the following attributes, because they're useless with the above tags removed:
attributeName, attributeType

@cure53
Copy link

cure53 commented Mar 11, 2015

I agree, <set> and <animate> should be blocked completely. Nothing good comes out of those two elements and according to our research, usage across e.g. Wikipedia SVGs is very very low.

Sources:

@petebacondarwin
Copy link
Member

LGTM

@petebacondarwin
Copy link
Member

I landed this on master and added the commit with the warning messages to 1.3.x. I didn't land the security fix since we never seemed to have landed the original mixed case fix in the first place there.

@cure53
Copy link

cure53 commented Mar 16, 2015

Just one small note: We have not yet managed to identify any attack surface coming from animateColor, animateMotion and animateTransform. They don't permit declarative changes on arbitrary attributes but have their own, specific and limited space for changes.

Unless (of course) you have attack examples that also work in these, I would go and say they are safe. Well, two of them. Note that animateColor (that would have had exploitation potential) is flagged deprecated and not supported by FF, IE or Chrome (or the respected browser engines).

@petebacondarwin
Copy link
Member

To stay on the safe side I would prefer to wait for people to request that these elements are white listed and look at this again, then.

@cure53
Copy link

cure53 commented Mar 17, 2015

@petebacondarwin Agreed, makes perfect sense!

netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
After angular#11124 got merged, a security vulnerability got introduced.
Animation in SVG became tolerated by the sanitizer.

Exploit Example:
```
<svg>
  <a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?">
    <circle r="400"></circle>
    <animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" />
  </a>
</svg>
```

Here we are animating an anchor's href, starting from a value that's a javascript URI,
allowing the executing of arbitrary javascript in the process.

Preventing only the animation of links is tricky, as SVG is weird and namespaces aren't predictable.
We've decided to have the sanitizer filter out svg animation tags instead.

Considering the sanitizer is commonly used to sanitize untrusted HTML code, this shouldn't affect
many apps in the wild. Also, no release has been with angular#11124 in it, but not this fix.

Closes angular#11290
tonytw1 pushed a commit to guardian/grid that referenced this pull request Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants