Skip to content

fix: harden DOM-XSS surfaces flagged by CodeQL js/xss - #143

Merged
therealsama merged 1 commit into
mainfrom
feat/harden-xss-codeql-alerts
Jun 10, 2026
Merged

therealsama merged 1 commit into
mainfrom
feat/harden-xss-codeql-alerts

Conversation

@therealsama

@therealsama therealsama commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

Sanitize untrusted HTML before it is parsed into a DOM in sanitizeHtml:
input now passes through DOMPurify before any innerHTML write instead of
only sanitizing the output, and the instance is renamed to the canonical
DOMPurify. The template write was already inert, so this is defense in
depth that also clears CodeQL's recognized barrier.

Only render http(s) URLs as outbound anchors in ItemArticle and StoryCard:
a hostile javascript:/data: URL from the HN API can no longer reach an
anchor href (React blocks javascript: but not data:). Non-http(s) URLs
degrade to the plain-text title / in-app discussion link.

The scheme check guards a single local rawUrl binding with one
startsWith('http'). That shape is required for CodeQL to honor the
barrier: a || of two checks reopens the finding because a LogOrExpr
doesn't carry the guard's true outcome into the guarded branch.

Add regression tests for the URL-scheme guard.

@therealsama
therealsama requested a review from kplachkov as a code owner June 9, 2026 22:17
Comment thread src/components/ItemArticle.tsx Fixed
@therealsama
therealsama force-pushed the feat/harden-xss-codeql-alerts branch from 3a19eba to 9ea80e4 Compare June 10, 2026 07:59
@therealsama
therealsama enabled auto-merge June 10, 2026 08:08
Sanitize untrusted HTML before it is parsed into a DOM in sanitizeHtml:
input now passes through DOMPurify before any innerHTML write instead of
only sanitizing the output, and the instance is renamed to the canonical
`DOMPurify`. The template write was already inert, so this is defense in
depth that also clears CodeQL's recognized barrier.

Only render http(s) URLs as outbound anchors in ItemArticle and StoryCard:
a hostile `javascript:`/`data:` URL from the HN API can no longer reach an
anchor href (React blocks `javascript:` but not `data:`). Non-http(s) URLs
degrade to the plain-text title / in-app discussion link.

The scheme check guards a single local `rawUrl` binding with one
`startsWith('http')`. That shape is required for CodeQL to honor the
barrier: a `||` of two checks reopens the finding because a LogOrExpr
doesn't carry the guard's true outcome into the guarded branch.

Add regression tests for the URL-scheme guard.
@therealsama
therealsama force-pushed the feat/harden-xss-codeql-alerts branch from 9ea80e4 to a65abb5 Compare June 10, 2026 08:10
@therealsama
therealsama merged commit dbc6b84 into main Jun 10, 2026
4 checks passed
@therealsama
therealsama deleted the feat/harden-xss-codeql-alerts branch June 10, 2026 09:46
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.

3 participants