Repository navigation
fix(docs): set chart error messages as text, not HTML - #463
Conversation
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>
There was a problem hiding this comment.
🟢 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 withtextContent, and swaps content viareplaceChildren. - Replaced the two
innerHTML-based error handlers (scenario load failure and summary load failure) with calls toshowError().
| 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
Fixes CodeQL alert #59 (
js/xss-through-dom) indocs/assets/js/peak-shaving-charts.js.When a scenario CSV failed to load, the scenario name and
err.messagewere concatenated intoinnerHTML. A smallshowError()helper now builds the<p class="ps-error">element and sets the message viatextContent. 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