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

fix($sanitize): blacklist SVG <use> elements #13453

Closed
wants to merge 1 commit into from

Conversation

petebacondarwin
Copy link
Contributor

The use element can reference external svg's (same origin) and can include
xlink javascript urls or foreign object that can execute xss.

This change disallows <use> elements in sanitized SVG markup.

An example of a malicious SVG document would be:

SVG to sanitize:

<svg><use xlink:href="test.svg#xss" /></svg>

External SVG file (test.svg)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg" width="100"
   height="100"
   id="xss">
<a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="javascript:alert(1)">
  <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</a>
</svg>

Here the SVG to sanitize loads in the test.svg file via the <use> element.
The sanitizer is not able to parse this file, which contains malicious
executable mark-up.

This can only be taken advantage of if the external file is available via the
same origin restrictions in place.

The use element can reference external svg's (same origin) and can include
xlink javascript urls or foreign object that can execute xss.

This change disallows `<use>` elements in sanitized SVG markup.

An example of a malicious SVG document would be:

SVG to sanitize:
```
<svg><use xlink:href="test.svg#xss" /></svg>
```

External SVG file (test.svg)
```
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg" width="100"
   height="100"
   id="xss">
<a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="javascript:alert(1)">
  <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</a>
</svg>
```

Here the SVG to sanitize loads in the `test.svg` file via the `<use>` element.
The sanitizer is not able to parse this file, which contains malicious
executable mark-up.

This can only be taken advantage of if the external file is available via the
same origin restrictions in place.
@lgalfaso
Copy link
Contributor

lgalfaso commented Dec 5, 2015

LGTM

On Saturday, December 5, 2015, Pete Bacon Darwin [email protected]
wrote:

The use element can reference external svg's (same origin) and can include
xlink javascript urls or foreign object that can execute xss.

This change disallows elements in sanitized SVG markup.

An example of a malicious SVG document would be:

SVG to sanitize:

External SVG file (test.svg)





Here the SVG to sanitize loads in the test.svg file via the element.
The sanitizer is not able to parse this file, which contains malicious
executable mark-up.

This can only be taken advantage of if the external file is available via
the

same origin restrictions in place.

You can view, comment on, or merge this pull request online at:

#13453
Commit Summary

  • fix($sanitize): blacklist SVG <use> elements

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#13453.

@petebacondarwin
Copy link
Contributor Author

Easy one :-) Does it need a breaking change notice?

@IgorMinar
Copy link
Contributor

Add breaking change note please. Otherwise lgtm

@Coridyn
Copy link

Coridyn commented Apr 7, 2016

We use the <use> element to reference SVG content defined on the page (e.g. as an alternative to Glyphicons):

<a href="#"><svg class="icon"><use xlink:href="#icon-call"></use></svg> Give us a call</a>

Would it be possible to opt in to <use> elements, allow local-only references (like above), or share the $compileProvider.imgSrcSanitizationWhitelist when sanitizing this sort of content?

Alternatively, are you aware of any workaround we could use without having to use trustAsHtml()?

@petebacondarwin
Copy link
Contributor Author

@Coridyn perhaps you could come up with a custom directive so you are not placing svg directly in the bound HTML content?

@Coridyn
Copy link

Coridyn commented Apr 8, 2016

@petebacondarwin The SVG is coming from user-editable content so I don't think that's possible.

Does running the content through $compile has the same security implications as using trustAsHtml()?

@petebacondarwin petebacondarwin deleted the svg-use-fix branch November 24, 2016 09:16
maistro-nathaniel-wooding added a commit to maistro-plc/angular.js that referenced this pull request Jun 7, 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.

4 participants