-
Notifications
You must be signed in to change notification settings - Fork 31
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
Update "javascript:" handling; esp. SVG animation and MathML href. #212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cure53 do you know why DOMPurify bans all SVG animation? Do you know other maintainers we can reach out to?
index.bs
Outdated
1. If the [=animating URL attributes list=] [=SanitizerConfig/contains=] | ||
«[|elementName|, |attrName|]» and |attr|'s | ||
[=get an attribute value|value=] [=string/is=] "`href`" or | ||
"`xlink:href`": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should double check that xlink:href
is actually meaningful as it supposedly only works when xmlns
puts xlink
in scope which is never the case in HTML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xlink:href
works in HTML regardless of namespace declarations. https://html.spec.whatwg.org/multipage/parsing.html#adjust-foreign-attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zcorpan that is xlink:href
as an attribute, but not as an attribute value of these SVG attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Still, xmlns:xlink
is also an adjusted attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, so it should work when xmlns:xlink
is also specified. In which case we want to always ban xlink:href
as is suggested here. (Having tests for all these combinations would be good though.)
I guess the other piece of feedback I forgot to note down here is that we should make sure we have the same processing model as these attributes have today, which regards to splitting on whitespace and such.
I believe the reason is that you can use SVG animation to animate For example: <svg>
<animate xlink:href=#x
attributeName=href
values=javascript:alert(1) />
<a id=x>
<text x=10 y=10>
Click me
</text>
</a> |
@securityMB thanks for weighing in! This PR attempts to tackle that in a more specific way, allowing generic animation features to continue to work. We are wondering if that is good enough or if we'll run into other trouble. |
Trusted types covers the SVGAnimatedString IDL type, which covers you updating an SVGScriptElement hrefs baseVal, and it also includes the So I think if sanitizer is stripping the |
@lukewarlow no, see the example above: #212 (comment). We cannot rely on the navigation check Trusted Types has here. We need something along the lines of this PR or ban SVG animation entirely, but that seems less well founded. |
Sorry to clarify I didn't mean to rely on TT for anything I was just providing context on what TT does for this area. |
I wrote a test to figure out what browsers will actually do...
[Edit: In HTML documents, Chrome & Safari will animate "xlink:href", but only if there's an explicit |
f8f8ef2
to
7b5fe3f
Compare
The current version now does this:
I think this covers all cases we have discovered. Presently, this just non-chalantly states the algorithm. Should I add a note and/or appendix that explains how we got there, in case someone else wants to understand what the point is? |
index.bs
Outdated
|
||
</div> | ||
|
||
<div class=note> | ||
<span class=marker>Note:</span> Current browsers support `javascript` URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this javascript:
URLs throughout (including the :
), including in definitions. I think that's more consistent with how we approach this elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good now, modulo nits. It's unfortunate we have to invoke the URL parser though, but I guess so be it. We never said that safe was going to be cheap.
fa31d18
to
65b8fee
Compare
In the meeting, we had briefly discussed what the support for MathML + href + javascript: was. It seems there's already WPT tests for this: https://wpt.fyi/results/mathml/relations/html5-tree?label=master&label=experimental&aligned&q=mathml%2Frelations%2Fhtml5-tree%2Fhref-click href-click-003.tentative.html tests navigating to a |
3bc2e48
to
252a614
Compare
Since this PR was quasi-abandoned, I've rebased and (partially) re-written it. Also, instead of the usual chronological commit history, this is now seperated out in semantically meaninfgul, seperate commits, that can also be reviewed seperately.
|
252a614
to
7de7d50
Compare
7de7d50
to
26f83ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me modulo some nits.
SVG supports declarative animations, including animations of href attributes. This can lead to XSS, if an element is navigated to a JavaScript URL.
26f83ee
to
7134494
Compare
Preview | Diff