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

fix(sanitizeUri): sanitize URIs that contain IDEOGRAPHIC SPACE chars #16311

Merged

Conversation

petebacondarwin
Copy link
Member

Chrome 62 was not sanitizing dangerous URLs containing
JavaScript, if they started with these "whitespace" characters.

Closes #16288

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

fix

What is the current behavior? (You can also link to an open issue here)

#16288

What is the new behavior (if this is a feature change)?

URIs are sanitized correctly on Chrome 62

Does this PR introduce a breaking change?

No

Please check if the PR fulfills these requirements

Other information:

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

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

We should make sure tests like that run in all supported browsers, not just Chrome.

@petebacondarwin
Copy link
Member Author

I have removed the isChrome condition

@mgol
Copy link
Member

mgol commented Nov 1, 2017

The commit message is too long & it makes the build fail.

@Narretz
Copy link
Contributor

Narretz commented Nov 1, 2017

I'm not sure if the description in this fix is 100% correct.
I've tested current Firefox, Chrome 62, 61, and 45 (version when the mxss fix was added), and Edge - none of these browsers execute javascript when it is preceeded by the IDEOGRAPHIC SPACE character.
http://plnkr.co/edit/DsOav9IHEdS5enbCxKsG?p=preview

So either the test is wrong, or the description is wrong (the string in the test is not dangerous, because it is not executed).

I think it makes sense to explicitly trim the string before sanitizing it though. The description should be more precise though.

@petebacondarwin
Copy link
Member Author

@Narretz - you have to apply the "evil" text via innerHTML for the vulnerability to become apparent. This is due to mutation that browsers do when updating the DOM via this property. Hence the "m" in mXSS.

You can see it happening on Chrome 61 here: https://plnkr.co/edit/Y6EsbsuDgd18YTn1oARu?p=preview

Background: http://www.nds.rub.de/media/emma/veroeffentlichungen/2013/12/10/mXSS-CCS13.pdf

@Narretz
Copy link
Contributor

Narretz commented Nov 2, 2017

@petebacondarwin Thanks for clarifying. The part about innerHTML and the link should be a code comment or part of the commit message.

@petebacondarwin
Copy link
Member Author

@Narretz :-( after I just got Travis to go green too

Browsers mutate attributes values such as `&angular#12288;javascript:alert(1)`
when they are written to the DOM via `innerHTML` in various vendor specific
ways.

In Chrome (<62), this mutation removed the preceding "whitespace" resulting
in a value that could end up being executed as JavaScript.

Here is an example of what could happen:
https://plnkr.co/edit/Y6EsbsuDgd18YTn1oARu?p=preview
If you run that in Chrome 61 you will get a dialog box pop up.

There is background here:
http://www.nds.rub.de/media/emma/veroeffentlichungen/2013/12/10/mXSS-CCS13.pdf

The sanitizer has a bit of code that triggers this mutation on an inert piece
of DOM, before we try to sanitize it:
https://github.com/angular/angular.js/blob/817ac567/src/ngSanitize/sanitize.js#L406-L417

Chrome 62 does not appear to mutate this particular string any more, instead
it just leaves the "whitespace" in place. This probably means that Chrome 62
is no longer vulnerable to this specific attack vector; but there may be
other mutating strings that we haven't found, which are vulnerable.

Since we are leaving the mXSS check in place, the sanitizer should still
be immune to any strings that try to utilise this attack vector.

This commit uses `trim()` to remove the IDEOGRAPHIC SPACE "whitespace"
before sanitizing, which allows us to expose this mXSS test to all browsers
rather than just Chrome.

Closes angular#16288
@petebacondarwin
Copy link
Member Author

I updated the commit message

@Narretz
Copy link
Contributor

Narretz commented Nov 2, 2017

LGTM

@petebacondarwin petebacondarwin merged commit 667db46 into angular:master Nov 3, 2017
@petebacondarwin petebacondarwin deleted the sanitize-mxss-issue-16288 branch November 3, 2017 10:16
expectHTML('<a href="&#x3000;javascript:alert(1)">CLICKME</a>').toBe('<a>CLICKME</a>');
});
}
it('should prevent mXSS attacks', function() {
Copy link
Member

Choose a reason for hiding this comment

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

TBH, I don't think this test does what it says it does, but that is not related to this PR (it was like that before).
(It is more like it should not be too strict in preventing mXSS aattacks 😃)

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.

Test failure on Chrome 62
5 participants