diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 3540c8edb..ba61cb296 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "cf364a6536f8fb3b0f0cda52a49fd3751513eff988ce5fadc15abcb1e4577358", + "registryDigest": "d065943b86358b5dc5f84c5910de117b21650c0be34071457d20820b28d68e7a", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/skills/continuous-learning-v2/hooks/observe.sh b/skills/continuous-learning-v2/hooks/observe.sh index 35c525997..7aa2e4dde 100755 --- a/skills/continuous-learning-v2/hooks/observe.sh +++ b/skills/continuous-learning-v2/hooks/observe.sh @@ -279,8 +279,9 @@ _SECRET_RE = re.compile( ) # Value-shaped secrets that carry no keyword: PEM private key blocks (to END or # end of the truncated text), GitHub tokens, AWS key IDs, Anthropic and OpenAI -# style sk- keys, JWTs (eyJ header, payload, optional signature) and DSN -# passwords (scheme://user:PASSWORD@host keeps scheme and user). Each branch is anchored +# style sk- keys and JWTs (eyJ header, payload, optional signature; either one +# cut by truncation ends at \Z), and DSN passwords (scheme://user:PASSWORD@host +# keeps scheme and user). Each branch is anchored # 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, @@ -289,7 +290,7 @@ _SECRET_RE = re.compile( _SECRET_VALUE_RE = re.compile( r"-----BEGIN[A-Z ]{0,40}PRIVATE KEY-----[\s\S]*?(?:-----END[A-Z ]{0,40}PRIVATE KEY-----|\Z)" r"|(?:(? { const records = capture('post', { tool_name: 'Read', @@ -131,7 +141,8 @@ if (process.platform === 'win32') { tool_response: { stdout: command, stderr: '' } }) ]) { assert.ok(!records.includes(anthropicCanary), 'Anthropic key persisted'); - assert.ok(records.includes('[REDACTED]')); + const field = JSON.parse(records).event === 'tool_start' ? 'command' : 'stdout'; + assert.equal(capturedField(records, field), command.replace(anthropicKey, '[REDACTED]')); } }); } @@ -141,6 +152,32 @@ if (process.platform === 'win32') { assert.ok(records.includes('[REDACTED]')); }); + // Truncation can also cut a bare JWT inside its payload or a key inside its + // body. What is left at the end of the capture must still be redacted. + const jwtKept = jwt.slice(0, jwt.indexOf('.') + 10); + const jwtPayloadStart = jwtKept.slice(jwt.indexOf('.') + 1); + const keyKept = anthropicKey.slice(0, 'sk-ant-api03-'.length + 12); + const cutAt = (end, value, kept) => `${'a'.repeat(end - kept.length - 1)} ${value}`; + for (const [label, value, kept, leak] of [ + ['JWT', jwt, jwtKept, jwtPayloadStart], + ['Anthropic key', anthropicKey, keyKept, keyKept.slice('sk-ant-api03-'.length)] + ]) { + for (const [where, phase, input, expectedEvent] of [ + ['string tool output', 'post', { tool_name: 'Bash', tool_input: { command: 'env' }, + tool_response: cutAt(5000, value, kept) }], + // json.dumps prefixes '{"content": "' (13 chars) before the value. + ['structured tool output', 'post', { tool_name: 'Read', tool_input: { file_path: '/tmp/x' }, + tool_response: { content: cutAt(5000 - 13, value, kept) } }], + ['parse-error fallback', 'post', JSON.stringify([cutAt(2000 - 2, value, kept)]), 'parse_error'] + ]) { + test(`redacts the ${label} cut at the truncation boundary in ${where}`, () => { + const records = capture(phase, input, expectedEvent); + assert.ok(!records.includes(leak), `cut ${label} persisted`); + assert.ok(records.includes('[REDACTED]')); + }); + } + } + // Capture truncation (5000 chars, 2000 in the parse-error fallback) can cut a // DSN right before its '@'; the password must still be redacted (#3568). const cutSecret = 'CANARYcutPassw0rd';