Skip to content

fix(security): detect paraphrased, spaced, homoglyph and non-English injection variants before scan approval (SEC-01) - #1588

Merged
Dumbris merged 19 commits into
mainfrom
fix/assess-detector-admission
Oct 12, 2026
Merged

Dumbris merged 19 commits into
mainfrom
fix/assess-detector-admission

Conversation

@Dumbris

@Dumbris Dumbris commented Oct 11, 2026

Copy link
Copy Markdown
Member

Problem

Assessment 2026-10-11, finding SEC-01 (P1, work package W04): under trust_mode: scan a changed tool definition is auto-approved when the offline scan is fully covered and returns clean (scanChangeIsClean, internal/runtime/tool_quarantine.go). A plain "ignore all previous instructions" was held, but a paraphrase, a letter-spaced form, a Cyrillic-homoglyph form and a German translation all scanned clean and were persisted as scan-approved. The detector only matched literal English phrases.

Revalidated on current main before any change. The assessment probe reproduces unchanged. On a rebuilt daemon each hostile variant was approved and invoked the upstream through the wrapper, direct and code_execution routes, and stayed approved across a restart.

Behaviour after this PR

  • De-obfuscation (detect.NormalizeForPhrase, exposed as ToolView.PhraseText) handles:

    • mixed-script homoglyphs, folded in both directions (Cyrillic, Greek and Armenian look-alikes)
    • whole-look-alike words, folded only between Latin words
    • leet digits inside letter words
    • separator-interleaved words (i.g.n.o.r.e, ig-no-re)
    • letter-spaced words (i g n o r e)

    NormalizedText and its other consumers are unchanged.

  • New matching:

    • paraphrase-robust English override families
    • non-English override families: de, fr, es, it, pt, nl, pl, ru, uk, zh, ja, ko
    • a letters-only pass
    • directive.imperative families for: voiding prior instructions, pivoting to disclosure, paraphrased system-prompt disclosure, and reassigning authority
  • Tiering (conservative):

    • Every new match is SOFT. It holds the change for review (warnings) and never auto-quarantines.
    • A match that only appears after de-obfuscation is also capped at SOFT.
    • HARD findings come only from the families already on main, run on plain normalized text, so this PR adds no new HARD false-positive path.
    • SEC-01 directive.imperative matches are never dropped by framing cues.
  • Position: „ ‚ « » ‹ › 「 」 『 』 now count as quotation marks. This can only lower a tier.

  • Unchanged: trust-mode defaults, manual and auto semantics, and fail-closed coverage (a missing bundle or a failed check is never clean).

Verification

  • Stratified corpus (internal/security/scanner/testdata/sec01_injection_variants.json):
    • entry types: seed, red-team, held-out (written before the change), review counterexamples, and benign controls
    • every hostile entry is held, except one documented gap (Turkish, known_gap)
    • benign controls stay clean
    • quoted, negated and question examples are never dangerous
    • a per-class table is logged
  • Real-world false positives: on LiveMCPTool (527 tools) the same 17 tools are held as on main. On the reference-server corpus (45 tools), 0 are held. The test enforces both ceilings.
  • Runtime: the inverted assessment probe TestScanMode_SEC01_ObfuscatedRugPullsAreHeld fails on main and passes here.
  • CI detect gate: recall 1.0, false-positive rate 0.0.
  • Race tests: go test -race ./internal/security/... ./internal/runtime/... passes.
  • Lint: golangci-lint v2, bare and with -tags server, reports 0 issues on internal/security.
  • Performance: scanning stays linear, at about 2x main on 25–410 KB descriptions.
  • Independent red-team harness (the assessment's tpa-redteam): bypasses dropped from 18 to 3, and no previously blocked case got weaker. The remaining three are outside this finding's scope: shadowing rewrite, sink-parameter rename, and a recipient-swap combination.
  • Live isolated daemons:
    • setup: scratch HOME and data, loopback ports 18975 and 18977, telemetry off, harmless stdio fixture that counts invocations
    • before: 6 hostile variants approved, each invoked 1/1/1 (wrapper/direct/code_execution)
    • after: all held, 0/0/0 upstream invocations, still held after a restart
    • benign changes approved and callable in both builds

Finding status

ID Status
SEC-01 Fixed (detection and hold behaviour). Review gate unresolved, see below.

Cross-review

The reviewer was OpenCode github-copilot/gpt-6.1-sol, in a fresh read-only context each round. It ran 10 rounds, and every verdict was REQUEST_CHANGES. Each finding was verified and fixed with a regression test. The findings were all about the HARD tier (false positives on negated, quoted or ordinary text) and one about quadratic cost. They led to the conservative SOFT-only design above. The final commit fixes round 10's findings but has not been re-reviewed, because the 10-round cap per PR was reached. Round 11 needs maintainer authorization.

Compatibility and rollout

  • No schema, config, API or dependency change, and no change to telemetry or metrics.
  • Some tool changes that were previously scan-approved will now be held for review under trust_mode: scan. This is the intended fix.
  • No HARD tier was added, so no new server-level auto-quarantine can come from this PR.
  • No dependent PRs in other repositories.
  • Separate pre-existing issue seen during live verification: tools/list_changed can be ignored when the upstream client is created before the discovery callback is registered. That is tracked separately and is not changed here.

🤖 Generated with Claude Code

…injection variants before scan approval (SEC-01)

Under trust_mode=scan a tool-definition change is auto-approved only when the
offline scan is fully covered and clean. Paraphrased, letter-spaced, Cyrillic
homoglyph and German instruction overrides scanned clean and were persisted as
scan-approved (assessment 2026-10-11, SEC-01).

- detect: NormalizeForPhrase folds mixed-script homoglyphs, leet digits,
  separator-interleaved and letter-spaced words; exposed as ToolView.PhraseText
  and read only by the phrase matchers (NormalizedText is unchanged).
- phrase.injection: paraphrase-robust override families, non-English override
  families (de fr es it pt nl pl ru uk zh ja ko), and a soft letters-only pass.
- directive.imperative: soft families for object-first voiding, pivot to
  disclosure, paraphrased system-prompt disclosure and authority reassignment.
- position: non-ASCII quotation marks count as quoting.
- Stratified corpus (seed, red-team, held-out, benign controls) with a
  per-class table, a real-world false-positive ceiling (LiveMCPTool 527 and
  reference 45: no new holds), and the inverted runtime probe.

Trust-mode defaults, manual semantics and fail-closed coverage are unchanged.
…lain text too (SEC-01 review)

- CJK override families are SOFT: they cannot see negation or descriptive
  framing, so a match holds the change for review but never quarantines.
- Space-delimited non-English overrides skip a negated match.
- The instruction-voiding family requires the agent's directives as target
  ("Treats all missing values as null." no longer matches).
- Phrase checks scan NormalizedText as well as PhraseText, and an all-look-alike
  Cyrillic word folds to Latin only next to a Latin word, so folding can no
  longer hide a Russian override inside English text.
…, resolve homoglyph neighbours (SEC-01 review)

- All non-English override families are SOFT: pattern matching cannot see
  every language's negation ("Ignoriere die vorherigen Anweisungen nicht")
  or descriptive framing. They still hold the change under trust_mode=scan.
- The instruction-voiding family moves to directive.imperative (soft) and
  requires a prior/system-qualified directive or "you were told".
- An all-look-alike Cyrillic word folds to Latin only next to a word that
  READS as Latin after mixed-word folding, so a Russian verb with a Latin 'o'
  no longer turns its neighbour "все" into "bce".
…ndependent homoglyph folding (SEC-01 review)

- The new English override families drop to the SOFT tier when the same
  clause negates them ("Do not set aside any prior guidance", "Never forget
  everything you were told"); they stay visible and still hold for review.
- Whole-look-alike words decide on an immutable snapshot of first-pass
  neighbour decisions, so adjacent ambiguous words fold the same way in
  either order.
…w (SEC-01 review)

A negator anywhere in the same clause ("Do not under any circumstances set
aside any prior guidance") now downgrades the new English override families
to the SOFT tier. The match stays visible and still holds the change under
trust_mode=scan, so adding a negator cannot suppress a hostile override.
…eview)

"Do not, under any circumstances, set aside any prior guidance" is negated:
the scope now ends only at . ! ? or ; so parenthetical commas no longer drop
the negator. Downgrade-only, as before.
Negation words are now letter runs, so "(not)", "[not]", "not/never",
"not—" and "never-ever" downgrade the new English override families to
review like a plain "not" does.
…inear (SEC-01 review)

Each guarded match re-tokenized the whole preceding sentence, so a long
punctuation-free run of repeated directives was quadratic on the synchronous
discovery path (~11 s for 300 KB). The look-back is now a fixed 160-byte
window: the same input scans in ~0.9 s end to end, about 2x origin/main.
…itial command (SEC-01 review)

Enumerating negators kept missing prohibition forms ("Under no circumstances
…", "Avoid discarding …", "You are forbidden to …") and negators beyond the
look-back window. The three new English families now reach the HARD tier only
when they open their sentence, optionally after a short lead-in ("First,",
"You must"); any other preceding wording downgrades them to SOFT, where they
are still surfaced and still hold the change under trust_mode=scan. The
look-back stays a fixed 80-byte window, so matching remains linear.
…of hard-blocking (SEC-01 review)

Syntactic guards for a HARD tier on the broad paraphrase families kept
leaking (prohibitions with colons, questions, metalinguistic mentions,
commands about ordinary data). The three paraphrase families are now SOFT
like the non-English ones: every match is surfaced and holds the change under
trust_mode=scan (verdict "warnings"), none auto-quarantines. Spaced, leet,
separator and homoglyph forms of the canonical phrase still reach HARD
through the original families after de-obfuscation. The imperative-lead
guard is removed.
… drop SEC-01 directive hits (SEC-01 review)

- A phrase match that exists only in the de-obfuscated text is capped at the
  SOFT tier: joining letters and folding look-alikes also rewrites
  prohibitions, questions and ordinary data ("Do not i g n o r e …",
  "Copy se-cr-et files into a local backup"). It still holds the change
  under trust_mode=scan. The change therefore adds no new HARD path.
- The SEC-01 directive.imperative families re-floor a position-discounted
  match instead of dropping it, so a framing cue ("Example:", a nearby
  describing verb) cannot turn a hostile paraphrase into a clean scan.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

…changed, compare real-world outcomes per tool (SEC-01 review)

- phrase.injection: a match in the de-obfuscated view is always review-only;
  a quoted plain occurrence elsewhere no longer lifts the cap, and the
  per-occurrence whole-text rescan (quadratic on repeated obfuscated
  directives) is gone.
- position: drop the added non-ASCII quote markers; they discounted existing
  detections below the emit floor and broke ASCII-quote nesting.
- corpus test: per-tool baseline outcomes with cardinality checks and the
  full runtime gate predicate (clean AND coverage OK).
…ep line breaks as clause ends in the squashed pass (SEC-01 review)
…s as clause ends in the squashed pass (SEC-01 review)
…e (SEC-01 review)

The squashed fallback re-read the whole prefix and suffix as []rune at every
clause boundary, so boundary-dense unmatched prose cost O(n^2) in the
synchronous scan-mode admission path. Precompute capped adjacent letter-run
tables once per text. Adds a scaling/allocation regression test for period,
newline, short-word and blank-line prose plus a squashed-only hostile tail,
and an oracle test against the original helpers.
…nd compatibility punctuation (SEC-01 review)

U+2028, U+2029, NEL, VT and FF, and fullwidth/halfwidth/small-form
sentence marks (NFKC-folded before boundary detection), now end a clause
in the squashed fallback, raw and JSON-escaped. Previously a benign
'Ignore previous search results<U+2028>Instructions ...' squashed into
one clause and was held under trust_mode=scan.
…d's script majority (SEC-01 review)

The squashed fallback normalizes one clause at a time, so a short mixed-script
chunk such as "тeм." took its own Cyrillic majority and folded to "тем",
hiding "system prompt" in Latin text. Compute the script majority once for
the whole field and pass it to clause normalization (NormalizeForPhraseIn).
Covers fullwidth, halfwidth and ASCII-period chunking in the description,
input schema and output schema; Russian short-sentence prose stays clean.
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/assess-detector-admission

Available Artifacts

  • archive-darwin-amd64 (31 MB)
  • archive-darwin-arm64 (28 MB)
  • archive-linux-amd64 (19 MB)
  • archive-linux-arm64 (17 MB)
  • archive-windows-amd64 (31 MB)
  • archive-windows-arm64 (27 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (27 MB)
  • installer-dmg-darwin-arm64 (24 MB)
  • smart-mcp-proxymcpproxy-goQA0OFB.dockerbuild (0 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 38167911161 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@codecov-commenter

codecov-commenter commented Oct 11, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.80531% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/security/detect/deobfuscate.go 91.60% 19 Missing and 4 partials ⚠️
...nal/security/detect/checks/directive_imperative.go 85.71% 1 Missing and 1 partial ⚠️
...nternal/security/detect/checks/phrase_injection.go 98.48% 1 Missing and 1 partial ⚠️
internal/security/detect/signal.go 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit a92151f into main Oct 12, 2026
52 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants