Commit Graph
24 Commits
Author SHA1 Message Date
yetone 2b2abec457 redact: a one-word name the model flags goes out only beside a thing's word, never alone or in tool arguments
With a model that labels Rina a PERSON, at origin/main 49c9491b7, these
went out unmasked through 4e7661adc's app-name exemption (thingNamed):
a tool_use {"recipient":"Rina"} and user content "Rina" (namesOnly took
one capitalized word for a list of app names), "Rina's Mac won't boot"
and "Rina uses Windows at home" (an app's or a system's word anywhere in
the clause, thingWords, counted as a cue).

thingNamed now:
- treats a possessive right after the word ('s, ’s) as a person's;
- no longer takes a thing word (or a Chinese one, zhThingWords, now
  gone) anywhere in the clause as a cue: only the word right before or
  after counts (using X, the X app, X vs, X 这个软件), or the item's
  place in a list of apps;
- takes a text of names only when it has two of them at least.
personFits never applies the exemption in a tool call's arguments
(Options.args, set by MaskJSON under args or an "arguments" string).

Cases 4e7661adc was written for that are exactly the leak, and are
masked now (filed as #5506):
- "Muesli" alone (thingname_test, and eval case app-alone, now Keep
  with Known #5506 for Privacy Filter);
- "Which is better for notes on my Mac, Cicada or Mimi?" and the
  "Cicada 和 Mimi 呢" half of "Parakeet 这个软件很好用,Cicada 和 Mimi
  呢?", whose only cue is elsewhere in the sentence. They are taken out
  of TestAppNamesNotPersons; "Parakeet 这个软件很好用。" stays.
- TestPersonBesideAppStillMasked's lone "Mimi" was let go "by design";
  it is masked now.
The rest of TestAppNamesNotPersons (the bare list, "Cicada and Mimi",
the Markdown list, switched to, crashes, using, vs, apps like) and every
other eval case pass unchanged.

TestFirstNameNearAThingMasked holds the four reported texts, ’s,
"Send the license to Rina." and three bodies (user text, tool_use input,
a function_call's arguments string), and that "using Rina" and "the Rina
app" still go as written. Broken by hand: with thingname.go, model.go,
redact.go and json.go as on main it fails on all 9 masked cases (and the
lone Mimi); with only the args flag forced off, the two tool-argument
cases with an app's word beside the name ("install Rina", "using Rina")
go out.

Run at 4c0e22aa7, this stack's head on origin/main c6b7bbedf, on mote:
- gofmt -l clean on the changed files.
- go vet -tags nogui, GOOS=linux go vet -tags nogui (./internal/redact
  ./internal/gateway) and GOOS=windows go vet ./internal/redact: clean.
- go test -tags nogui ./internal/redact ./internal/gateway -count=1
  -timeout 45m: ok (redact 2.6s, gateway 1837s at load ~100).
Not run: go test ./... (the change is internal/redact only) and the
GUI suite (no GUI file touched).
2026-11-06 18:36:19 +08:00
yetone d7714b3f3b redact: every tool call's arguments are the tool's, mcp_tool_use and Responses *_call included
With Secrets and Personal masking on, at origin/main 49c9491b7, an
Anthropic mcp_tool_use block's input was not counted as tool arguments:
scan knew only tool_use and server_tool_use. The protocol's key-name
exemptions (data, url, signature, *_id) then held inside what the model
wrote, so a phone under "data", a card under "customer_id", an email
under "signature" and an sk-ant key in a "url" went out as written. The
same held for every object-shaped tool call outside those two: a
Responses function_call, mcp_call or tool_search_call's arguments, a
custom_tool_call's input, a local_shell_call/shell_call/computer_call's
action, an apply_patch_call's operation, and a Chat Completions (or
Ollama) tool_calls[].function.arguments or legacy function_call given as
an object. scan's first look also searched for `"tool_use"` with its
quote, which `"mcp_tool_use"` doesn't contain, so a body with no tools
array skipped the walk altogether.

toolArgs now names the class: the input of any *_tool_use, the
arguments, input, action or operation of any *_call, and the
arguments/args under function, function_call or functionCall (Gemini's
args as before). The first look searches for `tool_use"`, `_call"` and
"arguments". A call's own id, name and server_name stay as they are
(they are siblings of the arguments, not under them).

TestEveryToolCallsArgumentsAreMasked loops over all 15 shapes with a
phone under data, an sk-ant key in a url, a card under customer_id and an
email under signature, and checks ids, name and server_name are kept.
Broken by hand: with json.go as on main it is red for mcp_tool_use, chat
tool_calls, chat function_call and the 8 Responses types, each value
"went out"; tool_use, server_tool_use and both Gemini shapes passed on
main too.

Not tried: a real vendor request with an mcp_tool_use replayed; the
masked values come back through the same restore as any tool_use's.

Run at 4c0e22aa7, this stack's head on origin/main c6b7bbedf, on mote:
- gofmt -l clean on the changed files.
- go vet -tags nogui, GOOS=linux go vet -tags nogui (./internal/redact
  ./internal/gateway) and GOOS=windows go vet ./internal/redact: clean.
- go test -tags nogui ./internal/redact ./internal/gateway -count=1
  -timeout 45m: ok (redact 2.6s, gateway 1837s at load ~100).
Not run: go test ./... (the change is internal/redact only) and the
GUI suite (no GUI file touched).
2026-11-06 18:36:19 +08:00
yetoneandggbdpq e4b0555a17 redact: a timestamp under a token's field name is not masked as a secret (#5002)
"access_token_expires_at": "2026-08-30T11:44:31.312645+08:00" went out as
"{{SECRET_…}}:44:31.312645+08:00": the field's name has token in it, and
the SECRET rule took the timestamp's head up to the hour (its colons are
not a secret's characters), so 2026-08-30T11 was masked and the rest was
sent as written. The same happened after 令牌是, 密钥为, token 是,
SERVER_KEY: and DB_PASS:, and in a tool call's arguments the whole value
was masked by its field's name (namedSecret).

An RFC 3339 timestamp, whole or its head to the hour, is now left as
written there (timestampValue, beside versionValue and pathValue in
fieldAt, keyAt and namedSecret). The exemption is by the value's shape,
not the key's name: a value that only starts as a timestamp
(2026-08-30T11x9k2abc) still masks, and a secret beside the timestamp in
the same tool call still masks.

Changed from the contributor's patch: the patch deleted fieldAt's doc
bullet for the next-field rule (nextField), which still exists; it is
kept.

Run (mote): go test -tags nogui ./internal/redact/... ./internal/pii/...
./internal/masking/... (ok); go vet -tags nogui ./internal/redact/...;
gofmt -l (empty).
Broken by hand: with the old fieldvalue.go, json.go and redact.go,
TestTimestampIsNoSecret fails on the reporter's line with the same
output as the report ("{{SECRET_2ojutfrk}}:44:31.312645+08:00") and on
the other lines.
Not tried: the local masking model on the reporter's whole request.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:06:51 +08:00
yetone 45385f0eed redact: a secret's field name masks only in a tool's arguments and result, with secrets on (#2946)
#2946's patch masked any JSON value whose field name looks like a
secret's (api_key, password, *_token) anywhere in a request body outside
tool definitions. That is an exemption, and a mask, keyed on a field's
name: it rewrote what the agent itself sends (mcp_servers'
authorization_token, a top-level api_key, metadata.session_token) as
well as the user's data. The name check now runs only where the user's
data sits in the protocol: a tool call's arguments (Anthropic tool_use
input, OpenAI arguments, Gemini functionCall args) and a tool's result
(Gemini functionResponse.response is added to the places scan reads),
and only with secrets masking on.

The Authorization/Cookie rule masked the word after the header name in
prose too ("Authorization: required for this route"). It now masks only
a value with a credential's shape: one token, or a scheme word and a
token, of 8 or more characters with a non-letter and not a ${VARIABLE};
or name=value cookie pairs.

Tests: TestMaskJSONNamedSecrets puts its values in tool_use input,
functionCall args and functionResponse response;
TestMaskJSONSecretNamesOnlyInToolArgs holds the agent's own fields as
written and nothing masked with secrets off; TestMaskAuthHeaders gains
prose rows (no mask) and a Cookie row.
docs/subsystems/gateway-routing.md says where the name check runs.

Landing record (yetone):
Run at the pushed batch head (tree a6b084d0b, on origin/main 616405061),
go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider and internal/plugin (this batch's
packages and those main changed since the full run): all ok. gofmt -l
clean; go vet ./... (darwin), GOOS=linux and GOOS=windows go vet -tags
nogui ./... clean. internal/gui on macOS (mote-run):
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
(#3949), both red at main too.
- The full go test ./... -timeout 45m -count=1 ran one rebase earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2 (main then gained 5bfa9f076's
group stand-in, b19d08593, f856d381a and 616405061). It ran on Linux
(wsl-run): 82 packages ok. internal/agent has 4 reds, all red at
origin/main on that box as well: TestInstalledVersion,
TestGrokInstalled, TestOmpDetectedWithPiDir and
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, #3548). The root
package and internal/cli need gtk4 to build, so they ran on macOS
(mote-run): ok. TestColdTurnsTaken (#4510) was red there once. An
earlier full run at base d307aa648 was red once in
TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone at both
the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
Broken by hand: the name check's scope put back to everywhere but tool
definitions: TestMaskJSONSecretNamesOnlyInToolArgs goes red; headerValue
made to accept anything: TestMaskAuthHeaders' prose rows go red;
restored, green.
Not tried: a real agent's request through the gateway with masking on.

#2946's patch masked any JSON value whose field name looks like a
secret's (api_key, password, *_token) anywhere in a request body outside
tool definitions. That is an exemption, and a mask, keyed on a field's
name: it rewrote what the agent itself sends (mcp_servers'
authorization_token, a top-level api_key, metadata.session_token) as
well as the user's data. The name check now runs only where the user's
data sits in the protocol: a tool call's arguments (Anthropic tool_use
input, OpenAI arguments, Gemini functionCall args) and a tool's result
(Gemini functionResponse.response is added to the places scan reads),
and only with secrets masking on.

The Authorization/Cookie rule masked the word after the header name in
prose too ("Authorization: required for this route"). It now masks only
a value with a credential's shape: one token, or a scheme word and a
token, of 8 or more characters with a non-letter and not a ${VARIABLE};
or name=value cookie pairs.

Tests: TestMaskJSONNamedSecrets puts its values in tool_use input,
functionCall args and functionResponse response;
TestMaskJSONSecretNamesOnlyInToolArgs holds the agent's own fields as
written and nothing masked with secrets off; TestMaskAuthHeaders gains
prose rows (no mask) and a Cookie row.
docs/subsystems/gateway-routing.md says where the name check runs.

Landing record (yetone):
Run at tree 7d7955eb9 (this batch on origin/main 3cfba2e37), go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider, internal/agent and internal/usage
(this batch's packages, plus those main changed since the full run): all
ok except internal/agent's TestInstalledVersion, TestGrokInstalled and
TestOmpDetectedWithPiDir, red at origin/main on that box too (#4033,
#3548). gofmt -l clean; go vet ./... (darwin), GOOS=linux and
GOOS=windows go vet -tags nogui ./... clean. On macOS (mote-run), the
root package and internal/cli ok; internal/gui red in
TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
(#3949) and TestColdTurnsTaken (#4510), the first two red at main too.
- The full go test ./... -timeout 45m -count=1 ran two rebases earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2, on Linux (wsl-run): 82
packages ok, internal/agent's 4 reds as above, plus
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, red at main). The
root package, internal/cli and internal/gui need gtk4 to build, so they
ran on macOS as above. An earlier full run at base d307aa648 was red
once in TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone
at both the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
- Rebased after these runs onto origin/main c1457f2ee. Its two commits
since 3cfba2e37 (3f2faef62 gui, c1457f2ee agent) touch neither
internal/gateway nor internal/redact, nor any file this batch changes,
and were not run again here.
Broken by hand: the name check's scope put back to everywhere but tool
definitions: TestMaskJSONSecretNamesOnlyInToolArgs goes red; headerValue
made to accept anything: TestMaskAuthHeaders' prose rows go red;
restored, green.
Not tried: a real agent's request through the gateway with masking on.
2026-11-01 06:38:01 +08:00
ggbdpq 9a05a7bcec redact: the mask covers ark- keys, _KEY/_PASS names, auth headers, and JSON field names (#2946)
What changed (one per gap the reporter reproduced on main):

- API_KEY gains the ark- value shape (#2946): Volcano Ark and the relays
  in front of it issue keys with an ark- prefix, and no value rule knew
  one. ARK_API_KEY=<ark key> was masked already (its name has api_key in
  it); ARK_KEY=<ark key>, a key in prose and one in a request body went
  as they were.
- A new SECRET rule takes an upper-case env var whose name only ends in
  KEY or PASS: SERVICE_X_KEY=…, FOO_KEY=…, DB_PASS=… — quoted or not.
  Upper case is the boundary: in the lower case a name that ends in key
  is code's (a sort_key:, a cache_key:, a public key =), so nothing of
  TestMaskGatewayKey's rows moves; notAPlainKey turns the upper-case
  SORT_KEY/PUBLIC_KEY/PROMPT_CACHE_KEY/CACHE_KEY away too.
- A new SECRET rule takes the value of an Authorization: or Cookie:
  header line, whatever it looks like — the opaque bearer tokens and
  session values the shape rules had no eye for (#2946).
- MaskJSON masks the value of a field named for a secret by its name,
  before the ids and names that would keep it: {"api_key": "…"} with a
  value no rule knows, {"db_pass": "…"}, an AKIA under access_key_id
  (its _id kept it from the value's own AKIA rule), {"Authorization":
  "Bearer …"} and {"Cookie": "…"} (#2946). signature,
  encrypted_content and data: values still go as written (#1911), and
  the tools' definitions are untouched. SecretName now says a name
  ending in pass is a secret's name too, so the archive (ScrubJSON) and
  MaskJSON judge a field by the same names.

Why: the reporter's five examples each leak a credential whose value has
no key's shape; the rules judged values by shape alone and field names
only ever kept a value. The boundary the reporter warned about —
sort_key, cache_key, prompt_cache_key, public_key must stay unmasked —
is held by case (lower-case names never enter the new rules) and by
notAPlainKey for the upper-case ones.

Run (rebased onto 9ae79122, upstream/main 10-27): the 18 upstream redact commits since
9b0f4861 (714ab8e8 CJK password rule .. 25341b4c address narrowing) add CJK-named
secret rules, made-up key forms and narrow emails and addresses — none covers
the five families here, so the rules take them side by side; the shared
secretNames rule carries upstream's new notCode boundary (511c4a76). The
_KEY/_PASS rule's boundary is notPlainKeyOrCode (plain key names and code
naming a secret both stay), the same resolution 2ea09ec3 on
codex/verify-2946-redact carried and the issue thread endorsed:
Refs #2946

Review: the ark- key, _KEY/_PASS assignment and Authorization/Cookie
rules land as written here. Two parts were narrowed in this batch's
redact follow-up ("a secret's field name masks only in a tool's
arguments"): a secret's JSON field name now masks only where the user's
data sits (a tool call's arguments and a tool's result, with secrets
on), never across the whole body by name, and an Authorization or Cookie
line masks only when what follows has a credential's shape. None of the
redact commits on main since 10-27 covered these five families.

Landing record (yetone):
Run at the pushed batch head (tree a6b084d0b, on origin/main 616405061),
go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider and internal/plugin (this batch's
packages and those main changed since the full run): all ok. gofmt -l
clean; go vet ./... (darwin), GOOS=linux and GOOS=windows go vet -tags
nogui ./... clean. internal/gui on macOS (mote-run):
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
(#3949), both red at main too.
- The full go test ./... -timeout 45m -count=1 ran one rebase earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2 (main then gained 5bfa9f076's
group stand-in, b19d08593, f856d381a and 616405061). It ran on Linux
(wsl-run): 82 packages ok. internal/agent has 4 reds, all red at
origin/main on that box as well: TestInstalledVersion,
TestGrokInstalled, TestOmpDetectedWithPiDir and
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, #3548). The root
package and internal/cli need gtk4 to build, so they ran on macOS
(mote-run): ok. TestColdTurnsTaken (#4510) was red there once. An
earlier full run at base d307aa648 was red once in
TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone at both
the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
Broken by hand: gua's ablations, in the thread. The narrowing is broken
by hand in that follow-up.
Not tried: a real vendor request carrying these values through the
gateway; the rules were tested in internal/redact only.

Review: the ark- key, _KEY/_PASS assignment and Authorization/Cookie
rules land as written here. Two parts were narrowed in this batch's
redact follow-up ("a secret's field name masks only in a tool's
arguments"): a secret's JSON field name now masks only where the user's
data sits (a tool call's arguments and a tool's result, with secrets
on), never across the whole body by name, and an Authorization or Cookie
line masks only when what follows has a credential's shape. None of the
redact commits on main since 10-27 covered these five families.

Landing record (yetone):
Run at tree 7d7955eb9 (this batch on origin/main 3cfba2e37), go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider, internal/agent and internal/usage
(this batch's packages, plus those main changed since the full run): all
ok except internal/agent's TestInstalledVersion, TestGrokInstalled and
TestOmpDetectedWithPiDir, red at origin/main on that box too (#4033,
#3548). gofmt -l clean; go vet ./... (darwin), GOOS=linux and
GOOS=windows go vet -tags nogui ./... clean. On macOS (mote-run), the
root package and internal/cli ok; internal/gui red in
TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
(#3949) and TestColdTurnsTaken (#4510), the first two red at main too.
- The full go test ./... -timeout 45m -count=1 ran two rebases earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2, on Linux (wsl-run): 82
packages ok, internal/agent's 4 reds as above, plus
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, red at main). The
root package, internal/cli and internal/gui need gtk4 to build, so they
ran on macOS as above. An earlier full run at base d307aa648 was red
once in TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone
at both the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
- Rebased after these runs onto origin/main c1457f2ee. Its two commits
since 3cfba2e37 (3f2faef62 gui, c1457f2ee agent) touch neither
internal/gateway nor internal/redact, nor any file this batch changes,
and were not run again here.
Broken by hand: gua's ablations, in the thread. The narrowing is broken
by hand in that follow-up.
Not tried: a real vendor request carrying these values through the
gateway; the rules were tested in internal/redact only.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 06:38:00 +08:00
yetone 5218119456 redact: every reply gets its values back, a turn that masked nothing too
yapechan123 (Discord) saw a table the model wrote come back as
{{PERSON_kb32hzkg}}、{{PERSON_iye66366}} and {{PERSON_isyrz5ih}}、
{{PERSON_j5kluh3x}}, all four in canonical form. Every way a placeholder
could come back unrestored was probed with those literal bytes, on each
protocol's stream split at every byte and at 1..7 runes, and whole:

- The gateway put no restoring writer on a reply when the request in
  hand masked nothing (redactedHits, redactedPromptHits returned early
  on n == 0). A vendor that holds the conversation (Codex's compacted
  history, a server-side session) answers with placeholders of earlier
  turns while the request carries no value, so they went back as
  written. Most likely the reporter's path. Now every reply on a masked
  route is read.
- Responses streams: each event's random "obfuscation" string could end
  like a placeholder start and take the stream's one held tail from its
  delta, so the placeholder after 、 stayed (4 of 140 text runs, 6 of
  tool args runs). The writer now holds a tail per string path and
  never for obfuscation or kept keys.
- Kept keys (name, type, data, status...) were never restored in a
  stream, so a Gemini functionCall args object {"name":"{{PERSON_…}}"}
  kept it. Every string is restored now but signatures, data: URLs and
  opaque blobs (sealedText).
- A whole body skipped restoring unless it held "{{", so a model's
  PERSON_kb32hzkg or {PERSON_kb32hzkg} stayed; heldIn looks for any held
  placeholder's hash.
- makeRoom let a random half of 200k values go though its comment said
  the oldest; now the least recently used half (touch on every mask and
  hit), so a value just masked is never the one let go.
- A binary reply (audio/, image/, video/, octet-stream, pdf, zip) goes
  through as it comes instead of being held.

Not fixed by design: values are in memory only (README's privacy
promise, TestNoValueOnDisk), so a placeholder from before a restart that
only the vendor still holds can't be restored. Masking switched off
later also restores nothing.

Tests (all red on d159314e3's code, green now, run on mote):
TestReporterTableRestoredOnEveryStream (responses-text 4, responses-tool
6 fails before), TestPlaceholdersRestoredWhereverTheySit,
TestFullValuesKeepTheNewest (499 of 1000 newest lost before),
TestBinaryReplyIsNotHeld, TestReplyToAnUnmaskedTurnIsRestored (gateway,
real stack: first turn masks an email, second masks nothing and the
fake vendor answers with the first turn's placeholder).

Run: gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... on mote: clean. The full go test -tags nogui
-timeout 45m ./... on mote, one step before this head, found a nil
masker in redactedPromptHits with masking off (image drawing:
TestAntigravityDrawingOutOfQuotaInsideTheReplyGoesOn, internal/cli's
image MCP); fixed here (m == nil returns as before). At this head
internal/redact and internal/gateway pass on Linux (wsl-run, 594s).
That run's other reds are outside this change: internal/gui
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll) and
TestColdTurnsTaken, internal/proc TestNoCommandBypassesProc
(internal/claudetui/child_unix.go uses os/exec). The full suite runs
again at the pushed head after the tag.
Not tried: a real Codex compaction round trip with a real account, and
the reporter's agent (unknown).
2026-10-31 11:23:53 +08:00
yetone 7632e1be1d redact: a text sent on a route goes on it as it went, the model's late finds too (vvrfxyz on X)
vvrfxyz on X: "脱敏功能是不是会降低缓存命中率 我开了脱敏后 dsh命中率暴跌".

Cause: the local model (AstrLink Guard, on by default) is waited for
2s a request (masking's defaultWait). A tool's output it hasn't read
by then goes with the rules' masking alone (pii.Partial). On the next
turn the model has read it, finds the names in it, and the same history
text now goes with {{PERSON_…}} in it. Everything from that message on
is a new prompt to the vendor, so its prefix cache misses. 50f52b540
(10-23) kept the known values of a text sent before as they went, but
not the model's finds.

Reproduced with real dsh 0.2.1-rc.2 (headless profile, sandbox HOME):
three turns in one session (read team.md, customers.csv and
notes/standup.md; check contracts.md; summarise the customers) through
a sandbox magpie with masking and the default model on, to a recording
Chat Completions upstream. dsh's own request bodies were recorded and
replayed in order, 3s apart, through a fresh sandbox magpie (found
cache cleared) on Linux (WSL2 magpie-desktop, -tags nogui).
- Old (origin/main without this change): "the local model read 5 of a request's
  7 texts in 2s". At request 7, message 6 (customers.csv's tool output)
  changed at byte 252: "1000,Fatima Rossi,Client 0 GmbH" became
  "1000,{{PERSON_2rmvxto6}},Client 0 GmbH". 4,793 of that request's
  18,380 history bytes were sent as before (26%). Over the whole
  conversation 97,815 of 111,402 resent bytes (87.8%) were the same.
  It happened on both runs.
- New: 108,378 of 108,378 (100%), the same Partial in the log.
- On mote (M5 Pro, CoreML) the model read everything inside 2s. Old
  code kept 100% of the prefix over the same 3 turns, and after a
  restart of magpie too (suspect 3, the key and the in-memory maps,
  was not the cause). Suspects 1 (known values) and 4 (re-encoding)
  were not the cause either: every other request kept its prefix byte
  for byte.

Fix:
- redact: sentKnownSpans becomes sentSpans. It remembers, per text and
  options, both the known values and the model's finds the text first
  went with (sentModel, sentKnown). The key now includes Options.Route,
  and for the model also the threshold, whether there is a model, and
  NamesByModel.
- learnLate: what the model finds in such a text since is made known
  (placeholder, scores) without being put in the text, so new text has
  it masked as before.
- The gateway gives masking each request's route (maskedFor,
  masking.WithRoute): the providers its model, the model's fallbacks or
  a group's members are served by, the same set unredactedRoute walks.
  Codex's own sign-in passes "codex", or the account's provider.
- A request with no route (search, embeddings, a text prompt) keeps
  the model's finds of now, and its known values as before.

Trade-off: a name the model reads late in a text sent before keeps
going as written on that route. That route's vendor was sent it as
written already. Within a route of several providers (fallbacks, a
group), a member that wasn't the first to get it may be sent it in
that form, as it could have been on the first turn's failover. In the
Linux replay, customers.csv's ~110 names stay as written on later
turns, where old code masked them from turn 2 on. The new turns'
masking is unchanged (the same placeholder counts in messages 9, 12
and 14). Another route, never sent the text, gets it masked with what
is known and found now. That is stricter than before for known values,
which were kept whatever the vendor. The alternative, waiting for the
model before any text goes, is what defaultWait was cut to 2s to stop
(shensmart, 10-28).

Tests:
- TestModelReadingLateKeepsTheSentPrefix (internal/masking): a model
  that reads a text only after its first request. Turn 2's history must
  be byte-identical, the name masked in new text, and masked on another
  route and with no route.
- TestMaskedPrefixKeptOnlyOnItsRoute (internal/gateway): a system
  prompt kept as written on its provider, masked on another.
- Broken by hand on mote, each red:
  - sentModel not remembered: "turn 2 rewrote message 2";
  - learnLate removed: "the new turn has the name the model found as
    written";
  - maskedFor returning ctx without a route: "another provider, never
    sent it, got the value as written".
  Each was green restored. TestMaskedConversationKeepsItsCachedPrefix
  and TestSentTextKeepsItsMasking stay green.

What was run, at this commit on origin/main 4b4c4a806, on mote
(after rebasing on e863f520c, which touches internal/gateway: gofmt, vet
of gateway/masking/redact, redact and masking whole, and gateway -run
"Mask|Redact|Sent|Effort|Route" ok again):
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean.
- Targeted at this head: go test ./internal/redact ./internal/masking
  ./internal/gateway (ok), with the two new tests and
  TestMaskedConversationKeepsItsCachedPrefix, TestSentTextKeepsItsMasking.
- Full suite (go test -timeout 45m ./...) was still running on mote at
  push (load ~110, other sessions), pushed per the ship-at-once rule; its
  result goes on the release and any red gets its own issue.
- GUI suite not run: no GUI file, API or string changed.

Not tried: vvrfxyz's own machine and vendor (DeepSeek's real cache_hit
counts), and Windows.
2026-10-30 10:26:50 +08:00
yetone 5a85a9836c redact: a value at the end of a tool call's arguments keeps its closing quote (xiaojiang091499 on X)
xiaojiang091499 on X (v0.1.1808): "隐私脱敏误把 Codex 工具参数结尾的引号和
花括号一起替换了,破坏了参数格式,导致会话一直报错重连". Still the case on
main before this commit.

Cause, outbound: a tool call's arguments are masked as JSON text
(MaskJSON, escaped). A span is kept out of escapes (#3022) but not inside
its JSON string, so a span that runs past the string's end took the
closing quote with it. The local model does this: Privacy Filter's
tokenizer merges a punctuation run, so in {"cmd":"export
DB_PASSWORD=Hunt3r!"} the real model's SECRET span is `Hunt3r!"`, and a
secret's edges are kept by design (#3591). Same with "the api key is
AbC…!?\"", "ship to 221B Baker Street, London.\"", "pwd=Qq123456@#\"".
A user rule like `tok-\S+` does the same. The vendor got
{"cmd":"export DB_PASSWORD={{SECRET_…}}}: arguments no longer JSON, so
Codex's turn failed and reconnected. The model is on by default since
v0.1.1858, so this hits every user from then.

Fix: inStrings (redact.go) moves each span in escaped text onto the JSON
string it starts in and ends it where that string ends. A span that is a
whole bare value (a number a rule finds, "acct": 12345678901) is kept and
its placeholder goes in quoted (span.bare); any other span outside a
string is dropped. Text that isn't valid JSON is left as before. This is the
path for Responses function_call and Chat tool_calls arguments (JSON
text); Anthropic tool_use input and Gemini functionCall args are
objects, masked string by string, so a span there never leaves its
string.

Sibling, inbound: Writer.event and restoreJSON read an event's "type" as
the walk reached it, so a Responses function_call_arguments.delta whose
"delta" key comes before "type" (as a Go map or any key-sorting proxy
writes it) had its value put back unescaped: a password with a quote in
it ended the arguments' string. typeOf now reads the type first, and the
Writer falls back to the SSE event name. Chat tool_calls and Anthropic
input_json_delta were already right (key "arguments"/"partial_json").

Tests (internal/redact/argstail_test.go):
- TestArgumentsValueAtEndKeepsQuote: the real model's four spans
  (captured from Privacy Filter on mote) and a \S+ rule, in Responses and
  Chat bodies; arguments stay JSON, the value is gone, Restore gives the
  original back.
- TestArgumentsBareValueQuoted: a bare number is masked as a string.
- TestWriterStreamArgumentsValueAtEnd: a value with a quote and a
  backslash, at the end of the arguments, split at every byte after its
  placeholder starts, through Responses deltas (delta before type),
  Chat tool_calls and Anthropic input_json_delta.
- TestRestoreJSONDeltaBeforeType: the whole-body path.

Broken by hand: without inStrings, the first two fail; with the type
read in the walk again in writer.go, the stream test fails at cuts 28-43
({"cmd":"export DB_PASSWORD=Hunt3r!"\x"}); the same in json.go fails
TestRestoreJSONDeltaBeforeType.

Real model: a probe (not committed) ran Privacy Filter on mote over 36
argument texts through MaskJSON as the gateway does; before, the
arguments were broken for each case above; after, all 36 are valid JSON
with the value masked.

Run on mote (mote-run): go test ./... -timeout 45m -count=1 at this
change on 655f8dbd1: every package ok except two reds already filed and
outside redact: internal/gui TestMainWindowCorners/macOS_26_SDK (#3949)
and internal/provider TestClaudeAccountServesModelsListedSinceItsFetch
(#3174). Rebased on 362774210/e5e2aa58e (gateway and routes only), then
internal/redact, internal/pii and internal/masking again at the pushed
head: ok. go vet ./..., GOOS=linux go vet -tags
nogui ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build
-tags nogui, GOOS=windows go build: ok. gofmt -l: nothing.

Not tried: a real Codex session through the gateway with a masked
password; Gemini's functionCall with the real model (its args are an
object, masked string by string, never as JSON text). No docs/subsystems
page describes where spans are placed, so none changed.
2026-10-29 01:17:04 +08:00
yetone a5315c70d5 redact: the local model doesn't read an agent's tool definitions (niuniu_8964 on X)
码妞 on X: the official container on a 4-core, 8 GB server, AstrLink Guard
on, Claude Code's requests sat at 脱敏中 for minutes and timed out, load
1.78, a short conversation. aca0f0d8a made Guard read a text's windows
at once; this takes away most of what it reads.

MaskJSON asked the model about every text it masks, the tools'
descriptions and their schemas' too. On Claude Code 2.1.296's own request
(internal/gateway/testdata/workdir) that was 67,532 bytes, 52,577 of them
definitions: the agent's or a tool server's text, the same in every
request. The per-text cache only helps after the first request has been
read whole, so a fresh install (or new tools, or a Claude Code update)
paid for all of it at once, past the gateway's 2 minutes on a slow CPU.

Now what is under the request's definitions (defKeys, defItems) is never
sent to the model; it is masked as with the model off, by the rules
alone (emails, phones, keys, the user's words still are). It is masked
after the rest of the request, so a value the model found in a message
is masked in a definition too, as known. The system prompt and messages
are read as before.

Measured on magpie-desktop (WSL, Ryzen AI Max+ 395, taskset to the CPUs
named), real Guard model (rev 7216b6a3, sha256s checked), that request
through redact.MaskJSON with guardBackend, cold cache:
  4 CPUs: 129 texts, 67,532 bytes, 11.5s before; 7 texts, 14,955 bytes, 2.6s now
  2 CPUs: 20.9s before, 4.9s now
  rules alone 13-15ms; the same body warm 13ms, the next turn 36-44ms,
  before and after.
On three real Claude Code requests (claude-code-2.1.296.json,
context/claude-code.json, dsh-gateway messages-turn.json), masked with
the model at 0.8 and with the rules alone, every top-level key came out
the same: the model masked nothing in their definitions that the rules
didn't.

No time cap was added. The reporter turned the model on (the default-on
model is from today, ae0327945), so a request there is held for the
model and never falls back to the rules; a cap would only turn the wait
into an error. Less to read is the fix.

Tests:
- TestModelNotAskedAboutDefinitions (new): on Claude Code 2.1.296's and
  Codex 0.162.1's own requests no definition's text is asked about, and
  every long text said is.
- TestDefinitionMaskedAsWithoutModel (new): a tool's description and a
  schema property's come out as with no model; the email, the key and
  the phone in them are masked.
- TestModelAskedOnceForRequest: now asks about the message only, and the
  description's name is still masked (as known).

Run:
- mote-run: go vet ./internal/redact ./internal/masking, GOOS=linux and
  GOOS=windows go vet of them: ok. go test ./internal/redact/...
  ./internal/masking/... ./internal/pii/... ./internal/gwmw/...: ok.
  go test -run "Mask|Redact|Privacy|Unmasked|Masked|Placeholder"
  ./internal/gateway ./internal/middleware ./internal/gui: ok.
- wsl-run: go test ./internal/redact ./internal/masking: ok; the stage
  timings above (a scratch test, not committed).
- gofmt -l: clean.
- The vet and the test lines above ran again after rebasing onto
  d6df72a2b (its own redact change), and redact, masking and the
  gateway masking tests again on 25fc92d59: ok.

Broken by hand:
- Definitions sent to the model again: TestModelNotAskedAboutDefinitions
  red ("the model was asked about a definition's "Launch a new agent…""),
  and TestModelAskedOnceForRequest red.
- Definitions masked in the first pass, before the messages:
  TestModelAskedOnceForRequest red ("description":"find Rina Kowalczyk"
  went as written).

Not tried: the reporter's server, the Docker image itself, or a real
Claude Code session through it; a Chinese full name only in a tool's
description is no longer masked (the model was what found one; the rules
mask Chinese names only beside the model). The full go test ./... wasn't
run: mote had another session's full suite on it at load ~216, and only
internal/redact changed.
2026-10-28 17:36:40 +08:00
yetone bea9f905d0 redact: a key can go as a made-up key of its own form, not a placeholder (Charles Cao on X)
Charles Cao on X (2114238140835844575) asked for a format-preserving
swap: sk_w3axCByTQgK1PxqPhfKTrJOLBqz6sbZv sent as another sk_ key of the
same shape and put back on the way home. With Mask secrets on, a key went
as {{API_KEY_xxxxxxxx}}, which a tool's check of the key's form fails
and a model may remark on.

Settings › Privacy has "Keep a key's form" under Mask secrets (shown only
while secrets are masked; off by default, so nothing changes for anyone
who doesn't turn it on). settings.RedactShape → redact.Options.Shape;
api.go keeps it when a page from before doesn't send it.

How (internal/redact/shape.go):
- Only a secret's kind, 16+ characters, all of [A-Za-z0-9-_.]. Personal
  data, the user's words and anything else still go as placeholders. A
  made-up key needs no JSON escaping.
- Prefix kept (sk-proj-, sk-ant-api03-, github_pat_, AKIA/ASIA, or up to
  4 letters plus - or _), same length, separators in place, and each
  other character a random one of the same class. A hex key stays hex
  of its case. Random from HMAC(placeholder key, kind+value), so it is
  the same every turn and a vendor's prompt cache still matches.
- Kept in values like a placeholder (makeRoom shared with placeholder),
  so masking records, Value(), signed-thinking re-masking (the put
  closure) and known-value re-masking work unchanged; kindOf reads it.
- restore() puts made-up keys back first, then placeholders.
  RestoreJSON no longer returns early when one is in the body;
  hasShapes copies nothing while none was made.
- A stream holds an event's end that may start a made-up key
  (partialTail → shapeTail), but never one inside a key that has come
  whole: a key ending in "s" is also the start of every sk_ key, and
  without that its end was held and the key went out unrestored (found
  as 1 in ~40 fresh processes; 0 of 150 after).
- apply() leaves a made-up key that came back unrestored alone
  (outsideShapes), as it does a placeholder.

Tests: shape_test.go — form kept (the reporter's key, hex, ghp_,
sk-proj-), same fake twice, Restore; off is placeholders; email/short/
odd values not shaped; MaskJSON then RestoreJSON with escaped tool
args; signed thinking re-masked to the same fake; no re-mask of a fake;
a stream split mid-key, after one character, and a key ending as one
starts. GUI: redact-shape.test.cjs (both engines, 5 languages, 1100 and
640px; row under Mask secrets, Off by default, one save with the rest
kept, no scroll, a later save keeps it; no row while secrets are off).
redact-words-any-case now finds Mask personal data by place after the
new row, not by index.

Broken by hand, each red: no restoreShapes (KeepsForm, JSON, Stream),
no shapeTail (Stream), no outsideShapes (JSON), no hasShapes (JSON),
put ignoring Shape (all three), shapeTail without the whole-key bound
(Stream).

Budgets: app.js 1,321,994 → 1,322,289 and the core 1,529,542 →
1,529,837, the row's 295 bytes, Settings' own row, no room added.

Doc: docs/subsystems/gateway-routing.md, a bullet beside the other
masking options.

Run at 4dfd88206 + this change (worktree key-shape):
- GUI (node --test, playwright 1.62.0, both engines): redact-shape
  22/22, redact-words-any-case 20/20, i18n-keys 4/4, privacy-model
  24/24, redact-kinds 22/22, mask-actions 20/20, masking-records
  52/52, provider-proxy 8/8, click-scroll 22/22.
- go test -tags nogui ./internal/gui ./internal/redact
  ./internal/settings: ok (internal/masking has no tests).
- TestShapeStream in 150 fresh processes: 0 red.
- Rebased on 04439c859: budget tests, internal/redact,
  internal/settings ok; gofmt clean; vet -tags nogui on darwin, linux
  and windows ok; i18n-keys 4/4.
- Earlier, at load ~40: account-discovery 22 red, red the same on
  origin/main defbb1a15, #3497 (ggbdpq has it); redact-rule-edit
  webkit zh-TW 420px red once, 3/3 alone, #3407.
- The full suite was not run before this push: it is queued behind
  other sessions' suites (one per machine).
Not tried: a real vendor turn with the setting on.
2026-10-25 15:35:52 +08:00
yetone 2dfaf75539 redact: a masked body is held at its size, not in a buffer grown by doubling (#3383)
With masking on, the masked body is what a request holds while it
streams (MaskJSON, 285 MB live in the report's heap). walk built it in a
bytes.Buffer grown by doubling, up to twice the body. It now makes room
for the body and a sixteenth at the first value it masks, and copies the
result to its size when placeholders grew it past an eighth spare.

Run:
- the heap probe, 8 requests of 9.7 MB held mid-stream with Privacy
  masking on: 138 MB before, 86 MB after (Anthropic to Anthropic);
  translated to Chat 235 MB before, 183 MB after.
- TestMaskedBodyHeldAtItsSize: green; red with both changes off
  ("the masked body of 4356589 bytes is held in 7077888").
- go test ./internal/redact/ ./internal/masking/ ok; gateway -run
  'Mask|Redact|…' ok (see the commit before).
2026-10-24 21:00:05 +08:00
yetone 9b57261b62 masking: a record keeps its request as sent, how long masking took and what the answer put back
For the 观测 › 脱敏 page's request view. In memory only: the masked body
of the latest 100 requests (each up to 4MB, 64MB in all), and by
placeholder how many places of the answer had the value put back
(redact.Writer.Put, counted once per place even when a stream splits
the placeholder). Took (µs) is written to disk too; it holds nothing of
the request.

GET /api/masking/sent?key= gives the body, POST /api/masking/values the
values the masker still remembers, both no-store.

Run: go test ./internal/maskrec ./internal/redact ./internal/gui
-run TestMaskingRecordsAPI and ./internal/gateway -run TestMasked; ok.
Broken by hand: without toldBack, TestMaskedRecordKeepsSentAndBack is red.
2026-10-24 19:41:02 +08:00
yetone 50f52b540b redact: a text masked for a vendor before is masked as it was then, so a cached prompt stays cached
With Privacy masking on, a value masked once is "known" and masked
wherever a later request has it (redact/known.go). When a rule first
finds a value in a later turn (a tool printing DB_PASSWORD=...), that
value was masked from then on in the system prompt and the turns already
sent with it as written. The prefix the vendor had cached changed, so
the whole prompt was written to the cache again and none of it was read.

Reported by audie on Discord: DeepSeek Harness on a routing group served
by a custom Anthropic-compatible provider. Adjacent turns 10s apart had
cache_read 0 and cache_write 412K to 427K.

Fix: Mask and MaskJSON (the vendor-bound paths, via masking.Masker) now
use sentKnownSpans. A text masked before gets the known values it had
the first time, keyed by a sha256 of the text and the options. Only
hashes and spans are kept, never a value, in two generations of 65536.
New text still gets every known value masked. Scrub (archives, sessions,
OTel; local only) keeps the latest known set.

Unchanged: if magpie restarts, or a text falls out of both generations,
the text is masked under the current known set once, as before.

What was run:
- internal/redact TestSentTextKeepsItsMasking and internal/gateway
  TestMaskedConversationKeepsItsCachedPrefix. The gateway test sends a
  dsh-shaped Chat Completions conversation to a group with an Anthropic
  member, and a Claude Code-shaped /v1/messages one. It checks that each
  turn's system, tools and earlier messages reach the fake upstream byte
  for byte. Both tests are red with sentKnownSpans forced back to
  knownSpans: the system prompt became "{{SECRET_...}}" on turn 3. Both
  are green with the fix.
- With masking off, a probe of the same dsh shape had the system, tools
  and earlier turns byte-identical on every turn.
- gofmt -l: clean. go vet: darwin, GOOS=linux -tags nogui ./...,
  GOOS=windows ./...: clean.
- Full suite at 8187919d7 (this tree, on origin/main bf2e067ef):
  set -o pipefail; go test -tags nogui -timeout 45m ./..., through the
  suite lock. 69 packages ok, none red (gateway 519s, agent 393s).

Not tried: audie's real setup. Their Privacy setting isn't known; with
masking off this is not the cause, and every breakpoint reading 0
(even the unchanged system block) points at the provider's own cache or
pool. Not tried against a real Anthropic or relay account. GUI not
touched, so the GUI suite was not run. Windows tests not run.
2026-10-23 20:53:53 +08:00
yetoneandggbdpq 243594410d redact: a tool call's arguments stay JSON when a value follows an escape (#3022)
A history tool call's function.arguments is JSON text inside a string.
MaskJSON masked it as plain text, so the n of a \n started a match:
"\n@mcp.tool()" became "\{{EMAIL_…}}()", the arguments were no longer
JSON, and Ollama Cloud refused every turn that replayed the call with
400 "invalid tool call arguments". Reported by xiaobaifly7 and reproduced
independently by Shane-Meng (\n\n\n@pytest.mark…).

Where a string holds JSON text (asJSON), mask now reads it the way the
vendor reads it once it is unescaped:
- unescapedView: a same-length view in which \n, \r, \t, \b and \f read
  as control characters and a \u escape reads as line breaks, so no word
  starts or ends on an escape's letter. \" \\ \/ stay as written, so the
  SECRET rule's \"-aware quote and Windows paths read as before.
- outsideEscapes: any span (rule, word, model, known) that starts or
  ends inside an escape is cut back to the escape's edges, so the JSON
  holds and what the span held is still masked. A span left empty is
  dropped.
- unescapedPut: the value kept for Restore is the unescaped one, so
  Restore (which escapes it again in arguments) gives the agent exactly
  what it wrote. Before this, a private key's \n came back as \\n.

Ported from ggbdpq's hunt53-f-redact-json-escape. Their test
TestMaskJSONKeepsArgumentsJSON is kept verbatim. Their guard alone let
"\njo@quill.dev" through unmasked, so this port also adds the view, the
trimming and the restore.

Run at base 673651e8d (origin/main) plus this change:
- gofmt -l: clean
- go vet ./... (darwin), GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok
- go test -tags nogui -race -count=3 ./internal/redact: ok
- go test -tags nogui -count=1 -timeout 45m ./internal/redact/...
  ./internal/gateway/...: ok (redact 3.7s, gateway 423s; internal/masking has no tests)
- Full suite NOT run: another session's `go test -timeout 45m ./...`
  was already running on this machine (one suite per machine).

Broken by hand (each run against the new tests in escape_test.go):
- old code (origin/main's redact.go, json.go and scrub.go, with a no-op
  outsideEscapes shim): all 4 tests red. TestMaskJSONKeepsArgumentsJSON
  "2 masked, want 1"; Escapes "invalid character '{' in string escape
  code" with \{{EMAIL_…}}; Restore gets \\n back; CutShort red.
- unescapedView off: KeepsArgumentsJSON, Escapes and CutShort red.
- unescapedPut off: TestRestoreArgumentsFromArguments red.
- outsideEscapes call off: CutShort red (a user rule
  `REL-[a-z\\]+` ending on the backslash of \" breaks the JSON).
- trimming replaced by dropping: CutShort's unit check red.

Fixtures come from the reporters' bytes: xiaobaifly7's \n@mcp.tool() and
Shane-Meng's \n\n\n@pytest.mark…. They also cover an address after \n,
\t, \" or \r\n, after a Windows path, and after é/—; an npm key
after \n; a key-context password; and cut-short arguments. Each checks
that the arguments still parse, the values are gone and the decorators
are unchanged.

Not tried / not covered:
- No real Ollama Cloud round trip, and nothing end to end on Windows.
- A user rule that reads past the string's closing quote (e.g. \S+ over
  JSON text) can still break arguments. That was true before this change
  and is not an escape case.
- Allow-list matching and a Hit's hint use the escaped text as written.
  A value remembered earlier with real newlines is not found by
  knownSpans in arguments unless a rule finds it again.
- A personal value written as a JSON number in arguments is not masked
  (masking it would break the JSON).

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-23 18:01:26 +08:00
yetone b00c82acfa masking: each kind is masked, sent with a warning or held back; a Never mask list and Try it (#1977)
Settings › Privacy gets two sections under What to mask:

- When a value is found: Mask, Warn or Block per kind (redactActions;
  a kind left out is masked). Warn sends the value as written and records
  it with a placeholder nobody remembers, not counted as masked. Block
  masks it as before and the gateway answers 400 naming the kind and the
  value's hint, never the value, with nothing sent (maskBlocked); the
  record is kept as Blocked. The secret kinds come first, the personal
  ones behind Show all kinds. A Never mask list (redactAllow) lets a whole
  value go as written in any case; a longer value it is part of is masked.
- Try it: POST /api/masking/preview masks a text as a request would
  (redact.Preview) and remembers nothing: no placeholder stands for it
  afterwards and its values aren't masked later as seen before. The page
  shows the vendor's text, what was found and what would be done, and
  keeps the text in no storage.

The masking card counts requests held back and values sent as written; a
call whose values only went as written gets an amber badge on Recent calls
and the Routing log. zh, zh-TW, ja and de throughout. Docs: gateway-routing
and gui-shell.

Broken by hand: the new GUI badge assertion fails on the old maskedBadge
(no .warn badge drawn); TestSettingsSaveKeepsWhatItDoesNotSend went red
until the two settings were in its fixture; "{n} held back" turned
i18n-keys red against the routing plugin's "{n} held" and was renamed.

Run at this tree (base origin/main 9b0f48612):
- gofmt clean; go vet on macOS, GOOS=linux -tags nogui, GOOS=windows.
- go test -count=1 -timeout 45m redact, maskrec, settings, gwmw, gui,
  gateway: ok.
- GUI, both engines: every Privacy file, mask-actions, masking-records,
  routing-bodies, i18n-keys, old-webkit: 263/263.
- Whole GUI suite earlier at 083b1c8e7's base, beside 7 other runs:
  53 red; alone, the ones left red fail the same on origin/main
  6fc532198 and are filed (#3179, #2228, #2448, #2276, #2549, #2163,
  #2399), except privacy-usage-stats and account-discovery, which this
  change's taller page moved off screen; both fixed here.

Not tried: a real vendor request held back by Block from a real agent.
2026-10-22 04:07:55 +08:00
yetone d3db461bbb redact: the local model's secrets leave UUIDs, digests and paths, and client_metadata goes as written
The owner's masking records showed Codex's turn metadata with every id as
{{SECRET_…}}: installation_id, session_id, turn_id, window_id,
context_window_id, root_turn_id, and a skill's file path in the
instructions. The local model (OpenAI's Privacy Filter) labels a UUID a
secret: run on Codex's x-codex-turn-metadata it took each id, and on a
log it took a request id and "sha256 9b74…". The vendor and magpie's own
sessions match a turn by those ids, so masking them can break what
depends on them, and hides nothing worth hiding.

- modelTakes: a secret the model finds is not taken when it names a
  thing (namesThing): a UUID, with window_id's ":0" after it too; a
  digest with its algorithm's name; a file's path. A password or a key
  it finds is still masked, and the rules' secrets (sk-…, password=…,
  API_KEY: …) are unchanged.
- client_metadata is in defKeys: the client's ids, which no model
  reads, go as written, as tools and stream_options do.

docs/subsystems/gateway-routing.md says both.

TestModelSecretIsNoID uses what the real model labelled "secret" on these
texts (pf-serve with the q8 model, run here): the UUIDs, the request id,
the sha256 digest, plus the reporter's path; the password and the
32-hex key beside them are still masked. Broken by hand: without
namesThing 5 values are masked, without client_metadata in defKeys a
user word in it is.

Run:
- At 3fff6c011 (on origin/main e65688886): gofmt -l clean; go vet clean
  on macOS, GOOS=linux -tags nogui and GOOS=windows; go test ./...
  -timeout 100m: 66 packages ok, and internal/agent and internal/library
  printed PASS but were marked FAIL when the disk briefly filled ("can't
  write testlog.txt: no space left on device"); run again alone, both ok
  (993s, 596s).
- Rebased on origin/main 141470515 (its 12 commits touch agent, cli,
  gateway, gui, provider, sessions, settings, tui, not redact): at this
  head gofmt and vet three ways clean, go test ./internal/redact
  ./internal/gwmw ./plugins/redact ok. The rest runs on CI before the
  tag.
2026-10-21 19:13:49 +08:00
yetone 88119d4f67 redact: Codex's tool server names, stream_options and snake_case words go as written (#3143, #3144)
Two reports from hibaliqya-yonma (v0.1.1306, Codex Desktop through
/backend-api/codex), each a 400 on every request until masking was
turned down:

- #3143: a user's word that is part of an MCP server's name went into a
  Responses function_call's namespace as mcp__{{TERM_…}}. Codex checks a
  namespace against ^[a-zA-Z0-9_-]+$, and the call is replayed every
  turn. namespace is kept as name is, and so are the server's name in
  its siblings: a Responses mcp_call's server_label, Anthropic's
  mcp_tool_use server_name.
- #3144: the local model took stream_options.reasoning_summary_delivery,
  "sequential_cutoff", for a name. stream_options is a request setting
  now (defKeys, with reasoning and text), and the model's name is never
  a snake_case word (snakeWord), wherever it is, so an enum or an
  identifier in a tool's arguments or in code is not taken either.

The same word in the user's own message is still masked, and a name
beside it still is. docs/subsystems/gateway-routing.md says both.

Tests from the reporter's bodies: TestMaskJSONKeepsReasoningSummaryDelivery,
TestMaskJSONKeepsToolServerNames (namespace, server_label, server_name),
TestModelTakesNoSnakeWord. Broken by hand: with json.go and model.go as
on main, all three fail; with the change they pass.

Run at this head (origin/main ba319a758):
- gofmt -l clean; go vet clean on macOS, GOOS=linux -tags nogui and
  GOOS=windows.
- go test ./... -timeout 100m: 68 packages ok, exit 0.
- With #3029's commit stacked on it: go test ./internal/redact
  ./internal/gateway ok (gateway 2742s at load ~25), vet the three ways
  clean.
2026-10-21 17:20:37 +08:00
yetone f21dd99f5a privacy: every masking is recorded, and Settings › Privacy shows it
What was masked is now kept, so the user can see it. Settings › Privacy
opens on a summary card: how many values were kept from vendors over 1,
7 or 30 days, by kind, by finder (rules, your words, the local model,
known values) and by where they went, with a day strip. The page is
grouped into What to mask, How it's found (rules and the local model are
layers, not a toggle: the model adds names and addresses rules can't
see) and Sharing. A records view lists each masked request: its kinds,
finders, placeholders and, while magpie runs, the line around each
value. Gateway › Recent calls and the Routing log carry a masked-N badge
that opens the record.

Originals never go to disk. internal/maskrec writes day files under
~/.config/magpie/masking (0600, 30 days, 100MB at most) holding kinds,
finders, placeholders, a first character or key prefix and a length.
The lines around values are kept in memory for the last 400 records
only, and /api/masking/value answers only while the masker remembers a
placeholder. Nothing is written under MAGPIE_TEST_SANDBOX.

A masker says what it masked through gwmw.Teller (JSONHits, TextHits,
Value); a plugin masker that doesn't is counted only, so older redact
plugins keep working. Every route that masks notes it: chat, Responses,
Codex backend and search, embeddings, images, video, transcription,
decide and the search MCP query. Masking still fails closed: a masker
that panics on any path refuses the request (TestMaskingOnAndOff's fake
now panics on JSONHits and TextHits too, since the gateway asks a Teller
through those).

app.js grows to 1,314,432 bytes, so its budget rises to 1,335,000 and
the core's to 1,528,800 (+1.5%): Settings is the core's own page.

Run at this head (rebased on origin/main a3ebed202):
- go vet clean on macOS, GOOS=linux -tags nogui and GOOS=windows;
  go test ./internal/gateway ok (561s).
- On origin/main c922225f1 (one commit back, the packages either side
  touches): agent, gateway, gui, gwmw, maskrec, provider, redact ok.
- On origin/main 592899467: go test ./... -timeout 45m, 65 packages ok;
  agent and gateway hit the 45m timeout under load ~26 (each mid-way
  through a short test, not a hang) and pass alone with -timeout 100m
  (1133s, 890s).
- GUI, on 592899467, the 42 files this change or main's new commits reach (privacy-*,
  redact-*, masking-records, settings-*, gateway-*, routing-bodies,
  routing-request-metrics, routing-log-icons, account-discovery,
  click-scroll, i18n-keys, old-webkit), both engines, every language:
  475 tests, 475 pass. routing-bodies is green here since 2543fb2c1.

Run on the previous base, origin/main c84864ffc (the whole suites):
- go test ./... -timeout 45m: every package ok (66), exit 0. An earlier
  run found TestMaskingOnAndOff/panics (its fake, above) and
  TestCoreScriptBudget (the budget, above); both fixed.
- gofmt -l clean; go vet on macOS, GOOS=linux -tags nogui and
  GOOS=windows clean; node --check on the changed scripts.
- GUI suite, both engines, every language, --test-concurrency=6:
  11533 tests, 11483 pass, 50 fail. Each failing file rerun alone here
  and on origin/main:
  - red the same on main, filed: codex-predictions (#2624),
    usage-checkin (#2549), usage-agents-hide (#2276), usage-fold
    (#2163), s3-sync (#2448), quota-count-wrap and
    quota-name-translated (#2228), routing-request-metrics (#2571),
    routing-bodies (#2559: red at its "second request pressed" step;
    this change's badge checks before and after it pass),
    routing-rule-remove (#3096, filed now: 0 2 1 alone here, 0 0 2 on
    c84864ffc).
  - load, pass alone: group-member-weight (#2387), routing-model-rest,
    context-tune (Chromium didn't launch in 180s at load average ~45;
    0 0 0 alone on both). An earlier whole run's library-chip-fan red is
    #3072 (filed), plugin-card-update #3079, lightweight #2638,
    segs-glide #2683.
  - mine, fixed: old-webkit, three ":hover, :focus-visible" lists
    Safari before 15.4 drops; split, 6/6.
- Broken by hand, each went red: masked values kept on disk
  (TestNoValueOnDisk), a snip that runs past an escaped quote
  (TestSnipStaysInItsString), the shared-line dedup in the records view
  (masking-records, 10 of 12).
- Real app in a sandbox HOME with the local model on: the summary card,
  flow, chips and records view in light and dark; persons and
  addresses, Chinese names among them, recorded by=model; a grep of the
  masking folder and the sandbox config for the masked values found
  none.
2026-10-21 06:12:37 +08:00
yetone c0dad80da1 redact, pii: a local model finds what the masking rules can't (#1977)
WIP on pf/serve, recovered after the scratchpad holding it was wiped.
internal/pii downloads OpenAI's Privacy Filter (q8 GGUF, sha256 pinned)
and pf-serve, runs it on the GPU first, and answers redact's Model;
settings.RedactModel turns it on, per computer. Off by default.

Run: go vet and go test -race on internal/redact, pii, source,
settings (all ok). Not yet released: pf-serve's serveSHA is empty
until pf-v1 is tagged.
2026-10-18 23:12:41 +08:00
yetone 62390fe92e redact: a masked word is never masked inside tool definitions or schemas, so Codex's apply_patch grammar reaches OpenAI intact (#1911, loveNangua)
What changed: MaskJSON masked custom words as raw substrings in every
string of the request, tool definitions included. A word "pd" turned
apply_patch's Lark rule name update_hunk into u{{TERM_..}}ate_hunk and
OpenAI refused the request with 400 "Invalid lark grammar". Definitions
are now kept by where they sit in the protocol, not by a key's name:
the request's top-level tools, tool_choice, functions, function_call,
toolConfig/tool_config, response_format, text (an object), reasoning,
include, output_format, output_config and generationConfig, and the
tools of a Responses input item of type additional_tools or
tool_search_output. Inside them only "description" strings are still
masked. A "tools" or "text" key in tool-call arguments, a message, a
Gemini part or a Responses message item is masked as before.

Run: go test ./internal/redact/ ./internal/provider/ (ok). The new
tests use Codex 0.162.1's real request (copied from the gateway's
testdata) with the top-level tools and as a Responses Lite
additional_tools item, plus Anthropic/Chat/Responses/Gemini schema
cases and negative cases. With the old json.go both tests fail
(update_hunk masked, every schema case changed). gofmt -l clean; go vet
-tags nogui on darwin, linux and windows. Not tried: a real request to
OpenAI with the word set.
2026-10-13 14:14:59 +08:00
yetone 3c7473eb3f redact: a value masked once is masked again wherever a request has it, whatever words are around it
The masking rules find a value by what is around it: DB_PASSWORD= before
a password, a bound an email may not touch (so an email that ends a
sentence isn't one). The vendor writes about a placeholder in words of
its own ("your password is {{SECRET_…}}", "I will write to {{EMAIL_…}}."),
the agent reads the value there (Restore), and on the next turn that text
is in the history, where no rule matches it, so it went out as written.

Now every value a placeholder was made for (redact's in-memory values,
bounded by maxValues, never written anywhere) is also matched as an exact
string in each string Mask and MaskJSON look at, and goes as the same
placeholder it had (same kind, same keyed hash), so history and vendor
caches stay stable:

- only from 8 characters (the assignment rule's minimum): the 3-character
  passwords the user:password@ rule takes, and the user's own words
  (which Options.Words matches everywhere already), are not;
- personal values only while personal masking is on, secrets only while
  secret masking is on;
- not as a piece of a longer value: a phone or card number with a digit
  beside it, an email inside a longer address (a full stop after it may
  end the sentence), a secret with a letter or digit against it;
- where a rule finds the same span, the rule's kind still wins, so
  nothing masked before changes placeholder;
- in what a vendor signed (7137feb4), the values masked elsewhere in the
  request go back as their placeholders as before, and so do known
  secrets, for a turn whose other copies were compacted away; known
  personal values don't, since a number the vendor wrote of its own
  (13800138000) may be one masked in another conversation, and masking
  it would break the signature.

A prefix index and a 4-byte bitset keep the lookup cheap: a ~1 MB body
masked in ~79 ms with 0, 1k or 200k known values alike (rules dominate).
Every route goes through redact.MaskJSON / Mask (chat, Responses,
Anthropic, Gemini, count_tokens, embeddings/rerank, the Codex backend,
image and video prompts), so each gets it; Scrub, the archive's, gets the
known secrets too.

Tests: TestEchoedValueMaskedNextTurn (gateway: two chat turns where the
fake vendor echoes the placeholders in other words; the second request
must not hold the password or the email, and keeps the first turn's
placeholders; then the echoed text alone through /v1/responses,
/v1/messages, count_tokens, Gemini generateContent, embeddings and the
Codex backend) fails on origin/main with the second turn sending
"…password is Mv4kestrelPass28, and I will write to
tomas.ng@quietfield.dev.". TestKnownValueMaskedInOtherWords and
TestKnownInSigned fail there too; TestShortValueNotMaskedEverywhere and
TestKnownReindexed pin the bounds and the eviction rebuild.

Run: gofmt -l (nothing); go vet -tags nogui ./... on darwin,
GOOS=linux and GOOS=windows; go build -tags nogui for darwin, linux,
windows; go test -tags nogui ./... under a temp HOME with pinned caches
(all ok); internal/redact -count=3 and -race. Not tried against a real
vendor.
2026-10-09 11:56:10 +08:00
yetone 1965e1f0f4 redact: a tool call's arguments are masked again, whatever their keys are called (7137feb4 let them out)
7137feb4 kept two kinds of strings from the masking rules, and both
reached what the agent itself wrote:

- Any object with a non-empty "signature", "thoughtSignature",
  "thought_signature" or "encrypted_content" counted as sealed by the
  vendor, so its strings went out unmasked but for the placeholders of
  values masked elsewhere. A tool_use input like a mail tool's
  {"signature":"Best, Bob","body":"DB_PASSWORD=… call 13800138000"} sent
  the password and the number in the clear; before 7137feb4 both were
  masked. A text block carrying a "signature" key did the same.
- Every key named id, …_id or …Id was kept, in a tool's arguments too:
  {"user_id":…,"phone_id":"13800138000"} went out as written.

Now only a thinking or reasoning block (Anthropic's signature, Responses'
encrypted content, reasoning.* details) or a part with Gemini's thought
signature counts as sealed, and nothing inside a tool_use input or a
functionCall's args does. In those arguments the keys are the tool's, so
no key keeps its value there (an encoded data: value still is); ids
outside them stay as 7137feb4 left them. A signed Gemini functionCall
part still goes back as written. The response side (writer.go) restores
ids again, which changes nothing for a real id and puts back a
placeholder the vendor echoed into a tool's user_id.

Ran (Docker golang:1.26.8, GOTOOLCHAIN=local): TestMaskJSONToolArgsMasked
(new: signature key and id keys in tool_use input, Gemini args, a text
block with a signature key) fails on origin/main in all four cases and
passes; 7137feb4's TestMaskJSONSignedGoesBackAsWritten,
TestMaskJSONKeepsIDs, TestSignedThinkingGoesBackAsSigned and
TestToolCallIDsGoBackAsGiven pass. gofmt -l clean; go vet -tags nogui
for linux, darwin and windows on internal/redact; go test -tags nogui
./internal/redact ./internal/gateway ./internal/usage pass. Not tried
against a real vendor.
2026-10-09 11:29:07 +08:00
yetone 7137feb4fc redact: what a vendor wrote and checks goes back as it wrote it — signed thinking and tool call ids (Jeremy.Zhou on Discord: OpenCode Zen answered 400 "invalid …" until 脱敏密钥 and 脱敏个人信息 were off)
Masking ran its rules over every string of the request except a fixed list
of keys, including two kinds of text the vendor itself wrote and checks
when it comes back:

- A thinking block (Anthropic's signature; also Gemini's thoughtSignature
  and Responses' encrypted reasoning). The vendor thinks about the
  placeholders it was given, the agent gets the values back (Restore), and
  on the next turn the rules masked that text again. Rules depend on
  what is around a value: "the password is {{SECRET_…}}" came back as
  "the password is hunter2abc1", which no rule matches without its
  DB_PASSWORD=, an email ending a sentence fails the email rule's bound,
  and a number the vendor wrote of its own ("13800138000") turned into a
  {{PHONE_…}}. The text no longer matched its signature, and Anthropic
  answers 400 "messages.1.content.0: Invalid `signature` in `thinking`
  block" — and the value itself went to the vendor in the clear.
  Now an object that carries a non-empty signature, thoughtSignature,
  thought_signature or encrypted_content is masked only by putting back
  the placeholders of the values masked elsewhere in the same request
  (longest first): what the vendor wrote, its own words untouched.
- A chat tool result's tool_call_id. "id", "tool_use_id" and "call_id"
  were kept, "tool_call_id" wasn't. GLM's ids are call_ and 19 digits,
  and ~5% of them pass Luhn as a bank card number, so the tool message's
  id became call_-{{BANK_CARD_…}} while the assistant's tool_calls id
  stayed, and the upstream refused the orphaned tool result ("messages
  with role 'tool' must be a response to a preceeding message with
  'tool_calls'"). Now every key named id, …_id, …Id (and their plurals)
  is left alone.

Account masking (账号打码) is display only and doesn't touch requests.

Tests: TestSignedThinkingGoesBackAsSigned (a fake Anthropic upstream that
signs its thinking with an HMAC and checks it, two turns through the
gateway) and TestToolCallIDsGoBackAsGiven (a fake chat upstream that
refuses a tool result with no matching call) fail on origin/main with
exactly those 400s; TestMaskJSONSignedGoesBackAsWritten (Anthropic,
Gemini thought and functionCall, Responses reasoning shapes, plus an
unsigned thinking block still masked) and TestMaskJSONKeepsIDs fail there
too. All pass with the change.

Run: gofmt -l (nothing), go vet -tags nogui ./... on darwin, GOOS=linux
and GOOS=windows, go build -tags nogui (darwin, linux, windows),
go test -tags nogui ./... under a temp HOME: all ok. Not tried against the
real OpenCode Zen, and the reporter's exact error text and model weren't
seen; both upstream checks are modeled on Anthropic's and OpenAI's
documented errors.
2026-10-09 11:09:22 +08:00
yetone 67c539d5da gateway: secrets can stay on the machine — with Settings › Privacy › Mask secrets on, API keys, private keys, tokens, JWTs and the passwords of connection strings and assignments in what an agent sends go to the vendor as placeholders like {{API_KEY_k3v9x2mq}}, and what the vendor answers has them back, streams included (a placeholder split between two events is put back whole, a tool call's arguments get the value escaped); personal data (emails, phone numbers, ID and bank card numbers, checksum-checked) and the user's own words can be masked too. A placeholder is the same for the same value every time, so a conversation's history and what the vendor cached of it stay the same turn after turn, and the request log shows what the vendor saw. Suggested on X as maskit's idea; written from scratch 2026-09-26 14:21:14 +08:00