Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrubber removes crucial SVG 1.1 elements #107

Open
stanhu opened this issue Mar 29, 2016 · 6 comments
Open

Scrubber removes crucial SVG 1.1 elements #107

stanhu opened this issue Mar 29, 2016 · 6 comments
Labels
allowlist issues related to what tags or attributes are allowed needs more information
Milestone

Comments

@stanhu
Copy link

stanhu commented Mar 29, 2016

The current sanitizer strips out crucial SVG 1.1 elements (e.g. style) and doesn't take into account the full mapping of allowed attributes and elements. I wrote a custom Loofah scrubber here that does this:

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3401/diffs

Is there interest in making this part of the Loofah package?

@flavorjones
Copy link
Owner

Hi,

Thanks for opening this issue. I'm open to discussing this.

I need to better understand what you're suggesting. Can you please fully explain the document type (preferably with an example) and the attributes you're using? You haven't provided much information here, and the merge request you linked to is a bit hard to follow.

@stanhu
Copy link
Author

stanhu commented Mar 30, 2016

Yes, take a look at this SVG file, as taken from this issue.

https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/wordmark/stacked_wm.svg

If you run this file through Loofah, the resulting image is a big black blob, nothing like the original. Why? The default Loofah scrubber only has style whitelisted as an attribute, not an element, while the SVG 1.1 spec says that it can be a full-fledged element. There are numerous other examples that illustrate the same issue for different reasons.

Now we could simply just add all the SVG 1.1 elements into the whitelist and be done with it. But since the spec clearly specifies which attributes are allowed for which elements, I went a step further and made the Loofah scrubber obey those rules. That's what the aforementioned merge request does.

@stanhu
Copy link
Author

stanhu commented Apr 19, 2016

@flavorjones, can you take a look here?

@Hampei
Copy link

Hampei commented Sep 27, 2016

I walked into this as well, but if you use inline svg, the style element is indeed a risk, since it can affect anything on the page.
We moved to using data-urls for svg and just added the style element to the list of safe elements.

Loofah::HTML5::WhiteList::SVG_ELEMENTS.add 'style'
Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS.add 'style'
Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS_WITH_LIBXML2.add 'style'

@flavorjones flavorjones added the allowlist issues related to what tags or attributes are allowed label Oct 27, 2018
@flavorjones
Copy link
Owner

Noting here for posterity that this would be addressed by #155 if we used DOMPurify's allowlists.

@flavorjones flavorjones added this to the v3.0.0 milestone Sep 28, 2019
@GeoffTidey
Copy link

GeoffTidey commented Mar 13, 2024

Had a similar issue with a SVG that had a style including 'stroke-miterlimit'

Loofah::HTML5::SafeList::ALLOWED_SVG_PROPERTIES.add 'stroke-miterlimit'

has fixed it for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
allowlist issues related to what tags or attributes are allowed needs more information
Projects
None yet
Development

No branches or pull requests

4 participants