diff --git a/CHANGELOG.md b/CHANGELOG.md index ad7a834..c76f7d2 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`) + 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 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 4b27ab3..429d245 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`) 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 655cb05..8677fd3 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,11 @@ 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" 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 @@ -793,6 +798,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..4b2498b 100644 --- a/pii/secret_test.go +++ b/pii/secret_test.go @@ -622,3 +622,36 @@ func TestSecretEmptyEscapedValueHasNoSpan(t *testing.T) { } } } + +// 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") + 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", + "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`, + } { + if got := d.Mask(in); strings.Contains(got, leak) || !strings.Contains(got, Redacted) { + t.Errorf("secret.Mask(%q) = %q, leaks %q", in, got, leak) + } + } +}