Skip to content

Potential fix for code scanning alert no. 22: Client-side cross-site scripting#86

Merged
EthanThePhoenix38 merged 1 commit intomainfrom
alert-autofix-22
Feb 14, 2026
Merged

Potential fix for code scanning alert no. 22: Client-side cross-site scripting#86
EthanThePhoenix38 merged 1 commit intomainfrom
alert-autofix-22

Conversation

@EthanThePhoenix38
Copy link
Member

@EthanThePhoenix38 EthanThePhoenix38 commented Feb 14, 2026

Potential fix for https://github.com/ThePhoenixAgency/AI-Pulse/security/code-scanning/22

In general, to fix this kind of issue you must ensure that any value deriving from user input (like window.location.hash) is either strictly validated against an allowlist of expected values or properly escaped before being written into HTML via innerHTML, document.write, or similar sinks. Here, the vulnerable usage is in the error template where ${filename} is inserted into HTML.

The minimal, behavior‑preserving fix is:

  1. Introduce a small helper function that HTML‑escapes a string (&, <, >, ", ', and / at least).
  2. Use this helper to sanitize filename at the point where it is interpolated into the error message HTML (line 418–422).
  3. Keep using the original unsanitized filename for non‑HTML contexts (like building the GitHub URL path), because the URL path is constrained by the existing logic via docsNav. However, to be extra defensive, we can also use the escaped version in the GitHub URL; escaping <, >, etc. is safe for URLs in HTML attributes.

Concretely:

  • Add a function escapeHtml(str) above loadDoc.
  • In loadDoc, compute const safeFilename = escapeHtml(filename);.
  • Use safeFilename instead of filename in the error HTML template literal (both in the visible text and the href attribute).

No external libraries are needed; the escaping function is simple and self‑contained. All changes are within docs.html in the shown script block.


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


Continue Tasks: ▶️ 1 queued — View all

…scripting

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@EthanThePhoenix38 EthanThePhoenix38 marked this pull request as ready for review February 14, 2026 12:50
Copilot AI review requested due to automatic review settings February 14, 2026 12:50
@EthanThePhoenix38 EthanThePhoenix38 merged commit c6f669a into main Feb 14, 2026
4 checks passed
@EthanThePhoenix38 EthanThePhoenix38 deleted the alert-autofix-22 branch February 14, 2026 12:50
Copy link
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 PR addresses a client-side XSS vulnerability (code scanning alert #22) by implementing HTML escaping for user-controlled filename values before they are inserted into the DOM via innerHTML. The vulnerability exists because filenames derived from window.location.hash were being used directly in HTML templates without sanitization.

Changes:

  • Added an escapeHtml() function to sanitize strings by escaping HTML special characters (&, <, >, ", ', /)
  • Applied HTML escaping to the filename parameter in the loading message and error templates
  • Used the sanitized filename in both text content and href attributes to prevent XSS injection

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

Comment on lines 402 to +403
async function loadDoc(filename) {
const safeFilename = escapeHtml(filename);
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

While HTML escaping prevents XSS in the displayed content, the filename parameter still comes from user-controlled input (window.location.hash via init()) without validation. Consider adding explicit validation at the start of this function to ensure the filename matches one of the allowed documents. For example, you could define an allowlist of valid filenames (TECHNIQUE.md, READER_MODE_PLAN.md, SUPABASE_MIGRATION.md, ACTION_README.md) and reject any filename that's not in the list. This would provide defense in depth against potential SSRF or path traversal issues when constructing the GitHub API URL on line 413.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants