Skip to content

Sanitizer: block data:/vbscript: URLs (XSS hardening)#42549

Open
mdo wants to merge 2 commits into
v6-devfrom
mdo/sanitizer-block-data-url
Open

Sanitizer: block data:/vbscript: URLs (XSS hardening)#42549
mdo wants to merge 2 commits into
v6-devfrom
mdo/sanitizer-block-data-url

Conversation

@mdo

@mdo mdo commented Jun 24, 2026

Copy link
Copy Markdown
Member

Problem (security)

The HTML sanitizer's SAFE_URL_PATTERN only rejected javascript:, so a data:text/html,… (or vbscript:) URL in an href/src passed the attribute allowList. Via data-bs-title/data-bs-content (with html: true or a permissive allowList) that's an XSS vector.

Fix

  • SAFE_URL_PATTERN now also rejects data: and vbscript:.
  • Restored a DATA_URL_PATTERN (as in earlier Bootstrap) that re-allows only safe base64 image/video/audio data URLs, so legitimate data:image/* sources keep working while data:text/html is blocked.

Verification

  • Added the dangerous URLs (data:text/html,…, base64 text/html, vbscript:) to the sanitizer's invalid-URL test; existing valid data:image|video|audio base64 URLs still pass.
  • Full unit suite passes; lint clean.

Fixes #42443.

The sanitizer's SAFE_URL_PATTERN only rejected javascript:, so a
data:text/html (or vbscript:) URL in an href/src passed the allowList —
an XSS vector via data-bs-title/data-bs-content. Reject data: and
vbscript: in SAFE_URL_PATTERN and re-allow only safe base64 image/video/
audio data URLs via a restored DATA_URL_PATTERN. Fixes #42443.
@mdo mdo requested a review from a team as a code owner June 24, 2026 17:07
Comment thread js/src/util/sanitizer.js
*
* Shout-out to Angular https://github.com/angular/angular/blob/15.2.8/packages/core/src/sanitization/url_sanitizer.ts#L49
*/
const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z0-9=]+$/i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants