fix: strip additional Unicode obfuscation vectors in sanitizer#1007
Open
qinlongli2024-ai wants to merge 1 commit intoanthropics:mainfrom
Open
fix: strip additional Unicode obfuscation vectors in sanitizer#1007qinlongli2024-ai wants to merge 1 commit intoanthropics:mainfrom
qinlongli2024-ai wants to merge 1 commit intoanthropics:mainfrom
Conversation
Extend stripInvisibleCharacters() to cover three additional Unicode ranges that can be used to smuggle hidden instructions or confuse code reviewers: - Tag characters (U+E0001–E007F): originally designed for emoji language tags, these can embed invisible ASCII-equivalent text in comments, issue bodies, or PR descriptions. - Variation selectors (U+FE00–FE0F): can alter glyph rendering to make visually identical characters differ at the codepoint level, enabling homoglyph / visual confusion attacks. - Interlinear annotation anchors (U+FFF9–FFFB): obscure formatting characters that have no visible rendering but could carry hidden payload in crafted inputs. Also adds descriptive comments to the existing stripping rules for better maintainability. Includes three new test cases covering each added range.
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
stripInvisibleCharacters()insanitizer.tscovers zero-width characters, control characters, soft hyphens, and bidi overrides — but misses three additional Unicode ranges that can be used to smuggle hidden content through PR descriptions, issue bodies, and comments.Added coverage
Example attack
An attacker could include tag characters in a PR comment that are invisible to human reviewers but parsed by the LLM:
The visible part says "Looks good!" but the tag characters encode hidden instructions.
Changes
src/github/utils/sanitizer.ts: Add three new.replace()calls + descriptive comments on all existing rulestest/sanitizer.test.ts: Add three test cases for the new rangesChecklist