Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

redact: code naming a secret (secretKey: Uint8Array, toBase64Url(…)) is not masked as one

yetone511c4a765e67
diff --git a/internal/redact/code_test.go b/internal/redact/code_test.go
new file mode 100644
index 000000000..7f3159625
--- /dev/null
+++ b/internal/redact/code_test.go
@@ -0,0 +1,41 @@
+package redact
+
+import (
+ "strings"
+ "testing"
+)
+
+// Code that names a secret is no secret: a TypeScript type, a field read,
+// a call (Kieran Zhang on X, 10-25: a session's own source had each of
+// these masked as SECRET). The lines are the reporter's, as the records
+// view showed them.
+func TestCodeIsNoSecret(t *testing.T) {
+ for _, in := range []string{
+ "...: string; readonly signingKey: { readonly secretKey: Uint8Array; readonly publicKey: Uint8Array }; /** The host's cu...",
+ "... host_key: details.1,\n private_key: details.2, }); } /// `#send` ...",
+ "... url, hostKey: pair.hostKey, privateKey: toBase64Url(device.privateKey), account: { serverOrigin: clien...",
+ `...ataDir, "relay-key"); try { const secretKey = fromBase64Url((await readFile(path, "utf8")).trim()); if (secr...`,
+ "type Keys = { apiKey: Base64Str | null }",
+ "f({ token: opts.token2 })",
+ "const password = sha256Hex (input)",
+ } {
+ if out, n := Mask(in, Options{Secrets: true}); n != 0 {
+ t.Errorf("%q: %d masked: %q", in, n, out)
+ }
+ }
+ // what a secret looks like written down stays masked: a value quoted,
+ // one after =, one a line ends, as .env files, logs and YAML have them
+ for in, v := range map[string]string{
+ `secretKey: "Uint8Array9x",`: "Uint8Array9x",
+ "TOKEN=abc123def456": "abc123def456",
+ "api_key=abc123def456, user=bob": "abc123def456",
+ "password: Passw0rd123\nuser: bob": "Passw0rd123",
+ "password: Passw0rd123": "Passw0rd123",
+ `{"secretKey": "abcd1234efgh"}`: "abcd1234efgh",
+ `{\"private_key\": \"abcd1234efgh\"}`: "abcd1234efgh",
+ } {
+ if out, n := Mask(in, Options{Secrets: true}); n != 1 || strings.Contains(unmarked(out), v) {
+ t.Errorf("%q: %d masked: %q", in, n, out)
+ }
+ }
+}
diff --git a/internal/redact/redact.go b/internal/redact/redact.go
index 3bf909603..7fcff4079 100644
--- a/internal/redact/redact.go
+++ b/internal/redact/redact.go
@@ -145,12 +145,12 @@ var rules = append([]rule{
{kind: "PASSWORD", re: regexp.MustCompile(`[A-Za-z][A-Za-z0-9+.-]*://[^\s:@/?#"'<>]+:([^\s@/?#"'<>]{3,})@`), markers: []string{"://"}, ok: notAVariable},
// 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},
+ markers: secretNames.markers(), ok: secretValue, at: notCode},
// a field called key and nothing more, as providers.json has one: "key":
// "oc_sk_…" (#195). Only a long value of letters and digits both, since
// code calls anything a key: a map's "key": "value", sort_key, keyboard.
{kind: "SECRET", re: regexp.MustCompile(`(?i)(?:^|[^A-Za-z0-9_.-])` + quote + `key` + quote + `[ \t]*[:=][ \t]*` + quote + `(` + secretCh + `{16,})`),
- markers: fieldNames{{"key", "key"}}.markers(), ok: secretValue},
+ markers: fieldNames{{"key", "key"}}.markers(), ok: secretValue, at: notCode},
{kind: "EMAIL", re: regexp.MustCompile(`[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}`), markers: []string{"@"}, bound: alnum + "._%+-", ok: realEmail, cat: catPersonal},
{kind: "ID_CARD", re: regexp.MustCompile(`[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx]`), bound: alnum, ok: chineseID, cat: catPersonal},
@@ -223,6 +223,30 @@ func secretValue(v string) bool {
return strings.ContainsAny(v, digits) && strings.IndexFunc(v, func(r rune) bool { return r >= 'A' && r <= 'Z' || r >= 'a' && r <= 'z' }) >= 0
}
+// identPath is a name in code, or a field read through one: Uint8Array,
+// details.2, opts.token2.
+var identPath = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z0-9_]+)*$`)
+
+// notCode turns away a value at s[a:b] that is code naming a secret, not
+// the secret: a call (privateKey: toBase64Url(…), secretKey =
+// fromBase64Url(…)), or, unquoted after a colon, a type or a read that
+// code goes on from (secretKey: Uint8Array;, private_key: details.2,).
+// A secret written in code is a string, so in quotes; one after = or at a
+// line's end (.env files, logs, YAML) is kept (Kieran Zhang on X, 10-25).
+func notCode(s string, a, b int) bool {
+ if !identPath.MatchString(s[a:b]) {
+ return true
+ }
+ rest := strings.TrimLeft(s[b:], " \t")
+ if strings.HasPrefix(rest, "(") {
+ return false
+ }
+ if a > 0 && (s[a-1] == '"' || s[a-1] == '\'') || !strings.HasSuffix(strings.TrimRight(s[:a], " \t"), ":") {
+ return true
+ }
+ return rest == "" || !strings.ContainsRune(";,)}]|?&<>", rune(rest[0]))
+}
+
func realEmail(v string) bool {
host := strings.ToLower(v[strings.LastIndexByte(v, '@')+1:])
if fileHost(host) {