Potential fix for code scanning alert no. 10: DOM text reinterpreted as HTML - #1
Draft
imbilawork wants to merge 1 commit into
Draft
Potential fix for code scanning alert no. 10: DOM text reinterpreted as HTML#1imbilawork wants to merge 1 commit into
imbilawork wants to merge 1 commit into
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/2nth-ai/developers/security/code-scanning/10
In general, the fix is to avoid inserting raw, user-controlled text into
innerHTML. Instead, build the DOM tree usingdocument.createElementand assign user-provided values totextContent(orinnerText) or to safe attributes. This preserves the intended UI while ensuring that any HTML meta-characters in the input are escaped and rendered as plain text, not executed as HTML/JS.For this specific case in
public/preview/luthuli/lodge.html, we should change theaddTaskfunction so that it no longer constructs the task item via a big HTML string assigned todiv.innerHTML. Instead:divwith classtask(already done).divfor the priority indicator; set itsclassNameto'task-pri pri-' + pri. Ifpricomes from a select with fixed options, this is safe; if not, ideally we would normalize or whitelistpribefore using it in a class name, but we’ll limit ourselves to code shown.divwith classtask-text, and inside it:strongelement whosetextContentistitle.descis present, append a text node' — ' + desc(again viatextContent/createTextNode).divwith classtask-dueand set itstextContenttodue || 'No date'.taskcontainerdivinstead of settinginnerHTML.We should leave the
addFeedItemfunction unchanged because, in the snippet, its inputs are either internal strings or controlled within code; the CodeQL alerts are specifically for theaddTaskpath. All changes occur within the script tag ofpublic/preview/luthuli/lodge.html, only around theaddTaskfunction, without introducing new imports or altering other behavior.Suggested fixes powered by Copilot Autofix. Review carefully before merging.