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

REVIEW: Fix for bypass in Firefox thanks to a newly discovered mXSS #94

Closed
cure53 opened this issue Sep 17, 2015 · 13 comments
Closed

REVIEW: Fix for bypass in Firefox thanks to a newly discovered mXSS #94

cure53 opened this issue Sep 17, 2015 · 13 comments

Comments

@cure53
Copy link
Owner

cure53 commented Sep 17, 2015

Hi @neilj and @fhemberger!

Today I ran into a mXSS issue on latest Gecko that causes a bypass under certain conditions. The problem is, that Firefox shows different behavior for innerHTML interaction than any other browser when doing that in an SVG context. I talked to @freddyb of Mozilla and we developed a fix.

The mXSS bug in Firefox causes a bypass when the sanitized HTML is later not being applied with innerHTML but with document.write() or alike. From a security standpoint, I find this to be close to critical. The cause for this issue is a parser behavior change in Gecko when dealing with HTML elements inside inline SVG documents. I will publish the attack vector after the fix has been reviewed (contact me offline for a PoC).

This fix might however be breaking so I'd love to hear your opinion. The tests are green and things look okay - but better to have that one triple-checked:

Changeset
https://github.com/cure53/DOMPurify/compare/DOMParser?expand=1

Test Results
https://travis-ci.org/cure53/DOMPurify/builds/80807894

Opinions are welcome!

Cheers,
.mario

@fhemberger
Copy link
Contributor

If it's a breaking change, that means this should be a 1.0.0 release (semver-major). And the reason for it should be documented. What browsers could break by switching from document.implementation.createHTMLDocument to window.DOMParser?

@cure53
Copy link
Owner Author

cure53 commented Sep 17, 2015

It might be a breaking change but I hope it's not, hence my review request :) So far it looks like it's not - but I cannot judge that on my own.

@fhemberger
Copy link
Contributor

If all the browser tests are green, it seems to work … I'm sorry, but at some point you lost me with all the DOM voodoo going on. I must admit, I'm not that much into that particular topic to be of much help here. (Especially after exclusively working on the server side the last 14+ months.) ;)

@cure53
Copy link
Owner Author

cure53 commented Sep 17, 2015

Aye, okay :) Are the code conventions all met? If so, I'd merge and prepare a release.

@mozfreddyb
Copy link
Contributor

s/@freddyb/@mozfreddyb ;-)

@fhemberger
Copy link
Contributor

LGTM

@cure53
Copy link
Owner Author

cure53 commented Sep 17, 2015

Thx. I am preparing the 0.6.7 release now.

@cure53 cure53 closed this as completed Sep 17, 2015
@koto
Copy link
Contributor

koto commented Apr 18, 2016

So, what was the bypass?

@cure53
Copy link
Owner Author

cure53 commented Apr 18, 2016

It was documented along with the release:

https://github.com/cure53/DOMPurify/releases/tag/0.6.7

<script>
// This is SAFE (but shouldn't be!)
document.body.innerHTML='<svg><p><style><img src="</style><img src=x onerror=alert(1)//">'
</script>


<script>
// This is UNSAFE
document.write('<svg><p><style><img src="</style><img src=x onerror=alert(1)//">')
</script>

@mozfreddyb
Copy link
Contributor

I think it was mentioned in the release notes, here's the issue discussed in Bugzilla:
https://bugzilla.mozilla.org/show_bug.cgi?id=1205631

@cure53
Copy link
Owner Author

cure53 commented Apr 18, 2016

@mozfreddyb "discussed" :)

The issue is still existing, FF is still unreliable and delivers broken innerHTML.
DOMPurify patches around it successfully - but we had to change a lot for that.

@mozfreddyb
Copy link
Contributor

Seems like a spec problem to me. shrugs
document.write was invented when HTML parsing wasn't properly defined.
You may have also gotten better results when supplying a doctype prior to your .write().

@cure53
Copy link
Owner Author

cure53 commented Apr 18, 2016

Nope, it's a Firefox problem :)

FF doesn't properly handle innerHTML in the SVG context. Even MSIE does it right :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants