{"id":"CVE-2026-65899","aliases":["CVE-2026-65899","GHSA-vxr8-fq34-vvx9"],"related":[],"kind":"vulnerability","state":"published","title":"DOMPurify before 3.4.9 Trusted Types Policy State Contamination","summary":"DOMPurify 3.0.0 before 3.4.9 does not reset the retained Trusted Types policy when clearConfig() is called, so a DOMPurify instance reused across trust boundaries stays bound to a previously supplied TRUSTED_TYPES_POLICY. A later caller that requests RETURN_TRUSTED_TYPE output receives a TrustedHTML object created by the old (potentially unsafe) policy rather than a clean default, which can lead to script execution at a Trusted Types sink. Passing TRUSTED_TYPES_POLICY: null on the later call also does not clear the retained policy.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"DOMPurify 3.0.0 before 3.4.9 does not reset the retained Trusted Types policy when clearConfig() is called, so a DOMPurify instance reused across trust boundaries stays bound to a previously supplied TRUSTED_TYPES_POLICY. A later caller that requests RETURN_TRUSTED_TYPE output receives a TrustedHTML object created by the old (potentially unsafe) policy rather than a clean default, which can lead to script execution at a Trusted Types sink. Passing TRUSTED_TYPES_POLICY: null on the later call also does not clear the retained policy.","source":"cvelist"},{"lang":"en","text":"## Impact\n\nA DOMPurify instance that is reused across trust boundaries can stay bound to a previously supplied `TRUSTED_TYPES_POLICY` even after `clearConfig()` is called. A later caller that requests `RETURN_TRUSTED_TYPE` receives a `TrustedHTML` object created by the old policy, not by a clean default configuration.\n\nIf the old policy is unsafe or controlled by a less-trusted integration, this turns a later \"default\" sanitize call into script execution at a Trusted Types sink. `TRUSTED_TYPES_POLICY: null` on the later call also does not clear the retained policy.\n[dompurify-trusted-types-policy-survives-clearconfig-poc.js](https://github.com/user-attachments/files/28604913/dompurify-trusted-types-policy-survives-clearconfig-poc.js)\n\n\n## Affected version\n\nTested against DOMPurify `3.4.8`, repository commit `825e617753ac1169306a542d3174a77f717a0cf6`.\n\n## Root cause\n\n`_parseConfig()` overwrites `trustedTypesPolicy` when `cfg.TRUSTED_TYPES_POLICY` is truthy, but the default/null path only initializes the internal policy when `trustedTypesPolicy === undefined`. Once a custom policy has been set, later default config parsing leaves it in place.\n\nRelevant code:\n\n- `src/purify.ts:786-812` accepts and stores `cfg.TRUSTED_TYPES_POLICY`.\n- `src/purify.ts:813-832` does not reset an existing policy when config has no policy or has `TRUSTED_TYPES_POLICY: null`.\n- `src/purify.ts:2123-2125` signs the final serialized HTML with the retained policy when `RETURN_TRUSTED_TYPE` is true.\n- `src/purify.ts:2133-2136` `clearConfig()` only clears `CONFIG` and `SET_CONFIG`; it does not reset `trustedTypesPolicy` or `emptyHTML`.\n\n## Local PoC\n\nRun from the DOMPurify checkout, or set `DOMPURIFY_REPO`:\n\n```bash\nnode /home/dompurify-trusted-types-policy-survives-clearconfig-poc.js\n```\n\nObserved output:\n\n```json\n{\n  \"result\": {\n    \"baseline\": \"<b>baseline</b>\",\n    \"duringPolicy\": \"<img src=x onerror=alert(\\\"TT_POLICY_SURVIVED_CLEARCONFIG\\\")>\",\n    \"afterClearString\": \"<img src=\\\"x\\\">\",\n    \"afterClearTrustedType\": \"[object TrustedHTML]\",\n    \"afterClearTrusted\": \"<img src=x onerror=alert(\\\"TT_POLICY_SURVIVED_CLEARCONFIG\\\")>\",\n    \"afterNullTrusted\": \"<img src=x onerror=alert(\\\"TT_POLICY_SURVIVED_CLEARCONFIG\\\")>\",\n    \"mountedHTML\": \"<img src=\\\"x\\\" onerror=\\\"alert(&quot;TT_POLICY_SURVIVED_CLEARCONFIG&quot;)\\\">\"\n  },\n  \"dialogs\": [\n    \"TT_POLICY_SURVIVED_CLEARCONFIG\"\n  ]\n}\n```\n\nThe important part is the split behavior after cleanup:\n\n- `purify.clearConfig(); purify.sanitize(...);` returns a normal sanitized string (`<img src=\"x\">`), because the later call is not asking for a Trusted Type.\n- `purify.clearConfig(); purify.sanitize(..., { RETURN_TRUSTED_TYPE: true });` still uses the old policy and returns attacker-controlled `TrustedHTML`.\n- Passing `{ TRUSTED_TYPES_POLICY: null, RETURN_TRUSTED_TYPE: true }` also still returns attacker-controlled `TrustedHTML`.\n\n## Preconditions\n\nThis is a shared-instance state contamination issue. It matters when one DOMPurify instance is reused by multiple integrations, plugins, request handlers, or components with different trust levels, and a cleanup step relies on `clearConfig()` to restore safe defaults.\n\nThis is not a default string-input bypass. An attacker must be able to influence a prior `TRUSTED_TYPES_POLICY` on the reused instance, or a less-trusted integration must have installed an unsafe policy.\n\n## Severity\n\n impact is XSS at a Trusted Types sink in applications that reuse a DOMPurify instance across trust boundaries. Attack complexity is high because exploitation depends on prior policy injection or a less-trusted integration and a later `RETURN_TRUSTED_TYPE` sink.\n\n## Suggested fix\n\nMake `clearConfig()` reset Trusted Types state as part of restoring defaults, or have `_parseConfig()` explicitly clear `trustedTypesPolicy` and `emptyHTML` when `TRUSTED_TYPES_POLICY: null` is supplied.","format":"markdown","source":"ghsa"},{"lang":"es","text":"DOMPurify 3.0.0 anterior a 3.4.9 no restablece la política de Trusted Types retenida cuando se llama a clearConfig(), por lo que una instancia de DOMPurify reutilizada a través de límites de confianza permanece vinculada a una TRUSTED_TYPES_POLICY suministrada previamente. Un llamador posterior que solicita una salida RETURN_TRUSTED_TYPE recibe un objeto TrustedHTML creado por la política antigua (potencialmente insegura) en lugar de un valor predeterminado limpio, lo que puede conducir a la ejecución de scripts en un sumidero de Trusted Types. Pasar TRUSTED_TYPES_POLICY: null en la llamada posterior tampoco borra la política retenida.","source":"nvd"}],"published":"2026-06-15T20:12:53.000Z","modified":"2026-10-24T13:10:00.147Z","severity":{"scorer":"VulnCheck","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","score":5.1,"rating":"MEDIUM"},"severities":[{"scorer":"VulnCheck","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","score":5.1,"rating":"MEDIUM"},{"scorer":"VulnCheck","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","rating":"LOW"}],"cwes":["CWE-693"],"affected":[{"ranges":[{"type":"semver","introduced":"0","fixed":"3.4.9","status":"affected"},{"type":"semver","version":"3.4.9","status":"unaffected"}],"vendor":"cure53","product":"DOMPurify","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"3.4.9"}],"ecosystem":"npm","package":"dompurify","purl":"pkg:npm/dompurify","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"3.0.0","fixed":"3.4.9"}],"vendor":"cure53","product":"dompurify","cpe":"cpe:2.3:a:cure53:dompurify:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/cure53/DOMPurify/security/advisories/GHSA-vxr8-fq34-vvx9","tags":["exploit","third-party-advisory","vendor-advisory","web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/cure53/DOMPurify/commit/825e617753ac1169306a542d3174a77f717a0cf6","tags":["patch"],"sources":["cvelist","nvd"]},{"url":"https://www.vulncheck.com/advisories/dompurify-before-trusted-types-policy-state-contamination","tags":["third-party-advisory"],"sources":["cvelist","nvd"]},{"url":"https://github.com/cure53/DOMPurify","tags":["package"],"sources":["ghsa"]}],"credits":["offset"],"assigner":"VulnCheck","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"yes","technicalImpact":"partial","date":"2026-07-27T16:15:29.603Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-65899","url":"https://www.cve.org/CVERecord?id=CVE-2026-65899","licence":"CVE Terms of Use","modified":"2026-10-08T15:23:59.489Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-vxr8-fq34-vvx9","url":"https://github.com/advisories/GHSA-vxr8-fq34-vvx9","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:12.262Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-65899","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-65899","licence":"Public domain","modified":"2026-10-24T13:10:00.147Z"}],"updatedAt":"2026-11-25T22:59:29.923Z","epss":{"score":0.00276,"percentile":0.21436,"date":"2026-12-01T12:00:22.000Z"}}