Skip to content

Commit e6fe562

Browse files
committed
Raise math-alphanumeric evasion threshold to 4 chars
The 2-character minimum blocked ordinary math notation that strings several styled variables together ("let f(x) = ax + b", "define xy as the product") — benign runs top out at 2-3 characters, well within the old threshold. Measured against five benign math samples and the three styled attack payloads from UnplugAI#131: benign tops out at 2, payloads run 9-12. Moved the minimum to 4, comfortably inside that gap. Per review on UnplugAI#151. Drafted with Claude Code, I reviewed and tested it.
1 parent ba06a7f commit e6fe562

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@
3535
# Mathematical alphanumeric symbols (U+1D400-U+1D7FF: bold, italic, script,
3636
# fraktur, double-struck, sans-serif, monospace letters/digits) normalize
3737
# straight to ASCII under NFKC, same as the confusables above. Unlike those,
38-
# a single styled symbol shows up in ordinary prose ("the field \U0001d53d"),
39-
# so this block can't be treated as unconditionally suspicious. A whole word
40-
# rendered in these characters is evasion; one isolated symbol is not, so
41-
# only runs of two or more count as a span.
38+
# ordinary math notation strings several styled variables together ("let
39+
# f(x) = ax + b", "define xy as the product"), so this block can't be
40+
# unconditionally suspicious at any short run length. Benign notation tops
41+
# out at 2 adjacent styled characters; a payload rendered in math-bold runs
42+
# 9-12. The threshold sits between the two: below it is notation, at or
43+
# above it is a styled word.
44+
_MATH_ALPHANUMERIC_MIN_RUN = 4
4245
_MATH_ALPHANUMERIC_RE = re.compile(r"[\U0001d400-\U0001d7ff]+")
4346
_WORD_RE = re.compile(r"\w+")
4447

@@ -66,7 +69,7 @@ def _evasion_spans(original: str) -> list[tuple[int, int]]:
6669
spans.append((match.start(), match.end()))
6770

6871
for match in _MATH_ALPHANUMERIC_RE.finditer(original):
69-
if match.end() - match.start() >= 2:
72+
if match.end() - match.start() >= _MATH_ALPHANUMERIC_MIN_RUN:
7073
spans.append((match.start(), match.end()))
7174

7275
# A homoglyph is only suspicious when a non-Latin character sits inside a

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ def test_single_math_symbol_not_invisible_text(self):
9999
findings = self.scanner.scan(text, self.ctx)
100100
assert not any(f.subcategory == "invisible_text" for f in findings)
101101

102+
def test_adjacent_math_variables_not_invisible_text(self):
103+
# Ordinary notation strings several styled variables together
104+
# ("ax", "f(x)") — short runs of 2-3, well under the styled-word
105+
# threshold. Flagging these blocks benign math prose. See PR #151
106+
# review.
107+
text = _make_text(
108+
"let \U0001d453(\U0001d465) = \U0001d44e\U0001d465 + \U0001d44f for all \U0001d465."
109+
)
110+
findings = self.scanner.scan(text, self.ctx)
111+
assert not any(f.subcategory == "invisible_text" for f in findings)
112+
102113
def test_interleaved_zero_width_emits_single_outer_span(self):
103114
raw = "h\u200be\u200bl\u200bl\u200bo w\u200bo\u200br\u200bl\u200bd"
104115
findings = self.scanner.scan(_make_text(raw), self.ctx)

0 commit comments

Comments
 (0)