mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 21:42:11 +00:00
fix(hooks): redact spaced-header JWTs and escaped or $'...' secret values
Match JWT headers that start with ey or ew (whitespace after the opening brace) and keep non-eyJ matches only when the header does not decode to an object with an alg field. Parse secret= / api_key= values with escaped double quotes, $'...' quoting and backslash escapes, and redact an unterminated quoted value to the end of the command. Refs #3846
This commit is contained in:
1 parent
08fb3c8a1c
commit
0b57406e57
2 files changed
+57
-2
No files matched your search
@@ -95,6 +95,42 @@ if (
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('sanitizeCommand redacts JWTs whose header has whitespace after the brace', () => {
|
||||
const spacedHeader = Buffer.from('{ "alg": "HS256" }').toString('base64url');
|
||||
const newlineHeader = Buffer.from('{\n"alg":"HS256"}').toString('base64url');
|
||||
assert.ok(spacedHeader.startsWith('eyA'), spacedHeader);
|
||||
assert.ok(newlineHeader.startsWith('ew'), newlineHeader);
|
||||
for (const header of [spacedHeader, newlineHeader]) {
|
||||
const token = [header, 'eyJzdWIiOiJmYWtlIn0', 'ZmFrZXNpZ25hdHVyZQ'].join('.');
|
||||
assert.strictEqual(sanitizeCommand(`export TOKEN_VALUE=${token}`), 'export TOKEN_VALUE=<REDACTED>');
|
||||
}
|
||||
|
||||
// Same shape, but the first segment does not decode to a JWT header.
|
||||
const notJwt = 'eyesightdata.example.com';
|
||||
assert.strictEqual(sanitizeCommand(`ping ${notJwt}`), `ping ${notJwt}`);
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('sanitizeCommand redacts whole quoted assignment values, including escapes', () => {
|
||||
assert.strictEqual(
|
||||
sanitizeCommand(`app --secret="first\\"${FAKE_VALUE}" --next`),
|
||||
'app --secret=<REDACTED> --next'
|
||||
);
|
||||
assert.strictEqual(
|
||||
sanitizeCommand(`app --secret=$'first\\'${FAKE_VALUE}' --next`),
|
||||
'app --secret=<REDACTED> --next'
|
||||
);
|
||||
assert.strictEqual(sanitizeCommand(`app --secret=first\\"${FAKE_VALUE} --next`), 'app --secret=<REDACTED> --next');
|
||||
assert.strictEqual(sanitizeCommand(`app --secret="${FAKE_VALUE} unterminated`), 'app --secret=<REDACTED>');
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('sanitizeCommand redacts secret= and api_key= assignments (#3846)', () => {
|
||||
assert.strictEqual(
|
||||
|
||||
Reference in new issue
Block a user