Skip to content

Commit 3ec76fe

Browse files
fix(injection): redact interleaved evasion runs as one span (UnplugAI#121)
1 parent c924854 commit 3ec76fe

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All notable changes to the `unplug-ai` SDK.
66

77
### Fixed
88

9-
- `injection` scanner no longer flags ordinary non-English text (Cyrillic, CJK) as `invisible_text`; the trigger is narrowed to genuine zero-width/bidi control characters and mixed-script homoglyph smuggling, and the finding span is scoped to the offending characters instead of the whole message (#121)
9+
- `injection` scanner no longer flags ordinary non-English text (Cyrillic, CJK) as `invisible_text`; the trigger is narrowed to genuine zero-width/bidi control characters and mixed-script homoglyph smuggling, the finding span is scoped to the offending characters instead of the whole message, and an interleaved evasion run (e.g. zero-width chars between every letter) emits one finding covering the outer span so redaction replaces it with a single BLOCKED tag (#121)
1010

1111
## [0.6.0] — 2026-07-20
1212

‎sdk/src/unplug/scanners/injection/scanner.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ def _scan(self, text: TaintedText, context: ExecutionContext) -> Generator[Findi
121121
if _EVASION_STAGES.intersection(norm_result.stages_applied)
122122
else []
123123
)
124+
# When several evasion spans sit in one run (e.g. a word interleaved
125+
# with zero-width chars, "he\u200bl\u200bl\u200bo"), replace the whole
126+
# run with a single finding so redaction emits one BLOCKED tag instead
127+
# of one per offending character.
128+
if len(evasion_spans) > 1:
129+
evasion_spans = [(evasion_spans[0][0], evasion_spans[-1][1])]
124130
stages_used = ", ".join(sorted(_EVASION_STAGES.intersection(norm_result.stages_applied)))
125131
for span_start, span_end in evasion_spans:
126132
yield Finding(

‎sdk/tests/unit/scanners/test_scanners.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ def test_fullwidth_latin_span_scoped_to_offending_char(self):
8181
assert len(invisible) == 1
8282
assert (invisible[0].span_start, invisible[0].span_end) == (11, 12)
8383

84+
def test_interleaved_zero_width_emits_single_outer_span(self):
85+
raw = "h\u200be\u200bl\u200bl\u200bo w\u200bo\u200br\u200bl\u200bd"
86+
findings = self.scanner.scan(_make_text(raw), self.ctx)
87+
invisible = [f for f in findings if f.subcategory == "invisible_text"]
88+
assert len(invisible) == 1
89+
assert (invisible[0].span_start, invisible[0].span_end) == (1, 18)
90+
91+
def test_interleaved_zero_width_redacts_as_one_block(self):
92+
from unplug.config.policy import RedactionMode, ScanPolicy
93+
from unplug.core.redaction import apply_span_redactions
94+
95+
raw = "h\u200be\u200bl\u200bl\u200bo w\u200bo\u200br\u200bl\u200bd"
96+
findings = self.scanner.scan(_make_text(raw), self.ctx)
97+
redacted = apply_span_redactions(
98+
raw, findings, ScanPolicy(redaction_mode=RedactionMode.BLOCKED_TAGS)
99+
)
100+
assert redacted is not None
101+
assert redacted.count("[BLOCKED:injection]") == 1
102+
assert redacted == "h[BLOCKED:injection]d"
103+
84104
def test_cjk_text_not_invisible_text(self):
85105
text = _make_text("今天北京的天气很好,我想去公园散步。")
86106
findings = self.scanner.scan(text, self.ctx)

0 commit comments

Comments
 (0)