Potential fix for code scanning alert no. 1: DOM text reinterpreted as HTML#8
Merged
EthanThePhoenix38 merged 1 commit intomainfrom Jan 31, 2026
Merged
Potential fix for code scanning alert no. 1: DOM text reinterpreted as HTML#8EthanThePhoenix38 merged 1 commit intomainfrom
EthanThePhoenix38 merged 1 commit intomainfrom
Conversation
…s HTML Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Addresses code scanning alert #1 (“DOM text reinterpreted as HTML”) by preventing user-provided chat text from being inserted into the DOM as HTML.
Changes:
- Reworks
addUserMessageto construct DOM nodes viadocument.createElementinstead of building an HTML string. - Uses
textContentfor user-providedtextto avoid HTML interpretation. - Appends the assembled message node via
appendChild(maintaining existing scrolling and message tracking behavior).
Comments suppressed due to low confidence (1)
chatbot.js:224
- This statement is unreachable.
window.open('https://calendly.com/ethanbernier/', '_blank'); case 'question':
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/ThePhoenixAgency/ThePhoenixAgency.github.io/security/code-scanning/1
In general, to fix this kind of issue you must ensure that untrusted text is not interpreted as HTML without proper escaping. Two common approaches are: (1) avoid building HTML strings with untrusted data and instead create DOM elements and assign
.textContent, or (2) rigorously HTML‑escape the untrusted data before interpolation. The first approach is usually simpler and less error-prone.For this code, the best fix without changing visible functionality is to stop interpolating
textinto an HTML string for user messages and instead create the message DOM structure usingdocument.createElement, settingtextContentfor the user-provided text. That way, any HTML metacharacters intextare treated as literal characters. We only need to change theaddUserMessagemethod (lines 145–161) inchatbot.js. No imports are necessary: we can use standard DOM APIs already available in the browser. Specifically, we will replace the construction ofmessageHTMLand theinsertAdjacentHTMLcall with: create a<div>for the message, a nested<div>for.message-contentwhosetextContentis set totext, and a nested avatar<div>populated viainnerHTMLwith the fixed SVG markup. Then append this container tomessagesDiv. The rest of the logic (scrolling andthis.messages.push) stays the same.Suggested fixes powered by Copilot Autofix. Review carefully before merging.