Skip to content

Commit 10e9adb

Browse files
authored
Update explainer.md
1 parent 5b4a8fd commit 10e9adb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

explainer.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ The intention is to allow for a gradual migration of the code from strings towar
189189
Please check the [specification draft](https://w3c.github.io/webappsec-trusted-types/dist/spec/#default-policy-hdr) for details.
190190

191191

192-
#### javascript: URLs
192+
### javascript: URLs
193193

194194
Using `javascript:` URLs as a payload for DOM XSS exploitation is quite common. At the same time,
195195
there are many sinks in the platform that accept URLs, and it would be prohibitive for the authors to have to r
@@ -288,3 +288,20 @@ controls in their application even if it occasionally uses `javascript:` URLs fo
288288
attribute DOMString textContent;
289289
};
290290
```
291+
292+
## Adopting Trusted Types
293+
294+
With the API described as above, the application may protect itself against DOM XSS using the following approach:
295+
296+
1. Identify the places where the injection sinks are being used (e.g. with `Content-Security-Policy-Report-Only: require-trusted-types-for 'script'; report-uri /csp`). Apart from `innerHTML`, these are usually places responsible for dynamic script loading, JSONP, or HTML sanitization and templating.
297+
298+
2. Rewrite those places to use Trusted Types instead, via dedicated policies. Where appropriate, move the sanitization and
299+
filtering logic to the policies. Where possible, enable the use of policies in your dependencies and rewrite legacy code
300+
not to use the sinks when unneccessary.
301+
302+
3. (Optional) Create a default policy to address direct sink usage in 3rd party dependencies.
303+
304+
4. Enforce Trusted Types at DOM XSS sinks, changing the report-only CSP to an enforcing one. From now on
305+
only the trusted types policies can introduce DOM XSS.
306+
307+
5. (Optional) Guard policy creation by using `trusted-types` directive.

0 commit comments

Comments
 (0)