Skip to content

fix(sanitizer): strip HTML comments after decoding entities#1504

Open
NickNojiri wants to merge 1 commit into
anthropics:mainfrom
NickNojiri:fix/sanitizer-entity-encoded-comment-bypass
Open

fix(sanitizer): strip HTML comments after decoding entities#1504
NickNojiri wants to merge 1 commit into
anthropics:mainfrom
NickNojiri:fix/sanitizer-entity-encoded-comment-bypass

Conversation

@NickNojiri

@NickNojiri NickNojiri commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

The content sanitizer strips HTML comments to remove hidden instructions before GitHub content reaches the model, but normalizeHtmlEntities runs later in the pipeline. Entity-encoded delimiters — <!-- … --> — pass through the initial stripHtmlComments untouched, then get decoded back into a live comment that reaches Claude. Verified the decimal, hex, and opening-delimiter-only variants all leak.
Fix

Re-run stripHtmlComments after entity decoding. All three variants now closed; plain-comment behavior unchanged.

Scope note: entity-encoded comments render visibly in GitHub's UI, so this is defense-in-depth hardening of the injection sanitizer rather than a fully-hidden exploit.
Testing

bun test — 771 pass, 0 fail · bun run typecheck clean · bun run format:check clean
Regression tests added for the decimal, hex, and partial-encoding variants

sanitizeContent strips HTML comments first (to remove hidden
instructions), but normalizeHtmlEntities runs several steps later.
Decoding entities can re-introduce a comment that was entity-encoded
specifically to survive that first strip: an input of
"&anthropics#60;!-- ... --&anthropics#62;" passes through stripHtmlComments untouched,
then normalizeHtmlEntities decodes it back into a live
"<!-- ... -->" comment that reaches the model.

Run stripHtmlComments once more after entity decoding so a comment
cannot slip through via encoding. Verified the decimal, hex, and
opening-delimiter-only variants are all closed, with the plain
comment case unchanged.

Add regression tests for the entity-encoded comment bypass.
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