From 7d4473432818e78baf0063382b7ca2f5fd9695fa Mon Sep 17 00:00:00 2001 From: Wen Date: Sat, 17 Oct 2026 09:43:42 -0300 Subject: [PATCH] fix(continuous-learning-v2): redact numeric DSN passwords cut at the truncation boundary --- skills/continuous-learning-v2/hooks/observe.sh | 14 ++++++++------ tests/hooks/observe-secret-redaction.test.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/skills/continuous-learning-v2/hooks/observe.sh b/skills/continuous-learning-v2/hooks/observe.sh index 2e38a9b47..aecb29a07 100755 --- a/skills/continuous-learning-v2/hooks/observe.sh +++ b/skills/continuous-learning-v2/hooks/observe.sh @@ -283,11 +283,12 @@ _SECRET_RE = re.compile( # on a literal prefix and uses bounded or non-overlapping classes (#2278). # Tokens may follow a JSON escape (\n, \t, \uXXXX) since dict I/O is encoded # before scrubbing; a DSN cut by truncation before its "@" ends at \Z, -# except a bare trailing host:port such as http://localhost:3000 (#3568). +# except a bare trailing host:port after http(s):// such as http://localhost:3000; +# any other scheme (postgres://app:1234) is redacted even when the password is numeric (#3568). _SECRET_VALUE_RE = re.compile( r"-----BEGIN[A-Z ]{0,40}PRIVATE KEY-----[\s\S]*?(?:-----END[A-Z ]{0,40}PRIVATE KEY-----|\Z)" r"|(?:(?> "$OBSERVATIONS_FILE" exit 0 @@ -367,18 +368,19 @@ _SECRET_RE = re.compile( # on a literal prefix and uses bounded or non-overlapping classes (#2278). # Tokens may follow a JSON escape (\n, \t, \uXXXX) since dict I/O is encoded # before scrubbing; a DSN cut by truncation before its "@" ends at \Z, -# except a bare trailing host:port such as http://localhost:3000 (#3568). +# except a bare trailing host:port after http(s):// such as http://localhost:3000; +# any other scheme (postgres://app:1234) is redacted even when the password is numeric (#3568). _SECRET_VALUE_RE = re.compile( r"-----BEGIN[A-Z ]{0,40}PRIVATE KEY-----[\s\S]*?(?:-----END[A-Z ]{0,40}PRIVATE KEY-----|\Z)" r"|(?:(? 'a'.repeat(end - ' postgres://app:1234'.length) + ' postgres://app:1234'; + for (const [label, phase, input, expectedEvent] of [ + ['string tool output', 'post', { tool_name: 'Bash', tool_input: { command: 'env' }, + tool_response: numPad(5000) }], + ['parse-error fallback', 'post', JSON.stringify([numPad(2000 - 2)]), 'parse_error'] + ]) { + test(`redacts numeric DSN password cut at the truncation boundary in ${label}`, () => { + const records = capture(phase, input, expectedEvent); + assert.ok(!records.includes('app:1234'), 'numeric DSN password persisted'); + assert.ok(records.includes('postgres://app:[REDACTED]')); + }); + } + // Ordinary code, URLs without credentials and SSH remotes stay readable. const benign = [ 'const tokenizer = new Tokenizer(config);',