Sanitizer: block data:/vbscript: URLs (XSS hardening) - #42806
Open
aljojoby9 wants to merge 2 commits into
Open
Conversation
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.
There was a problem hiding this comment.
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_PATTERNto rejectdata:andvbscript:schemes, not justjavascript:. - Reintroduce a
DATA_URL_PATTERNto allow only safe base64data:URLs for image/video/audio. - Extend sanitizer unit tests with
data:text/htmlandvbscript: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.
| * | ||
| * 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 |
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The HTML sanitizer's
SAFE_URL_PATTERNonly rejectedjavascript:, so adata:text/html,…(orvbscript:) URL in anhref/srcpassed the attribute allowList. Via tooltip/popover content (for exampledata-bs-title/data-bs-content) that is an XSS vector.This is already fixed on
v6-devin #42549. The same gap is still present on the stable 5.3.x line shipped as 5.3.8.Changes
SAFE_URL_PATTERNnow also rejectsdata:andvbscript:DATA_URL_PATTERNthat re-allows only safe base64 image/video/audio data URLsdata:text/htmlandvbscript:casesRelated
main