Repository navigation
fix(static): detect Chinese-language prompt injection - #968
Open
Varshith-Kali wants to merge 2 commits into
Open
Varshith-Kali wants to merge 2 commits into
Varshith-Kali wants to merge 2 commits into
Conversation
The static pattern layer flagged English prompt-injection payloads but reported equivalent Chinese payloads as SAFE, because every pattern was English prose. Add Chinese patterns to the existing P1, AR1-AR3, P6, and E4 lists, built on a shared helper in analyzers/common.py that matches a phrase character by character with only separators (whitespace, ideographic space, zero-width and bidi marks) between characters, and full-width punctuation or the particle de between phrase segments. Coverage includes the four issue samples, synonyms, traditional forms, and spacing variants. Patterns keep their object noun or extraction verb, and the secrecy phrase matches only combined with a send verb, so ordinary benign Chinese prose does not newly flag. Fixes NVIDIA#953 Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
…tespace scan The single refusal pattern started with an optional adverb group followed by a gap that matches whitespace. On a long separator run the regex engine tried that gap at every whitespace position and backtracked the whole run, which is quadratic and pushed the scan past the per-artifact runtime limit, leaving the cross-window separator test partial on PR NVIDIA#968 CI. Split the pattern into adverb-present and adverb-absent variants. Each variant starts with a required Chinese character, so non-matching text fails fast, and together they match exactly the phrases the single pattern matched. Add regression tests: refusal without the adverb still flags AR1, and a 50,000 space separator scans in under 5 seconds with no AR1 finding. Signed-off-by: Varshith Puli <pulivarshit@gmail.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.
Fixes #953
Gap
The static pattern layer (--no-llm) flagged English prompt-injection payloads but reported equivalent Chinese payloads as SAFE, because every pattern was English prose. Reproduced on the issue samples before this change: the Chinese override and jailbreak samples produced zero findings, the exfiltration sample produced only the URL-driven E1, and the extraction sample produced nothing.
Fix
Chinese patterns added to the existing lists, not a separate per-language module:
A shared helper in analyzers/common.py (chinese_spaced, CHINESE_GAP) matches each phrase character by character, allowing only separators between characters (whitespace, ideographic space, zero-width and bidi marks) and full-width punctuation or the particle de between phrase segments. That covers the issue variants: synonyms, traditional forms, inter-character spacing, and full-width punctuation.
Precision guards, chosen because #901/#902 just fixed false positives on ordinary prose: every pattern keeps its object noun or extraction verb, a bare mention of the system prompt or of unrestricted mode never matches, and the secrecy phrase alone never matches (it needs a send verb in the same paragraph).
Test evidence
Scope notes