Potential fix for code scanning alert no. 14: DOM text reinterpreted as HTML#335
Draft
leandrumartin wants to merge 1 commit intomainfrom
Draft
Potential fix for code scanning alert no. 14: DOM text reinterpreted as HTML#335leandrumartin wants to merge 1 commit intomainfrom
leandrumartin wants to merge 1 commit intomainfrom
Conversation
…as HTML Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.
Potential fix for https://github.com/oss-slu/DigitalBonesBox/security/code-scanning/14
General fix: Avoid feeding untrusted or semi‑trusted text back into the DOM via
innerHTMLunless it has been properly HTML‑escaped, or avoidinnerHTMLaltogether by constructing DOM nodes withtextContent. Here, the vulnerability is intests/test-colored-regions.html:addLogbuilds HTML strings containing unescapedmessageand then assignsconsoleDiv.innerHTMLa concatenation of those strings. We can keep the visual formatting (timestamp, severity coloring) but build elements programmatically and store them inlogsas DOM nodes instead of HTML strings, and append them using DOM APIs (appendChild/replaceChildren) so that any text is treated as text, not HTML.Best concrete fix without changing functionality:
logsfrom an array of HTML strings to an array of DOM elements (e.g.,<span>nodes).addLog, instead of building a template string with<span class=...>...</span>and pushing it tologs, create aspanelement, set itsclassName, and assign itstextContentto the full[timestamp] TYPE: messagestring. This ensures any special characters inmessageare escaped by the browser.consoleDiv.innerHTML = logs.slice(-50).join('\n');, clearconsoleDivand append the last 50spanelements, optionally inserting real text newlines or<br>elements between them for readability. This removes the dangerousinnerHTMLuse for tainted content while preserving log display behavior.dropdowns.js,imageDisplay.js,coloredRegionsOverlay.js) unchanged, as the sink is in the test file’s logger and fixing it protects against all tainted flows.All changes are confined to
tests/test-colored-regions.html, lines 84–97 where the logging is implemented.Suggested fixes powered by Copilot Autofix. Review carefully before merging.