fix(injection-defense): detect single-bracket [INST]/[/INST] delimiter (#353) - #373
Open
gnanirahulnutakki wants to merge 1 commit into
Open
fix(injection-defense): detect single-bracket [INST]/[/INST] delimiter (#353)#373gnanirahulnutakki wants to merge 1 commit into
gnanirahulnutakki wants to merge 1 commit into
Conversation
#353) The delimiter_injection signature only matched the doubled [[INST]] and <|im_start|>, so the real single-bracket [INST] / [/INST] Llama/Mistral chat-template delimiter — the form an attacker actually uses to smuggle a new turn/role — passed the filter unflagged. Widen the regex to (?i)\[\s*/?\s*INST\s*\]|<\|im_start\|>|<</?SYS>>: matches [INST], [/INST], the doubled [[INST]] and internal-whitespace forms, plus the closely related Llama system delimiters <<SYS>> / <</SYS>>. Anchored to exactly INST/SYS so [INSTALL], [INSTRUCTIONS], [INFO], a[0] do not match. Add crates/injection-defense/tests/inst_delimiter_variants.rs covering both directions: the [INST] variants are now blocked as DelimiterAbuse, and representative benign bracketed text is not falsely flagged. Fixes #353 Checkpoint: architect/sessions/fix-353-inst-delimiter/journal.md Signed-off-by: GR <gnanirn@gmail.com> Signed-off-by: Gnani Nutakki <gnani.nutakki@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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.
Root cause
crates/injection-defense/src/pattern.rs— thedelimiter_injectionsignature was
r"\[\[INST\]\]|<\|im_start\|>". The\[\[INST\]\]alternativerequires a doubled bracket, so it only fired on
[[INST]]. The delimiterattackers actually use to smuggle a new turn/role — the single-bracket
Llama/Mistral chat-template markers
[INST]and[/INST]— matched nothingand passed the filter unflagged. Verified in-tree: the other delimiter
signatures (
system_directive_delimiter,role_tag_delimiter,<|im_start|>)did not cover this form, so single-bracket
[INST]was a genuine gap.Fix
Widen the one regex to:
[INST],[/INST], the doubled[[INST]](inner match), andinternal-whitespace forms like
[ INST ].<<SYS>>/<</SYS>>that pair with
[INST].<|im_start|>(ChatML).INST/SYS+ closing bracket, so benign bracketed text—
[INSTALL],[INSTRUCTIONS],[INFO],[INSTANCE], array indexinga[0]— does not match. No false positives.Tightest possible scope: one signature line changed, no new dependencies,
Cargo.lockuntouched.Regression tests
New
crates/injection-defense/tests/inst_delimiter_variants.rs, both directions:inst_delimiter_variants_are_blocked—[INST],[/INST],[[INST]],[ INST ],<s>[INST],<<SYS>>…<</SYS>>all →Block+DelimiterAbuse.benign_bracketed_text_is_not_flagged—[INSTALL],[INSTRUCTIONS],[INFO],a[0],[INST. of Tech],[instance]all →Allow, noDelimiterAbuse.Verification (all green locally)
cargo test -p ardur-injection-defense— pass (incl. 2 new tests)cargo test -p ardur-e2e-tests— passcargo clippy -p ardur-injection-defense --all-targets -- -D warnings— cleancargo fmt --check— cleanFixes #353