Sanitizer: block data:/vbscript: URLs (XSS hardening)#42549
Open
mdo 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. Fixes #42443.
| * | ||
| * 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 |
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.
Problem (security)
The HTML sanitizer's
SAFE_URL_PATTERNonly rejectedjavascript:, so adata:text/html,…(orvbscript:) URL in anhref/srcpassed the attribute allowList. Viadata-bs-title/data-bs-content(withhtml: trueor a permissiveallowList) that's an XSS vector.Fix
SAFE_URL_PATTERNnow also rejectsdata:andvbscript:.DATA_URL_PATTERN(as in earlier Bootstrap) that re-allows only safe base64 image/video/audio data URLs, so legitimatedata:image/*sources keep working whiledata:text/htmlis blocked.Verification
data:text/html,…, base64text/html,vbscript:) to the sanitizer's invalid-URL test; existing validdata:image|video|audiobase64 URLs still pass.Fixes #42443.