From 6c0aa4b25fa794db02c3a01406046a06a50a0639 Mon Sep 17 00:00:00 2001 From: DavidG Date: Sat, 14 Nov 2026 11:35:37 +0000 Subject: [PATCH 1/2] fix(pii): auth-only secret flags need a credential value (#198) findSecretFlags masked the word after any flag LooksSecret accepts, so initdb's "--auth-local and --auth-host" hint lost "and". A flag secret only through "auth" now masks its value only when it looks like a credential and is no auth method name; a bare stop word is never a secret flag's value. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 +++++++ GUIDE.md | 4 ++++ pii/secret.go | 34 +++++++++++++++++++++++++++++++++- pii/secret_test.go | 30 ++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad7a834..ba0e711 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,13 @@ GUIDE.md is the contract between lockkit and the products built on it. `name`/`full_name`/`nom`/`naam` with EN/FR/NL/DE names, and `products`/`roles`/`cities`/`tags` negatives), held to the baseline like the detectors (#163). +- pii: a bare stop word (`and`, `or`, `to`…) after a secret command-line + flag is no longer masked (`use --password or --token`), and a flag + secret only through `auth` (`--auth`, `--auth-local`, `--auth-host`) + masks its value only when it looks like a credential: initdb's + `--auth-local and --auth-host` hint and `--auth-local peer` stay + readable; `--auth-token …`, `--auth s3cr3tT0ken` and + `--password hunter2` stay masked (#198). ## v0.19.1 (2026-11-13) diff --git a/GUIDE.md b/GUIDE.md index 4b27ab3..d4d813d 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -458,6 +458,10 @@ itself (lockssh runs its commands there). value is a path. `docker`/`podman`/`nerdctl`/`buildah login -p` and `mongo*` `-p` are masked; `-p` elsewhere is not. Status words under a secret name (`auth=failed`) are masked too. A + bare stop word after a secret flag (`--password or --token`) is kept; + a flag secret only through `auth` (`--auth`, `--auth-local`) masks its + value only when it looks like a credential, not a method name + (`--auth-host scram-sha-256`) or a plain word. A dotted quad after `version`, `build`, `release`, `oid` or a product token (`Chrome/124.0.0.0`) is no address. - `pii.LooksSecret(name)`: a field, header or flag name that holds a diff --git a/pii/secret.go b/pii/secret.go index 655cb05..cd353ed 100644 --- a/pii/secret.go +++ b/pii/secret.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "math" "regexp" + "slices" "strings" "unicode/utf8" ) @@ -782,7 +783,12 @@ func findSecretFlags(s string) []span { secret = ok && p != "" && !allDigits(u+p) case (len(flag) > 2 && flag[1] == '-' || len(flag) > 3) && LooksSecret(flag): // "--password x", and single-dash Java-style "-storepass x". - secret = true + // "use --password or --token" is prose; "--auth-local peer" + // names a method: a flag secret only by "auth" needs a value + // shaped like a credential. + bare := vs == start + secret = !(bare && stopWords[strings.ToLower(v)]) && + (!authOnly(flag) || looksCredential(v) && !authMethods[strings.ToLower(v)]) } if !secret || ve <= vs { return start @@ -793,6 +799,32 @@ func findSecretFlags(s string) []span { return out } +// stopWords are never the value of a secret flag: "--auth-local and +// --auth-host", "pass --password or --token". +var stopWords = set("and", "or", "to", "the", "with", "a", "an", "of", "for", "in", "on", "by", "then", "is", "if", "not", "nor", "but") + +// authMethods name an authentication method, not a credential: initdb's +// "--auth-host scram-sha-256", "--auth-local peer". +var authMethods = set( + "trust", "reject", "md5", "password", "scram-sha-256", "gss", "sspi", "ident", "peer", "ldap", "radius", + "cert", "pam", "bsd", "basic", "digest", "bearer", "ntlm", "negotiate", "kerberos", "oauth", "none", +) + +// authOnly reports a flag that is secret only through its "auth" token: +// "--auth", "--auth-local", "--auth-host", but not "--auth-token" or +// "--auth-key". +func authOnly(flag string) bool { + toks := Tokens(flag) + if !slices.Contains(toks, "auth") { + return false + } + rest := slices.DeleteFunc(slices.Clone(toks), func(t string) bool { return t == "auth" }) + if slices.Contains(rest, "key") { + return false // "--auth-key": an owned key + } + return len(rest) == 0 || !LooksSecret(strings.Join(rest, "-")) +} + func allDigits(s string) bool { for i := 0; i < len(s); i++ { if !isDigit(s[i]) { diff --git a/pii/secret_test.go b/pii/secret_test.go index 7459dd9..1f373fe 100644 --- a/pii/secret_test.go +++ b/pii/secret_test.go @@ -622,3 +622,33 @@ func TestSecretEmptyEscapedValueHasNoSpan(t *testing.T) { } } } + +// A flag secret only through "auth" names a method unless its value looks +// like a credential, and a stop word is never a secret flag's value +// (lockkit#198, from initdb's hint). +func TestSecretFlagAuthAndStopWords(t *testing.T) { + d := detector(t, "secret") + for _, in := range []string{ + "initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.", + "initdb --auth-local peer --auth-host scram-sha-256", + "use --password or --token to log in", + "--auth basic", + } { + if got := d.Mask(in); got != in { + t.Errorf("secret.Mask(%q) = %q, want unchanged", in, got) + } + } + for in, leak := range map[string]string{ + "--auth-token abcd1234efgh5678": "abcd1234efgh5678", + "--auth s3cr3tT0ken": "s3cr3tT0ken", + "--auth-local Zq8Lr2Vt6Wn0Yp4X": "Zq8Lr2Vt6Wn0Yp4X", + "--auth-key k3y": "k3y", + "--password hunter2": "hunter2", + "--token tok9": "tok9", + `--password "and"`: `and`, + } { + if got := d.Mask(in); strings.Contains(got, leak) || !strings.Contains(got, Redacted) { + t.Errorf("secret.Mask(%q) = %q, leaks %q", in, got, leak) + } + } +} From ee3722160dca0cbdaea465e2403850d1afe025c6 Mon Sep 17 00:00:00 2001 From: DavidG Date: Sat, 14 Nov 2026 11:44:51 +0000 Subject: [PATCH 2/2] fix(pii): auth-only flags keep only auth method names Review: "--auth admin:pw" (httpie) and "--basic-auth admin:pw" would leak through the looksCredential test. Keep only a known method name. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 +++--- GUIDE.md | 6 +++--- pii/secret.go | 9 ++++----- pii/secret_test.go | 7 +++++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba0e711..c76f7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,10 @@ GUIDE.md is the contract between lockkit and the products built on it. - pii: a bare stop word (`and`, `or`, `to`…) after a secret command-line flag is no longer masked (`use --password or --token`), and a flag secret only through `auth` (`--auth`, `--auth-local`, `--auth-host`) - masks its value only when it looks like a credential: initdb's + keeps an auth method name (`peer`, `scram-sha-256`, `md5`…): initdb's `--auth-local and --auth-host` hint and `--auth-local peer` stay - readable; `--auth-token …`, `--auth s3cr3tT0ken` and - `--password hunter2` stay masked (#198). + readable; `--auth admin:pw`, `--auth-token …`, `--auth s3cr3tT0ken` + and `--password hunter2` stay masked (#198). ## v0.19.1 (2026-11-13) diff --git a/GUIDE.md b/GUIDE.md index d4d813d..429d245 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -459,9 +459,9 @@ itself (lockssh runs its commands there). login -p` and `mongo*` `-p` are masked; `-p` elsewhere is not. Status words under a secret name (`auth=failed`) are masked too. A bare stop word after a secret flag (`--password or --token`) is kept; - a flag secret only through `auth` (`--auth`, `--auth-local`) masks its - value only when it looks like a credential, not a method name - (`--auth-host scram-sha-256`) or a plain word. A + a flag secret only through `auth` (`--auth`, `--auth-local`) keeps an + auth method name (`--auth-host scram-sha-256`, `--auth-local peer`) + and masks any other value (`--auth admin:pw`). A dotted quad after `version`, `build`, `release`, `oid` or a product token (`Chrome/124.0.0.0`) is no address. - `pii.LooksSecret(name)`: a field, header or flag name that holds a diff --git a/pii/secret.go b/pii/secret.go index cd353ed..8677fd3 100644 --- a/pii/secret.go +++ b/pii/secret.go @@ -784,11 +784,10 @@ func findSecretFlags(s string) []span { case (len(flag) > 2 && flag[1] == '-' || len(flag) > 3) && LooksSecret(flag): // "--password x", and single-dash Java-style "-storepass x". // "use --password or --token" is prose; "--auth-local peer" - // names a method: a flag secret only by "auth" needs a value - // shaped like a credential. - bare := vs == start - secret = !(bare && stopWords[strings.ToLower(v)]) && - (!authOnly(flag) || looksCredential(v) && !authMethods[strings.ToLower(v)]) + // names a method: a flag secret only by "auth" keeps a method + // name, and masks anything else ("--auth admin:pw", httpie). + lv := strings.ToLower(v) + secret = !(vs == start && stopWords[lv]) && !(authOnly(flag) && authMethods[lv]) } if !secret || ve <= vs { return start diff --git a/pii/secret_test.go b/pii/secret_test.go index 1f373fe..4b2498b 100644 --- a/pii/secret_test.go +++ b/pii/secret_test.go @@ -623,8 +623,8 @@ func TestSecretEmptyEscapedValueHasNoSpan(t *testing.T) { } } -// A flag secret only through "auth" names a method unless its value looks -// like a credential, and a stop word is never a secret flag's value +// A flag secret only through "auth" keeps an auth method name and masks +// any other value, and a stop word is never a secret flag's value // (lockkit#198, from initdb's hint). func TestSecretFlagAuthAndStopWords(t *testing.T) { d := detector(t, "secret") @@ -643,6 +643,9 @@ func TestSecretFlagAuthAndStopWords(t *testing.T) { "--auth s3cr3tT0ken": "s3cr3tT0ken", "--auth-local Zq8Lr2Vt6Wn0Yp4X": "Zq8Lr2Vt6Wn0Yp4X", "--auth-key k3y": "k3y", + "http --auth admin:pw x.io": "admin:pw", + "--basic-auth admin:pw": "admin:pw", + "--auth hunter": "hunter", "--password hunter2": "hunter2", "--token tok9": "tok9", `--password "and"`: `and`,