From 13f45d2c6a4eb64ba1a10e44decc865c163f17be Mon Sep 17 00:00:00 2001 From: Paco Cartones <253313177+pacocartones@users.noreply.github.com> Date: Mon, 3 Aug 2026 13:51:06 +0200 Subject: [PATCH] docs: clarify sanitize-html affected range --- .../2026/07/GHSA-vccv-cmxp-4j9h/GHSA-vccv-cmxp-4j9h.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advisories/github-reviewed/2026/07/GHSA-vccv-cmxp-4j9h/GHSA-vccv-cmxp-4j9h.json b/advisories/github-reviewed/2026/07/GHSA-vccv-cmxp-4j9h/GHSA-vccv-cmxp-4j9h.json index 40b70de90eea..37ecf85360d5 100644 --- a/advisories/github-reviewed/2026/07/GHSA-vccv-cmxp-4j9h/GHSA-vccv-cmxp-4j9h.json +++ b/advisories/github-reviewed/2026/07/GHSA-vccv-cmxp-4j9h/GHSA-vccv-cmxp-4j9h.json @@ -7,7 +7,7 @@ "CVE-2026-53606" ], "summary": "sanitize-html has incomplete URI scheme validation in that allows javascript: URIs through action, formaction, data, poster, and background attributes", - "details": "## Summary\n\nsanitize-html uses `allowedSchemesAppliedToAttributes` (default: `['href', 'src', 'cite']`) to gate the `naughtyHref()` function that blocks dangerous URI schemes like `javascript:` and `vbscript:`. The HTML specification defines 10+ attributes that accept URIs (`action`, `formaction`, `data`, `poster`, `background`, `ping`, `xlink:href`, `dynsrc`, `lowsrc`), but none of these are included in the default gate list. When a developer allows any of these attributes in their configuration, `javascript:` URIs pass through completely unmodified, enabling XSS.\n\nThe library has zero awareness of these URI-bearing attributes — none appear anywhere in the 854-line source file (verified by grep). No warning mechanism exists, and the README provides no security guidance about expanding `allowedSchemesAppliedToAttributes` when allowing form or media attributes.\n\n## Severity\n\nExploitation requires non-default configuration: the developer must explicitly allow a non-default tag (e.g., `form`) AND a non-default attribute (e.g., `action`). Default configuration is NOT vulnerable. However, this is a common configuration pattern for CMS platforms, form builders, and rich content editors.\n\n## Affected Versions\n\nAll versions of sanitize-html from v1.18.0 (which introduced `allowedSchemesAppliedToAttributes`) through at least v2.17.2. The default list has been `['href', 'src', 'cite']` since introduction and has never been expanded.\n\n## Root Cause\n\n**File**: `index.js:329` (sanitize-html 2.10.0, confirmed same in 2.17.x)\n\n```javascript\n// Line 329 — The gate that controls scheme validation\nif (options.allowedSchemesAppliedToAttributes.indexOf(a) >= 0) {\n if (naughtyHref(name, value)) {\n delete frame.attribs[a];\n return;\n }\n}\n```\n\n**Default list at line 829**:\n```javascript\nallowedSchemesAppliedToAttributes: ['href', 'src', 'cite'],\n```\n\nThe `naughtyHref()` function (lines 627-667) correctly blocks `javascript:`, `vbscript:`, and other dangerous schemes. However, it has exactly 2 call sites in the entire codebase (lines 330 and 395), both inside the `indexOf` gate. There is no ungated path.\n\nWhen attribute name is `action`, `formaction`, `data`, `poster`, `background`, etc.:\n- `indexOf('action')` returns `-1`\n- The `if` block is skipped entirely\n- `naughtyHref()` is never called\n- `javascript:alert(1)` passes through unmodified\n\nThe `escapeHtml()` function at line 464 provides no defense — it only encodes `& < > \"` characters, which are not present in `javascript:alert(1)`.\n\n**Data Flow**:\n```\nAttacker input:
',\n {\n allowedTags: ['form', 'button'],\n allowedAttributes: { form: ['action'] }\n }\n);\nconsole.log('V1 (action):', v1);\n// OUTPUT: \n// XSS triggers when user submits the form\n\n// ===== VECTOR 2: button formaction (100% reliable) =====\nconst v2 = sanitize(\n '',\n {\n allowedTags: ['button'],\n allowedAttributes: { button: ['formaction'] }\n }\n);\nconsole.log('V2 (formaction):', v2);\n// OUTPUT: \n\n// ===== VECTOR 3: object data =====\nconst v3 = sanitize(\n '',\n {\n allowedTags: ['object'],\n allowedAttributes: { object: ['data'] }\n }\n);\nconsole.log('V3 (data):', v3);\n// OUTPUT: \n\n// ===== CONTROL: href IS scheme-checked (expected behavior) =====\nconst ctrl = sanitize(\n 'click',\n {\n allowedTags: ['a'],\n allowedAttributes: { a: ['href'] }\n }\n);\nconsole.log('Control (href):', ctrl);\n// OUTPUT: click ← href correctly stripped by naughtyHref()\n```\n\n**Observed behavior**: `javascript:` preserved on `action`/`formaction`/`data` but correctly stripped on `href`.\n\n**Expected behavior**: `javascript:` should be stripped on ALL URI-bearing attributes, or at minimum, the library should warn developers when they allow URI-bearing attributes not covered by scheme validation.\n\n## Impact\n\nAn attacker can achieve XSS in applications that use sanitize-html with non-default configurations allowing URI-bearing attributes:\n\n- `