Packages / dompurify / Security
DOMPurify IN_PLACE Sanitization Bypass via Attached Shadow Root Inside <template>.content
Affected releases · dompurify
- 3.x3.0.0 – 3.4.6Fixed in 3.4.7
- 2.x2.0.0 – 2.5.9No fix on this line yet
- 1.x and older0.4.0 – 1.1.1No fix, no longer updated
On 3.x, the newest line:
npm install dompurify@3.4.7Affected
3.0.0 – 3.4.6
39 releases
Fixed
3.4.7 – 3.4.17
11 releases, latest
Affected
2.0.0 – 2.5.9
63 releases
Affected
1.0.0 – 1.1.1
14 releases
Affected
0.4.0 – 0.9.0
29 releases
Is your project affected?
Paste your package.json, or type the range you declare for dompurify. It is read in your browser and sent nowhere.
What happens
If the HTML you give it contains a <template> element, and inside that template there's an element with a shadow DOM attached to it, DOMPurify quietly skips over the shadow contents. Whatever the attacker put in there - an image with an onerror handler, a link with a javascript: URL, even a full script - survives untouched. The moment the application uses that template the way templates are meant to be used (cloning it and inserting the result into the page), the malicious payload comes along and runs as if it had never been sanitized. From there an attacker gets everything XSS normally gets them: session cookies, stored tokens, the ability to act as the user, and the ability to leave persistent payloads behind for the next person who visits.