fix(P2): add bidi control character detection (Trojan Source / CVE-2021-42574)#92
Open
Shrotriya-lalit wants to merge 1 commit into
Open
Conversation
…n Source) P2_PATTERNS was missing Unicode bidi override/embedding/isolate characters (U+202A-U+202E, U+2066-U+2069) that can be used to hide malicious instructions from human code review while the LLM sees and executes them. Add the range with confidence 0.85 (higher than plain zero-width chars because bidi controls have almost no legitimate use in AI skill content). Closes NVIDIA#39 Signed-off-by: Lalit Shrotriya <shrotriya.lalit@outlook.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.
Problem
P2_PATTERNScatches zero-width characters (–) but was missing the full set of Unicode bidi control characters (U+202A–U+202E,U+2066–U+2069).Bidi overrides are the attack vector behind CVE-2021-42574 (Trojan Source): an attacker inserts a RIGHT-TO-LEFT OVERRIDE (
) or similar character so the code looks safe to a human reviewer, but the LLM reads the characters in logical order and follows hidden instructions.Fix
Add one regex entry to
P2_PATTERNS:Confidence 0.85 — higher than plain zero-width chars because bidi controls have almost no legitimate use in AI skill markdown content.
Tests
test_p2_bidi_control_chars_produce_finding— RLO character triggers P2test_p2_bidi_rlo_edge_cases— all 9 bidi control characters individually trigger P2Closes #39
Checklist
make lintpassesgit commit -s)