fix(sanitization): match onload case- and space-insensitively - #31417
Open
chuhuangvio-itch wants to merge 1 commit into
Open
fix(sanitization): match onload case- and space-insensitively#31417chuhuangvio-itch wants to merge 1 commit into
chuhuangvio-itch wants to merge 1 commit into
Conversation
sanitizeDOMString blocked untrusted HTML that contains "onload=" before setting it via innerHTML, because onload can fire synchronously while parsing into the detached document fragment, ahead of the later attribute-allowlist pass. The check used a plain lowercase substring match, so variants like onLoad=, ONLOAD= or onload = (whitespace before the =) were not caught, even though HTML parses them as the same event handler. Use a case-insensitive regex that also tolerates whitespace around the =. Adds a test covering the case and whitespace variants.
|
@chuhuangvio-itch is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
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.
What is the current behavior?
sanitizeDOMString(core/src/utils/sanitization/index.ts) blocks untrusted HTML containingonload=before it reachesinnerHTML, becauseonloadcan fire synchronously while the string is being parsed into the working document fragment — before the later attribute-allowlist pass runs. The check is a plain lowercase substring match (untrustedString.includes('onload=')), so it missesonLoad=,ONLOAD=, oronload =(whitespace before=) even though HTML parses all of those as the same event handler.What is the new behavior?
=(/onload\s*=/i), matching how HTML actually parses attribute names.Does this introduce a breaking change?
Other information
sanitizeDOMStringis used byion-toast,ion-loading, theion-alertmessage,ion-refresher-content, andion-infinite-scroll-contentto sanitize developer-supplied HTML strings that may embed end-user input (e.g. another user's display name rendered in a toast/alert). This closes a gap where a payload like<svg onLoad=...>could bypass the intended guard and reachinnerHTMLunfiltered.I didn't find an existing
SECURITY.mdor private vulnerability reporting channel enabled on this repo, so opening this directly as a PR with the fix rather than filing a separate public issue describing the bypass.