redact: a URL's password that is also its user, host or database goes as written (xuanwo on X)

xuanwo on X, 10-29: "我的很多项目名被识别成了 password,一天脱敏了 26M
次". The screenshot: a Codex summary where geodatafusion went as a
made-up word (bsssqojjdekwi) in every path, in rust/geodatafusion/,
geodatafusion.toml and cargo test -p geodatafusion; GEODATAFUSION in
capitals was left. Settings listed it under Passwords.

Cause, reproduced with the repo's own bytes: the geodatafusion repo's
PostGIS test (testing/postgis/README.md, rust/geodatafusion/tests/
postgis/README.md, .github/workflows/postgis-differential.yml) runs on
  postgresql://geodatafusion:geodatafusion@127.0.0.1:55432/geodatafusion
The URL PASSWORD rule (user:password@) took the password. Once masked a
value is known (knownSpans) and is masked wherever it is written, case
as written, so the project's name went as a password in every request
for the rest of the run. Neither the local model nor b9f1fcddd's
words-only check is involved: this is a rule's find, which is known
whatever its look. Other projects set up the same way (name:name@)
each made their name known.

The rule: masking a URL's password hides nothing when the same URL has
it written as its user, a label of its host or a part of its path
(postgres:postgres@, root:root@, guest:guest@, app:shopdb@…/shopdb,
geo:geo@db/geo). hiddenInURL leaves such a password as written, so it
is never known. Whole parts only: geo:geod@…/geodb is masked. A
password not written elsewhere in its URL is masked as before, whatever
it looks like, there and as known everywhere after
(postgresql://geo:opensesame@…: opensesame is masked in a later path
too). This is scoped by where the value is in the URL, not by how it
looks: a URL in a tool call's arguments is judged the same way, and a
random password there (Tr0ub4dor3) is masked.

What the user gets: after updating (a restart forgets every known
value, the store is in memory) the project's name goes as written. The
user's ask, choosing what is masked without one exception at a time,
is already in Settings › Privacy: each kind (Passwords among them) has
Mask / Warn / Block, and Warn sends that kind as written while still
recording it; Never mask takes values. Yayoi_no_yume asked under the
same tweet for a switch per kind; that row is it. No new control is added: an Off
that records nothing would be a fourth state beside Warn with little
more to it.

The 26M: maskrec counts every place masked in every request's whole
body, and an agent resends its history each turn, so one known word in
a long Codex history was counted hundreds of times a turn. Filed as
#4193 (with the unmeasured CPU question of MaskJSON having no memo).

Tests: url_password_test.go.
TestURLPasswordWrittenElsewhereGoesAsWritten: the repo's README and
workflow lines, then the screenshot's summary text, then a Codex body
with the URL in exec_command's arguments and "cargo test -p
geodatafusion", each unchanged with 0 masked; postgres:postgres@,
root:root@, guest:guest@, app:shopdb@…/shopdb, redis://:cachebox@cachebox,
geo:geo@db/geo unchanged. TestURLPasswordStillMasked: hunter2pass,
geo:opensesame@…/geodata, geo:geod@…/geodb and redis's r3disPass
masked; Tr0ub4dor3 in a tool call's arguments masked; opensesame
masked again as known in a later path.

Broken by hand: the rule without hiddenInURL: red, both URL lines
masked, the summary 9 places masked as the screenshot shows
(/f745/<made-up>, rust/<made-up>/tests, -p <made-up>), the body 4, and
each of the six same-word URLs masked; green with it.

Run (mote, at 033b17baf + this commit): go test -run
'URLPassword|URLUserinfo|Known' ./internal/redact ok; gofmt -l clean;
GOOS=linux and GOOS=windows go vet ./internal/redact ok. Full suite
go test -count=1 -timeout 45m ./... started on mote; at push time it was
still in internal/agent and internal/gateway (load 60 to 225 from four
suites of other sessions), internal/access ok so far. Shipped without
waiting on it, as the owner asks; any red it names gets its own issue.

Not tried: a real Codex session with the geodatafusion repo; no GUI
change, so no GUI run.
This commit is contained in:
yetone
2026-10-29 15:53:04 +08:00
parent da8039368f
commit 95b40fb2f1
2 changed files with 144 additions and 1 deletions
+41 -1
View File
@@ -163,7 +163,7 @@ var rules = append([]rule{
{kind: "TOKEN", re: regexp.MustCompile(`eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}`), markers: []string{"eyJ"}, bound: tokenCh},
// the password of user:password@host, or of :password@host as a Redis
// URL has it with no user
{kind: "PASSWORD", re: regexp.MustCompile(`[A-Za-z][A-Za-z0-9+.-]*://[^\s:@/?#"'<>]*:([^\s@/?#"'<>]{3,})@`), markers: []string{"://"}, ok: notAVariable},
{kind: "PASSWORD", re: regexp.MustCompile(`[A-Za-z][A-Za-z0-9+.-]*://[^\s:@/?#"'<>]*:([^\s@/?#"'<>]{3,})@`), markers: []string{"://"}, ok: notAVariable, at: hiddenInURL},
// password = …, API_KEY: "…", as .env files and configs have them
{kind: "SECRET", re: regexp.MustCompile(`(?i)[A-Za-z0-9_.-]*(?:` + secretNames.pattern() + `)[A-Za-z0-9_.-]*` + quote + `[ \t]*[:=][ \t]*` + quote + `(` + secretCh + `{8,})`),
markers: secretNames.markers(), ok: secretValue, at: fieldAt},
@@ -409,6 +409,46 @@ func inUserinfo(s string, a int) bool {
return k < j
}
// hiddenInURL says the password at s[a:b], in a URL's user:password@,
// is hidden by masking it: it is not also written as it is elsewhere in
// the same URL, as its user name, a part of its host or of its path. A
// test database's URL often gives one word for all three:
// postgresql://geodatafusion:geodatafusion@127.0.0.1:55432/geodatafusion
// is the PostGIS test of the geodatafusion repo. Its password was masked
// while the URL still had it twice as written, and once masked the word
// was known (knownSpans): the project's folders, its crate, its .toml
// and cargo test -p geodatafusion went to the vendor as a made-up word
// for the rest of the run, as a password (xuanwo on X, 10-29: "很多项目名
// 被识别成了 password", 26M masked in a day). postgres:postgres,
// root:root and guest:guest are the same: anyone who reads the user
// reads the password. A password not written elsewhere in its URL is
// masked as before, whatever it looks like: app:geodatafusion@ masks it
// there and, as known, wherever it is next.
func hiddenInURL(s string, a, b int) bool {
pw := s[a:b]
i := strings.LastIndex(s[:a], "//")
if i < 0 || s[a-1] != ':' {
return true
}
if s[i+2:a-1] == pw {
return false // the user name
}
// the host and the path, to the URL's end
end := b + 1
for end < len(s) && !strings.ContainsRune(" \t\r\n\"'<>`\\)]}", rune(s[end])) {
end++
}
if b+1 > end {
return true
}
for _, part := range strings.FieldsFunc(s[b+1:end], func(r rune) bool { return strings.ContainsRune("/:.?#&=;,@", r) }) {
if part == pw {
return false
}
}
return true
}
// realEmail is whether v, matched as an address, is someone's. git@ is
// the user every git host is reached by over SSH (git@github.com:o/r.git,
// git@gitee.com, a company's own git@git.corp.com), no one's mailbox, and
+103
View File
@@ -0,0 +1,103 @@
package redact
import (
"regexp"
"strings"
"testing"
)
// xuanwo on X, 10-29: "很多项目名被识别成了 password". The geodatafusion
// repo's PostGIS test runs against
// postgresql://geodatafusion:geodatafusion@127.0.0.1:55432/geodatafusion
// (testing/postgis/README.md, .github/workflows/postgis-differential.yml).
// The URL's password was masked, so the word was known, and the project's
// name went as a made-up word in every path, crate and command of the
// Codex summary in their screenshot.
// the README's and the workflow's lines, as the repo has them
const geoURLLines = "GEODATAFUSION_POSTGIS_URL=postgresql://geodatafusion:geodatafusion@127.0.0.1:55432/geodatafusion \\\n" +
" GEODATAFUSION_POSTGIS_URL: postgresql://geodatafusion:geodatafusion@127.0.0.1:55432/geodatafusion\n"
// the summary in the screenshot, as Codex wrote it
const geoSummary = "**当前状态**\n" +
"- 工作树: `/Users/xuanwo/Code/worktrees/f745/geodatafusion`\n" +
"- 分支: `xuanwo/sqllogictest-coverage`\n" +
"- 构建固定使用 `CARGO_TARGET_DIR=/Users/xuanwo/.cache/geodatafusion-goal/target`、`CARGO_BUILD_JOBS=4`、`CARGO_INCREMENTAL=0`\n" +
"**未提交改动**\n" +
"- `rust/geodatafusion/tests/geos_runtime.rs`: 新增 GEOS runtime 最低版本断言; 设置 `GEODATAFUSION_EXPECT_GEOS_VERSION` 时要求精确版本。\n" +
"- `geodatafusion.toml`: `ST_LineMerge`、`ST_ConcaveHull` 从 verified 降为 partial\n" +
"```bash\n" +
"export GEOS_LIB_DIR=/Users/xuanwo/.cache/geodatafusion-goal/geos-3.11.5-prefix/lib\n" +
"CARGO_TARGET_DIR=/Users/xuanwo/.cache/geodatafusion-goal/target \\\n" +
" cargo test -p geodatafusion --features geos-3_11 --locked --lib --no-run\n" +
"BIN=$(ls -t /Users/xuanwo/.cache/geodatafusion-goal/target/debug/deps/geodatafusion-* | grep -v '\\.d$' | head -1)\n" +
"```\n"
func TestURLPasswordWrittenElsewhereGoesAsWritten(t *testing.T) {
Forget()
t.Cleanup(Forget)
o := Options{Secrets: true, Personal: true, Shape: true}
// the URL itself: the password is its user and its database, so
// nothing of it is hidden by masking it
if out, n := Mask(geoURLLines, o); out != geoURLLines || n != 0 {
t.Errorf("%d masked: %q", n, out)
}
// and so the project's name is not known: the summary goes as written,
// as a request's text and as a tool call's arguments
if out, n := Mask(geoSummary, o); out != geoSummary || n != 0 {
t.Errorf("%d masked in the summary: %q", n, out)
}
body := `{"input":[{"type":"function_call","name":"exec_command","arguments":"{\"cmd\":\"psql postgresql://geodatafusion:geodatafusion@127.0.0.1:55432/geodatafusion -c 'select 1'\"}","call_id":"call_1"},` +
`{"type":"message","role":"user","content":[{"type":"input_text","text":"cargo test -p geodatafusion"}]}]}`
if out, n := MaskJSON([]byte(body), o); string(out) != body || n != 0 {
t.Errorf("%d masked in a body: %s", n, out)
}
// the same for a password that is another part of its URL: a user's,
// a host's label, the database
for _, in := range []string{
"postgres://postgres:postgres@localhost:5432/app",
"mysql://root:root@127.0.0.1/shop",
"amqp://guest:guest@rabbit:5672/",
"mysql://app:shopdb@db.internal/shopdb?ssl=true",
"redis://:cachebox@cachebox:6379/0",
`"url": "postgresql://geo:geo@db/geo"`,
} {
if out, n := Mask(in, o); out != in || n != 0 {
t.Errorf("%d masked: %q went as %q", n, in, out)
}
}
}
// A password not written elsewhere in its URL is a password still, of
// whatever look: masked there, and as known wherever it is next. A word
// that is also a project's name is masked with it then: that is the
// user's password, and Settings › Privacy's Passwords row (Warn) or
// Never mask lets it go.
func TestURLPasswordStillMasked(t *testing.T) {
Forget()
t.Cleanup(Forget)
o := Options{Secrets: true, Personal: true}
ph := `\{\{PASSWORD_[a-z2-7]{8}\}\}`
for _, c := range []struct{ in, want string }{
{"postgres://app:hunter2pass@db.acme-corp.cn:5432/x", `^postgres://app:` + ph + `@db\.acme-corp\.cn:5432/x$`},
{"postgresql://geo:opensesame@127.0.0.1:55432/geodata", `^postgresql://geo:` + ph + `@127\.0\.0\.1:55432/geodata$`},
// a part of a part is no part: the user geo, the database geodb
{"postgresql://geo:geod@127.0.0.1/geodb", `^postgresql://geo:` + ph + `@127\.0\.0\.1/geodb$`},
{"REDIS_URL=redis://:r3disPass@cache.acme-corp.cn:6379/0", `^REDIS_URL=redis://:` + ph + `@cache\.acme-corp\.cn:6379/0$`},
} {
if out, _ := Mask(c.in, o); !regexp.MustCompile(c.want).MatchString(out) {
t.Errorf("%q went as %q", c.in, out)
}
}
// in a tool call's arguments too
body := `{"input":[{"type":"function_call","name":"exec_command","arguments":"{\"cmd\":\"psql postgresql://geo:Tr0ub4dor3@10.0.0.5/geodata\"}","call_id":"call_1"}]}`
if out, n := MaskJSON([]byte(body), o); strings.Contains(string(out), "Tr0ub4dor3") || n != 1 {
t.Fatalf("%d masked in a tool call: %s", n, out)
}
// known: the word goes masked in other words afterwards
if out, _ := Mask("cd ~/src/opensesame && ls", o); strings.Contains(out, "opensesame") {
t.Fatalf("a known password went as written: %q", out)
}
}