mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 21:42:11 +00:00
fix(hooks): redact JWTs joined to an underscore-prefixed label
The JWT chain scanner only accepted a header at the start of a segment or after `-`, so `session_<JWT>` reached the audit and cost logs unredacted. Treat `_` as a prefix boundary too and cover it in the tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
71084e0555
commit
f0eee4b543
2 files changed
+8
-5
No files matched your search
@@ -34,8 +34,9 @@ function redactJwt(token) {
|
||||
}
|
||||
|
||||
// Redact JWTs inside one run of `[A-Za-z0-9_.-]` characters. A JWT may follow
|
||||
// a word prefix joined by `-` (`session=jwt-<JWT>`), so each dot-separated
|
||||
// segment is checked for a header starting at its beginning or after a `-`.
|
||||
// a word prefix joined by `-` or `_` (`session=jwt-<JWT>`, `session_<JWT>`), so
|
||||
// each dot-separated segment is checked for a header starting at its beginning
|
||||
// or after a `-` or `_`.
|
||||
// Every segment is scanned once and decoded at most once, keeping long
|
||||
// `ey-ey-...` runs linear (a `\b`-anchored regex retries at each `-`).
|
||||
function redactJwtsInChain(chain) {
|
||||
@@ -49,7 +50,7 @@ function redactJwtsInChain(chain) {
|
||||
let first = -1;
|
||||
let preferred = -1;
|
||||
for (let j = 0; j + 10 <= seg.length; j++) {
|
||||
if ((j === 0 || seg[j - 1] === '-') && seg[j] === 'e' && (seg[j + 1] === 'y' || seg[j + 1] === 'w')) {
|
||||
if ((j === 0 || seg[j - 1] === '-' || seg[j - 1] === '_') && seg[j] === 'e' && (seg[j + 1] === 'y' || seg[j + 1] === 'w')) {
|
||||
if (first < 0) first = j;
|
||||
if (seg.startsWith('eyJ', j)) {
|
||||
preferred = j;
|
||||
|
||||
@@ -166,7 +166,7 @@ if (
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('sanitizeCommand redacts JWTs joined to a hyphenated prefix', () => {
|
||||
test('sanitizeCommand redacts JWTs joined to a hyphenated or underscored prefix', () => {
|
||||
assert.strictEqual(
|
||||
sanitizeCommand(`curl --cookie "session=jwt-${FAKE_JWT}" https://example.com`),
|
||||
'curl --cookie "session=jwt-<REDACTED>" https://example.com'
|
||||
@@ -174,7 +174,9 @@ if (
|
||||
assert.strictEqual(sanitizeCommand(`echo prefix-${FAKE_JWT}`), 'echo prefix-<REDACTED>');
|
||||
assert.strictEqual(sanitizeCommand(`echo ey-${FAKE_JWT}`), 'echo ey-<REDACTED>');
|
||||
assert.strictEqual(sanitizeCommand(`open https://x.example.com/a.${FAKE_JWT}`), 'open https://x.example.com/a.<REDACTED>');
|
||||
assert.strictEqual(sanitizeCommand('ping eyesightdata.example.com'), 'ping eyesightdata.example.com');
|
||||
assert.strictEqual(sanitizeCommand('ping eyesightdata.example.com'), 'ping eyesightdata.example.com'); assert.strictEqual(sanitizeCommand(`echo session_${FAKE_JWT}`), 'echo session_<REDACTED>');
|
||||
assert.strictEqual(sanitizeCommand(`export AUTH=bearer_${FAKE_JWT}`), 'export AUTH=bearer_<REDACTED>');
|
||||
assert.strictEqual(sanitizeCommand('ls my_eyes.backup.tar'), 'ls my_eyes.backup.tar');
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
|
||||
Reference in new issue
Block a user