Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Redact quoted command-line flag values

Claudeed266da67831
diff --git a/pkg/asymptoteobserve/privacy.go b/pkg/asymptoteobserve/privacy.go
index 1b4d79aa..bf164416 100644
--- a/pkg/asymptoteobserve/privacy.go
+++ b/pkg/asymptoteobserve/privacy.go
@@ -46,6 +46,10 @@ const redactUnquoted = `(?:[^"'` + "`" + `,\s\\]|\\[^"'` + "`" + `])[^"'` + "`"
// structure around it.
const redactBare = `[^"'` + "`" + `\\\s,{}\[\]][^"'` + "`" + `\\\s,{}\[\]]*`
+// redactFlag is a command-line flag named for a secret and its separator: `--password `,
+// `--token=`, `-api-key `.
+const redactFlag = `(?:^|\s)--?[a-z0-9-]*(?:password|passwd|passphrase|token|secret|api-?key|access-?key)(?:=|\s+)`
+
// redactionRule is one redaction. ${1} and ${3}, when the pattern has them, are kept around the
// value.
type redactionRule struct {
@@ -100,8 +104,10 @@ var redactionRules = []redactionRule{
// and nested objects or arrays are left for their own fields' rules.
{regexp.MustCompile(`(?i)(\b` + redactLabel + `(?P<q>` + redactOpenQuote + `)\s*[:=]\s*)(?P<value>` + redactBare + `)`), "${1}${q}" + redactedValue + "${q}", isLiteralOrAuthScheme},
{regexp.MustCompile(`(?i)(\b` + redactLabel + `\s*[:=]\s*)(?P<value>` + redactUnquoted + `)`), "${1}" + redactedValue, isAuthScheme},
- // A command-line flag: `--password x`, `--token=x`, `--api-key x`.
- {regexp.MustCompile(`(?i)((?:^|\s)--?[a-z0-9-]*(?:password|passwd|passphrase|token|secret|api-?key|access-?key)(?:=|\s+))([^\s"'-][^\s"']*)()`), "${1}" + redactedValue, nil},
+ // A command-line flag: `--password x`, `--token=x`, `--api-key x`, and quoted, the way agents
+ // usually write arguments: `--password "x y"`, `--token='x'`.
+ {regexp.MustCompile(`(?i)(` + redactFlag + redactOpenQuote + `)(` + redactQuoted + `)`), "${1}" + redactedValue, nil},
+ {regexp.MustCompile(`(?i)(` + redactFlag + `)([^\s"'-][^\s"']*)`), "${1}" + redactedValue, nil},
// The password in a URL's userinfo: `postgres://user:pw@host`, `https://x-access-token:[email protected]`.
{regexp.MustCompile(`(?i)(\b[a-z][a-z0-9+.-]*://[^/\s:@"'<>]+:)([^@/\s"'<>]+)(@)`), "${1}" + redactedValue + "${3}", nil},
// Credentials recognizable by their own shape, wherever they appear. The type prefix is public
diff --git a/pkg/asymptoteobserve/privacy_test.go b/pkg/asymptoteobserve/privacy_test.go
index b21e3e2c..7abe47e2 100644
--- a/pkg/asymptoteobserve/privacy_test.go
+++ b/pkg/asymptoteobserve/privacy_test.go
@@ -264,6 +264,9 @@ func TestRedactStringTakesWholeValues(t *testing.T) {
{"quoted with spaces", `secret: "correct horse, battery staple"`, `secret: "[REDACTED]"`},
{"single quoted symbols", `password='p]a}s\\s'`, `password='[REDACTED]'`},
{"escaped json", `{\"token\": \"a]b}c d\"}`, `{\"token\": \"[REDACTED]\"}`},
+ {"quoted flag", `docker login --password "hunter2 hunter2" registry`, `docker login --password "[REDACTED]" registry`},
+ {"single quoted flag", `mysql --password 'p@ss' db`, `mysql --password '[REDACTED]' db`},
+ {"quoted flag with equals", `tool --token="opaque-value" run`, `tool --token="[REDACTED]" run`},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {