Skip to content

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

Merged
rajbos merged 2 commits intomainfrom
alert-autofix-53
Apr 10, 2026
Merged

Potential fix for code scanning alert no. 53: Client-side cross-site scripting#579
rajbos merged 2 commits intomainfrom
alert-autofix-53

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Apr 10, 2026

Potential fix for https://github.com/rajbos/github-copilot-token-usage/security/code-scanning/53

Best fix: validate and sanitize the incoming repoPrStatsData at the message boundary before storing/rendering it, and ensure all dynamic fields used in HTML templates are escaped or type-coerced to safe primitives.

In this file (vscode-extension/src/webview/usage/main.ts), the least disruptive, functionality-preserving fix is:

  1. Add small helper sanitizers (string/number/url coercion).
  2. Add a sanitizeRepoPrStatsData function that:
    • enforces expected structure,
    • escapes text fields (owner, repo, error, AI detail labels),
    • constrains URLs to http/https (or safe fallback),
    • coerces count fields to finite non-negative numbers.
  3. In repoPrStatsLoaded message case, sanitize message.data before assigning to repoPrStatsData and rendering.
  4. In renderReposPrContent, ensure numeric outputs are explicitly formatted from safe numbers (defense in depth).

This keeps existing UI behavior while eliminating tainted raw values flowing into innerHTML.

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

…scripting

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@rajbos rajbos marked this pull request as ready for review April 10, 2026 21:22
@rajbos rajbos enabled auto-merge (squash) April 10, 2026 21:22
The CodeQL autofix introduced sanitizeRepoPrStatsData but mapped
aiDetails to {label, count} instead of the required RepoPrDetail
shape {number, title, url, aiType, role}, causing a TS2352 type
error and CI build failure.

Replace the incorrect mapping with proper sanitization:
- number: coerced to safe non-negative number
- title: HTML-escaped string
- url: validated to http/https via toSafeHttpUrl
- aiType: constrained to allowed union values, fallback 'other-ai'
- role: constrained to allowed union values, fallback 'author'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos merged commit a0da624 into main Apr 10, 2026
16 checks passed
@rajbos rajbos deleted the alert-autofix-53 branch April 10, 2026 21:34
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.

1 participant