Skip to content

fix(docs): set chart error messages as text, not HTML - #463

Merged
MaStr merged 1 commit into
mainfrom
fix/docs-chart-error-xss
Oct 19, 2026
Merged

MaStr merged 1 commit into
mainfrom
fix/docs-chart-error-xss

Conversation

@MaStr

@MaStr MaStr commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Fixes CodeQL alert #59 (js/xss-through-dom) in docs/assets/js/peak-shaving-charts.js.

When a scenario CSV failed to load, the scenario name and err.message were concatenated into innerHTML. A small showError() helper now builds the <p class="ps-error"> element and sets the message via textContent. The summary loader had the same pattern and uses the helper too.

Rendering is unchanged; only the error text is no longer interpreted as HTML.

🤖 Generated with Claude Code

The peak shaving charts put the scenario name and err.message into
innerHTML when a CSV failed to load. Build the error paragraph with
textContent instead (CodeQL js/xss-through-dom, alert #59). The summary
error path had the same pattern and is changed too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 07:34
@MaStr
MaStr merged commit 71a42b7 into main Oct 19, 2026
13 checks passed
@MaStr
MaStr deleted the fix/docs-chart-error-xss branch October 19, 2026 07:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Both err.message error paths are now rendered as text via textContent, the remaining innerHTML uses are static or trusted CSV data, and the ps-error class remains defined, making this a correct and self-contained security fix.

No open issues 🎉

What changed in this PR

This PR fixes a CodeQL js/xss-through-dom finding in the documentation's peak-shaving chart script. Previously, when a scenario CSV or the summary CSV failed to load, the catch handlers concatenated the scenario name and err.message directly into container.innerHTML, meaning the error text was interpreted as HTML. The PR introduces a small showError() helper that builds the <p class="ps-error"> element and assigns the message via textContent, so the error text can no longer be parsed as markup. Both error paths now use the helper, and the visible rendering is unchanged.

Changes:

  • Added a showError(container, text) helper that creates a <p class="ps-error">, sets the message with textContent, and swaps content via replaceChildren.
  • Replaced the two innerHTML-based error handlers (scenario load failure and summary load failure) with calls to showError().
File Description
docs/​assets/​js/​peak-shaving-charts.js Adds a showError() helper using textContent and routes both CSV-load error handlers through it to prevent HTML injection via err.message.

Review effort: Balanced

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