-
Notifications
You must be signed in to change notification settings - Fork 9
Potential fix for code scanning alert no. 51: Double escaping or unescaping #1182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
Check failure
Code scanning / CodeQL
DOM text reinterpreted as HTML High
Copilot Autofix
AI 4 days ago
In general, the problem is that
decodeHtmlusesd.innerHTML = strto decode HTML entities. This makes the browser treatstras HTML, which is dangerous for tainted input. The correct pattern is the inverse: set a node’stextContent(orinnerText) so that the browser treats the string as plain text, then readinnerHTMLorvalueas needed. For decoding entities safely, we want to ensure user input is never parsed as markup.The best minimal fix here is to change
decodeHtmlso it never assigns tainted data toinnerHTML. A safe pattern for decoding entities is:textContent(so it is not parsed as HTML).innerHTMLto get the entity-encoded version, or for decoding, use a known-safe pattern that does not interpret new markup.However, for decoding HTML entities, an even safer and simpler approach is:
<textarea>or<div>).element.innerHTMLto a trusted string that contains the tainted string only insidetextContent, ortextContent/innerText.Given our constraints and desire for minimal change, we can implement
decodeHtmlusingtextContentandinnerHTMLin a way that never parsesstras HTML. A straightforward pattern is:For
<textarea>, assigning totextContentsets its textual contents without parsing as HTML, and reading.valuegives the same text; when the input contains entity sequences like&, they remain literal, so we do not get decoding via DOM parsing at all. Given that our current “decode” step is actually unnecessary for security and mostly cosmetic, the safest correction is to simply remove the innerHTML-based decoding and let the previously stripped, raw text pass through unmodified. In other words, we can changedecodeHtmlto be an identity function or to usetextContentin a non-parsing way.To preserve intent but eliminate the vulnerability with minimal behavioural change, we can:
decodeHtmldefinition (lines 188–193) with a version that never assigns tainted data toinnerHTMLand, for now, simply returns the input unchanged. Since later rendering should already be usingescHtml, this is safe.introPreview = decodeHtml(introPreview);call intact so that if future logic wants to refine decoding, it has a hook.No new imports or external libraries are needed; this is confined to the
buildReviewSummaryfunction in build/media_source/js/message-wizard.es6.js, in thedecodeHtmlhelper.