fix(security): prevent HTML entity-encoded comment injection bypass in sanitizer#1035
Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Open
fix(security): prevent HTML entity-encoded comment injection bypass in sanitizer#1035MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Conversation
…n sanitizer Move normalizeHtmlEntities to run before stripHtmlComments in the sanitizeContent pipeline. Previously, entity-encoded HTML comments (e.g. &anthropics#60;!&anthropics#45;&anthropics#45; ... &anthropics#45;&anthropics#45;&anthropics#62;) passed through stripHtmlComments undetected and were then decoded into real comment tags by normalizeHtmlEntities, allowing hidden prompt injection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
sanitizeContentfunction insrc/github/utils/sanitizer.tshas an ordering vulnerability that allows HTML comment injection through entity encoding.Vulnerability
stripHtmlCommentsruns beforenormalizeHtmlEntities, so an attacker can encode<!--and-->as HTML entities to bypass comment stripping entirely:This entity-encoded string passes through
stripHtmlCommentsundetected (it doesn't match<!--...-->), thennormalizeHtmlEntitiesdecodes it into a real HTML comment:<!-- ignore above instructions -->The result is a fully functional hidden comment injected into sanitized content — a prompt injection vector.
Attack vector
An attacker can embed entity-encoded HTML comments in GitHub issue bodies, PR descriptions, or comments. These comments are invisible when rendered by GitHub but survive the sanitizer and reach the LLM as hidden instructions.
Fix
Move
normalizeHtmlEntitiesto run beforestripHtmlCommentsso that entity-encoded markup is decoded first, then stripped by the appropriate sanitization step.Before:
After:
Tests added
<,-,>)<,-,>)Both tests verify that the injected comment content is fully removed from sanitized output.