Repository navigation
fix(security): detect paraphrased, spaced, homoglyph and non-English injection variants before scan approval (SEC-01) - #1588
Merged
Conversation
…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.
Deploying mcpproxy-docs with
|
| Latest commit: |
277f1c2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://eadaa745.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-assess-detector-admissio.mcpproxy-docs.pages.dev |
…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).
… bound its gap (SEC-01 review)
…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.
…efore clause splitting (SEC-01 review)
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 38167911161 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Problem
Assessment 2026-10-11, finding SEC-01 (P1, work package W04): under
trust_mode: scana changed tool definition is auto-approved when the offline scan is fully covered and returnsclean(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 scannedcleanand were persisted asscan-approved. The detector only matched literal English phrases.Revalidated on current
mainbefore any change. The assessment probe reproduces unchanged. On a rebuilt daemon each hostile variant was approved and invoked the upstream through the wrapper, direct andcode_executionroutes, and stayed approved across a restart.Behaviour after this PR
De-obfuscation (
detect.NormalizeForPhrase, exposed asToolView.PhraseText) handles:i.g.n.o.r.e,ig-no-re)i g n o r e)NormalizedTextand its other consumers are unchanged.New matching:
directive.imperativefamilies for: voiding prior instructions, pivoting to disclosure, paraphrased system-prompt disclosure, and reassigning authorityTiering (conservative):
warnings) and never auto-quarantines.main, run on plain normalized text, so this PR adds no new HARD false-positive path.directive.imperativematches 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
internal/security/scanner/testdata/sec01_injection_variants.json):known_gap)dangerousmain. On the reference-server corpus (45 tools), 0 are held. The test enforces both ceilings.TestScanMode_SEC01_ObfuscatedRugPullsAreHeldfails onmainand passes here.go test -race ./internal/security/... ./internal/runtime/...passes.-tags server, reports 0 issues oninternal/security.mainon 25–410 KB descriptions.code_execution)Finding status
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
trust_mode: scan. This is the intended fix.tools/list_changedcan 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