ac4af582301a4e8a29245dbba767eba31334ddf9
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
359da679db |
redact: 试一试 shows the made-up key when "keep key form" is on, short keys and named keys too
A user turned on 保留密钥格式 (v0.1.1497) and 试一试 still showed
{{SECRET_…}} for "用密钥 sk_abcdefg 部署可以吗". Three gaps:
- Preview wrote every value with tag, which never looked at Shape: a
sibling v0.1.1497 missed. It now makes the same key shapeOf gives a
real request, without storing it.
- shapeOf made up nothing under 16 characters, so sk_abcdefg stayed a
placeholder even on a real request. Now 8 or more, with at least 6
characters made up after the prefix.
- 密钥 OPENAI_API_KEY=sk_… is found with its name (the CJK key rule
takes NAME=value as the value), and '=' isn't a key character, so it
fell back to a placeholder. The name now stays as written and only
the key after it is made up and remembered, so a reply naming the key
alone is put back too.
Run: go test ./internal/redact ./internal/settings, -tags nogui
./internal/gui, ./internal/gateway -run 'Redact|Mask|Shape|Privacy' all
ok; go vet darwin, linux and windows (nogui); gofmt clean.
Broken by hand: Preview back to tag, minShape 16, the minRandom check
removed and splitName turned off each turn TestShapeShortAndPreview,
TestShapeKeepsAName or TestMaskingPreviewKeepsKeyForm red; storing the
whole NAME=value turns TestShapeKeepsAName's Restore red.
Not tried: the GUI suite (no front-end change) and a real model's reply
naming the made-up key; the full Go suite.
|
||
|
|
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
|