diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 39101dfb0..909217e79 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": "e97d914bd5d871e528da92d905fd768be77b89220a108817f59bac2cbc2f0969", + "registryDigest": "65b0e26848994515124a8e256e8f2ec996453b98bd89c461407edf3c2d1e3883", "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 93a115620..fa6ddd7d7 100755 --- a/skills/continuous-learning-v2/hooks/observe.sh +++ b/skills/continuous-learning-v2/hooks/observe.sh @@ -295,7 +295,7 @@ _SECRET_RE = re.compile( _PEM_RE = re.compile(r"-----BEGIN[A-Z ]{0,40}PRIVATE KEY-----[\s\S]*?(?:-----END[A-Z ]{0,40}PRIVATE KEY-----|\Z)") _SECRET_VALUE_RE = re.compile( r"(?:(? key.txt`, anthropicCanary], ['bare OpenAI project key', `client = OpenAI(${openaiProjectKey})`, openaiCanary], ['bare legacy sk- key', `KEYS = [${legacyKey}]`, legacyCanary], - ['bare JWT', `curl -H "X-Session: ${jwt}" https://api.example.com`, jwtCanary] + ['bare JWT', `curl -H "X-Session: ${jwt}" https://api.example.com`, jwtCanary], + ['bare JWT with empty claims', `curl -H "X-Session: ${emptyClaimsJwt}" https://api.example.com`, jwtCanary], + // Redacted to the end of the token, not skipped because a hyphen follows. + ['bare legacy sk- key with a suffix', `KEYS = [${legacyKey}-CANARYsuffix]`, 'CANARYsuffix'] ]) { test(`redacts ${label} before persisting tool input`, () => { const records = capture('pre', { tool_name: 'Write', @@ -99,6 +104,12 @@ if (process.platform === 'win32') { if (label === 'bare JWT') { assert.equal(capturedField(records, 'content'), content.replace(jwt, '[REDACTED]')); } + if (label === 'bare JWT with empty claims') { + assert.equal(capturedField(records, 'content'), content.replace(emptyClaimsJwt, '[REDACTED]')); + } + if (label === 'bare legacy sk- key with a suffix') { + assert.equal(capturedField(records, 'content'), 'KEYS = [[REDACTED]]'); + } }); test(`redacts ${label} before persisting structured tool output`, () => { const records = capture('post', { tool_name: 'Read', @@ -293,6 +304,51 @@ if (process.platform === 'win32') { for (const line of benign) assert.ok(records.includes(line), `benign text altered: ${line}`); assert.ok(!records.includes('[REDACTED]')); }); + // Both writers carry the same patterns. Run them on 300 KB of adversarial + // input so a pattern that backtracks quadratically (#2278) fails here. + test('scrub patterns stay identical in both writers and linear on 300 KB input', () => { + const hook = fs.readFileSync( + path.join(repoRoot, 'skills/continuous-learning-v2/hooks/observe.sh'), 'utf8'); + const copies = hook.split('_SECRET_RE = re.compile(').slice(1).map((rest) => + `_SECRET_RE = re.compile(${rest.split(/\n(?:import signal|def scrub)/)[0]}` + .replace(/'"'"'/g, "'")); + assert.equal(copies.length, 2); + assert.equal(copies[0], copies[1], 'the parse-error copy of the patterns drifted'); + const driver = String.raw` +import re, sys, time +ns = {"re": re} +exec(sys.stdin.read(), ns) +patterns = [ns[n] for n in ("_PEM_RE", "_SECRET_RE", "_SECRET_VALUE_RE", "_CUT_TAIL_RE")] +n = 300000 +cases = { + "hyphen run": "a-" * (n // 2), + "sk- then hyphen run": "sk-" + "a-" * (n // 2), + "repeated sk-": "sk-" * (n // 3), + "sk- keys followed by a hyphen": (" sk-" + "a" * 40 + "-") * (n // 45), + "eyJ segments": ("eyJ" + "a-" * 10 + ".") * (n // 24), + "repeated eyJ dots": "eyJ." * (n // 4), + "label then hyphens": "token=" + "-" * n, + "repeated labels": "token:" * (n // 6), + "escaped newline before sk-": "\\nsk-" * (n // 5), + "unfinished DSNs": "a://b:" * (n // 6), + "unterminated PEM": "-----BEGIN RSA PRIV" + "ATE KEY-----" + "A" * n, +} +for name, text in cases.items(): + start = time.perf_counter() + for pattern in patterns: + pattern.sub("X", text) + print("%s\t%.3f" % (name, time.perf_counter() - start)) +`; + const result = spawnSync('python3', ['-c', driver], + { input: copies[0], encoding: 'utf8', timeout: 60000 }); + assert.equal(result.status, 0, result.stderr || 'timed out'); + const timings = result.stdout.trim().split('\n'); + assert.equal(timings.length, 11); + for (const line of timings) { + const [name, seconds] = line.split('\t'); + assert.ok(Number(seconds) < 2, `${name} took ${seconds}s`); + } + }); test('keeps a trailing host:port in string output unredacted', () => { const records = capture('post', { tool_name: 'Bash', tool_input: { command: 'npm run dev' }, tool_response: 'listening on http://localhost:3000' });