Files
magpie/internal/redact
yetone 641b1217f2 redact: a URL's user:password@host is a PASSWORD and a host, not one EMAIL (#3538)
With Mask personal data on, postgres://app:hunter2pass@db.acme-corp.cn:5432/x
went as app:{{EMAIL_…}}:5432/x: the EMAIL rule took hunter2pass@db.acme-corp.cn,
which starts where the PASSWORD rule's value does and is longer, so it won
the overlap. The kind was wrong and the host the model may need was hidden.

Now an EMAIL match whose start is inside a URL's authority (after
scheme:// with no /, ?, #, space, quote or @ between) is turned away
(notUserinfo, the rule's `at`), and the local model's EMAIL the same way
(modelFits). The password is the PASSWORD rule's and the host goes as
written. An address in a URL's path or query, in mailto: and in prose is
an EMAIL still.

Sibling found on the way: the PASSWORD rule asked for a user before the
colon, so redis://:pass@host (Redis has a password and no user) was not
masked with Mask secrets alone, and was only covered by the EMAIL accident
with personal data on. The user part may now be empty; without that the
email fix would have sent a Redis password as written.

Behaviour change to note: a userinfo with no password
(https://yetone@github.com/..., ssh://git@gitlab...) was an EMAIL and now
goes as written; it is a user name in a URL, not an address. With Mask
personal data on and Mask secrets off, a URL's password now goes as
written, as Mask secrets off says (it went as an EMAIL by accident).

#3029's file names (…@2x.jpg) are untouched: realEmail is unchanged and
TestFileNameIsNoEmail/TestMoreFileNamesAreNoEmail pass. #3365 (rule SECRETs
and known values) is a different rule; this changes nothing it reports.

Test: TestURLUserinfoIsNoEmail (internal/redact/userinfo_test.go) with the
report's literal string, mysql://, amqp://, mongodb+srv://, https://user:pass@,
redis://:pass@, a user with no password, ssh://git@, and emails in prose,
mailto:, a URL path, a query, and a query after a userinfo; a request via
MaskJSON; and the local model's EMAIL.

Broken by hand:
- redact.go and model.go reverted: red, 9 table cases plus the request and
  model checks (the literal went as postgres://app:{{EMAIL_…}}:5432/x).
- model.go alone reverted: red on the model check only.
- the PASSWORD regex's user back to +: red on both Redis cases (with
  personal on it went fully unmasked).

Run at this head (rebased on origin/main d153f0259):
- go test -count=1 ./internal/redact/... ./internal/masking/... ./plugins/redact/...: ok
- go test -count=1 ./internal/gateway/ -run 'Mask|Redact|Privacy|Masked': ok
- gofmt -l internal/redact internal/masking plugins/redact: empty
- GOOS=linux, windows, darwin go vet on the three packages: ok
Not run: the full suite (no suite lock on this machine; owner: don't hold
the push for it). Not tried in the GUI's Try it preview by hand; it calls
the same redact.Preview path the tests exercise.
2026-10-25 09:57:21 +08:00
..
gateway: a request archive, off unless turned on, keeps each call's headers and bodies in the user's own S3 bucket and a recent call reads its own back (Jorben on Discord: 请求存档) — the Gateway page's recent calls only ever held the last bodies in memory, the first 256 KB of each, with no headers, gone at a restart. A switch over Recent calls ("Request archive", POST /api/settings/archive, settings' requestArchive) turns it on, refused with a reason while sync isn't set up with an s3:// bucket; with it on, each call the gateway serves gets an id (UTC HHMMSS-<16 hex>, said back in X-Magpie-Archive-Id) and, once it is recorded, its method, path and query, request headers and body and response status, headers and body go as one JSON file to <prefix>/magpie/archive/<YYYY-MM-DD>/<id>.json in the bucket sync keeps its backup in, signed with the same client (davsync.Bucket, no new SDK). Before anything leaves, Authorization, x-api-key, Cookie, Set-Cookie, any header or JSON field or query parameter named for a key, token, secret or password, and anything that looks like a key or token anywhere in the text (the redaction rules' patterns, in a stream's data lines too) become [REDACTED] — gone, no placeholder kept; the archive is plain JSON, readable in the bucket, not sealed with the passphrase. Uploads go one at a time on their own goroutine from a queue of 16 calls, each body capped at the 256 KB the call already keeps and marked truncated; a full queue drops the call with a log line, a failed upload is logged and shown under the switch until the next one goes, and no request waits on any of it. A recent call the archive kept shows its date and id under its bodies, and "Fetch from archive" (GET /api/archive?date=&id=, only a date and an id of that shape) shows the request's and response's headers and bodies as the bucket has them, or says it isn't there yet. The hook is in record() and the Call literal, so PR #239's request log lines are not touched; the archived call carries its usage, and with #239 its vendor request id. Only calls through serve() are archived, not Codex's backend, image or video calls. TestArchiveOn, TestArchiveOff, TestArchiveName, TestRequestArchiveToS3 (a real gateway request through the signature-checking fake S3), TestScrub and request-archive.test.cjs fail without the change; TestSettingsSaveKeepsWhatItDoesNotSend now sets requestArchive. A sandbox magpie web with a fake vendor and a fake S3 server uploaded nothing while off; on, it uploaded a signed archive with none of eight planted secrets in it, read it back through /api/archive and in the page, and with the S3 server down served the call in 0.1 s and said why the upload failed. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (Claude account tests and TestClaudeRunEndsWhenTheClientLeaves pass alone); request-archive, click-scroll, old-webkit, sse-body, gateway-fold pass.
2026-10-01 17:13:34 +08:00