From 16a23737f23a5c95050832d079ee0d0c77cfe240 Mon Sep 17 00:00:00 2001 From: Karim Masmoudi <125830216+Kernel-Hunter@users.noreply.github.com> Date: Wed, 4 Nov 2026 11:43:29 +0100 Subject: [PATCH] fix(continuous-learning-v2): run shape patterns before the keyword matcher _SECRET_RE stops after 256 value chars. With it first, a longer keyword-labeled key such as OPENAI_API_KEY=sk-proj-... lost its prefix and the shape pattern could no longer see the rest, so the tail was persisted. Running _SECRET_VALUE_RE first fixes both the observation path and the parse-error fallback; "[REDACTED]" is outside the keyword value class, so the second pass leaves it alone. --- manifests/context-packs/skill-triggers@1.json | 2 +- skills/continuous-learning-v2/hooks/observe.sh | 8 ++++++-- tests/hooks/observe-secret-redaction.test.js | 13 +++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 255b3ed61..6798959fa 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": "f24282bd1d290f922b4ffe2f996ae7b249f84ef2a18804ff97633012818f3093", + "registryDigest": "e93e6248f74627968ef65d9bf0e64a6c0d22abce6efc6342c856613bf3262015", "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 66984e351..e3bc85e4d 100755 --- a/skills/continuous-learning-v2/hooks/observe.sh +++ b/skills/continuous-learning-v2/hooks/observe.sh @@ -313,8 +313,10 @@ except Exception: raw_full = sys.stdin.read() raw = raw_full[:2000] -raw = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", raw) +# Shape patterns first: _SECRET_RE stops after 256 value chars, which would +# strip the sk-/eyJ prefix from a longer keyword-labeled key and leave its tail. raw = _SECRET_VALUE_RE.sub(lambda m: (m.group(2) or "") + "[REDACTED]", raw) +raw = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", raw) if len(raw_full) > 2000: raw = _CUT_TAIL_RE.sub("[REDACTED]", raw) print(json.dumps({"timestamp": os.environ["TIMESTAMP"], "event": "parse_error", "raw": raw})) @@ -405,8 +407,10 @@ def scrub(val): val = str(val) # Tool I/O is cut to 5000 chars before it reaches this process. cut = len(val) >= 5000 - val = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", val) + # Shape patterns first: _SECRET_RE stops after 256 value chars, which would + # strip the sk-/eyJ prefix from a longer keyword-labeled key and leave its tail. val = _SECRET_VALUE_RE.sub(lambda m: (m.group(2) or "") + "[REDACTED]", val) + val = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", val) return _CUT_TAIL_RE.sub("[REDACTED]", val) if cut else val if parsed["input"]: diff --git a/tests/hooks/observe-secret-redaction.test.js b/tests/hooks/observe-secret-redaction.test.js index d9668e61c..cc500bfd0 100644 --- a/tests/hooks/observe-secret-redaction.test.js +++ b/tests/hooks/observe-secret-redaction.test.js @@ -190,6 +190,19 @@ if (process.platform === 'win32') { assert.equal(capturedField(records, 'content'), 'value [REDACTED] end'); }); } + // The keyword matcher stops after 256 value chars, so a long keyword-labeled + // key must be caught by its shape first or its tail is persisted. + for (const [phase, input, expectedEvent] of [ + ['post', { tool_name: 'Read', tool_input: { file_path: '/tmp/x' }, + tool_response: { content: `OPENAI_API_KEY=${openaiProjectKey}${'B'.repeat(300)}${longTail}` } }], + ['post', JSON.stringify([`OPENAI_API_KEY=${openaiProjectKey}${'B'.repeat(300)}${longTail}`]), 'parse_error'] + ]) { + test(`redacts a long keyword-labeled sk-proj key completely (${expectedEvent || 'tool_complete'})`, () => { + const records = capture(phase, input, expectedEvent); + assert.ok(!records.includes(longTail), 'key tail persisted'); + assert.ok(records.includes('OPENAI_API_KEY=[REDACTED]')); + }); + } // The end-of-capture match only applies to text that was actually cut. for (const output of ['git checkout sk-learn', 'payload eyJhIjoxLCJiIjoyfQ']) {