Skip to content

Potential fix for code scanning alert no. 20: DOM text reinterpreted as HTML#1123

Merged
zhblue merged 1 commit intomasterfrom
alert-autofix-20
Jan 21, 2026
Merged

Potential fix for code scanning alert no. 20: DOM text reinterpreted as HTML#1123
zhblue merged 1 commit intomasterfrom
alert-autofix-20

Conversation

@zhblue
Copy link
Copy Markdown
Owner

@zhblue zhblue commented Jan 21, 2026

Potential fix for https://github.com/zhblue/hustoj/security/code-scanning/20

In general terms, the problem is that text read from the DOM (#errtxt) flows into innerHTML without escaping, so any HTML meta-characters in that text will be interpreted as HTML. To fix this, we must ensure that the dynamic parts derived from errmsg are HTML-escaped before they are concatenated into the HTML string assigned to innerHTML.

The best fix without changing the existing functionality is to keep using innerHTML (so the <br> and <hr> formatting is preserved), but escape the tainted part (ret) before concatenation. The exp strings are static, developer-controlled messages that already contain some intended HTML, so they should remain unescaped. We can implement a small helper function escapeHtml inside reinfo (or just above it in the same file snippet) that replaces special characters (&, <, >, ", ', and possibly /) with their HTML entity equivalents, then call this helper when appending ret into expmsg.

Concretely:

  • In trunk/web/include/reinfo.js, define an escapeHtml function within the reinfo function (or immediately before it, if you prefer a shared helper) using only standard JavaScript (no new imports needed).
  • In the loop where expmsg is built, change the line expmsg+=ret+":"+exp+"<br><hr />"; to instead use escapeHtml(ret) so that any special characters from errmsg are safely encoded.
  • Leave the rest of the logic unchanged so that the same explanations and formatting are provided; only the user-influenced error text is now rendered safely.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…as HTML

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@zhblue zhblue marked this pull request as ready for review January 21, 2026 02:13
Copilot AI review requested due to automatic review settings January 21, 2026 02:13
@zhblue zhblue merged commit 68273fd into master Jan 21, 2026
7 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses a security vulnerability (DOM-based XSS) where user-controlled text from the DOM is injected into innerHTML without proper sanitization. The fix introduces an escapeHtml function to encode HTML special characters before inserting the matched error text into the DOM.

Changes:

  • Added escapeHtml helper function to sanitize user-influenced content
  • Applied HTML escaping to regex match results before concatenating into innerHTML

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants