Skip to content

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

Open
aljojoby9 wants to merge 2 commits into
twbs:mainfrom
aljojoby9:fix/backport-sanitizer-data-vbscript-urls
Open

Sanitizer: block data:/vbscript: URLs (XSS hardening)#42806
aljojoby9 wants to merge 2 commits into
twbs:mainfrom
aljojoby9:fix/backport-sanitizer-data-vbscript-urls

Conversation

@aljojoby9

Copy link
Copy Markdown

Description

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 tooltip/popover content (for example data-bs-title / data-bs-content) that is an XSS vector.

This is already fixed on v6-dev in #42549. The same gap is still present on the stable 5.3.x line shipped as 5.3.8.

Changes

  • SAFE_URL_PATTERN now also rejects data: and vbscript:
  • Restore a DATA_URL_PATTERN that re-allows only safe base64 image/video/audio data URLs
  • Extend the invalid-URL unit tests with data:text/html and vbscript: cases
  • Bump JS bundlewatch budgets for the small size increase

Related

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.

Backports the v6 fix from twbs#42549 to the 5.3.x line. Related to twbs#42443.
Copilot AI lite review requested due to automatic review settings August 6, 2026 19:26
@aljojoby9
aljojoby9 requested a review from a team as a code owner August 6, 2026 19:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backports Bootstrap’s sanitizer hardening to the 5.3.x line by closing an XSS gap where data: and vbscript: URLs could pass through href/src sanitization (notably impactful for tooltip/popover HTML content scenarios).

Changes:

  • Tighten SAFE_URL_PATTERN to reject data: and vbscript: schemes, not just javascript:.
  • Reintroduce a DATA_URL_PATTERN to allow only safe base64 data: URLs for image/video/audio.
  • Extend sanitizer unit tests with data:text/html and vbscript: invalid URL cases, and adjust bundlewatch size budgets accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
js/src/util/sanitizer.js Blocks data:/vbscript: URLs by default while re-allowing a constrained subset of safe base64 media data: URLs.
js/tests/unit/util/sanitizer.spec.js Adds test coverage for newly-blocked dangerous data:text/html and vbscript: URLs.
.bundlewatch.config.json Updates bundle size budgets to account for the small size increase from sanitizer changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread js/src/util/sanitizer.js Outdated
*
* 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-z=]+$/i

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Added audio/mpeg to DATA_URL_PATTERN and a unit case for a safe data:audio/mpeg;base64,... URL in 8c91b30.

audio/mp3 is nonstandard. Accept the real MIME type audio/mpeg so safe
base64 MP3 data URLs keep working after the data: scheme is blocked.
Copilot AI review requested due to automatic review settings August 6, 2026 19:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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