mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 16:25:30 +00:00
fix(hooks): try later JWT header candidates after a failed prefix match
A word prefix such as `eyewear_session_` was taken as the only JWT header candidate; when it failed validation the real header after `_` was never tried and the token stayed in the command log. Keep scanning eligible candidates, with a constant-time prefilter and a per-segment decode cap so long candidate runs stay linear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f0eee4b543
commit
5f72adbd83
2 files changed
+65
-24
No files matched your search
@@ -182,6 +182,33 @@ if (
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('sanitizeCommand tries later JWT headers after a prefix candidate fails', () => {
|
||||
const spacedHeader = Buffer.from('{ "alg": "HS256" }').toString('base64url');
|
||||
const newlineHeader = Buffer.from('{\n"alg":"HS256"}').toString('base64url');
|
||||
for (const header of [spacedHeader, newlineHeader]) {
|
||||
const token = [header, 'eyJzdWIiOiJmYWtlIn0', 'ZmFrZXNpZ25hdHVyZQ'].join('.');
|
||||
assert.strictEqual(sanitizeCommand(`echo eyewear_session_${token}`), 'echo eyewear_session_<REDACTED>');
|
||||
assert.strictEqual(sanitizeCommand(`echo ey-eye-${token}`), 'echo ey-eye-<REDACTED>');
|
||||
}
|
||||
assert.strictEqual(sanitizeCommand('ls eyewear_session_eyebrows.backup.tar'), 'ls eyewear_session_eyebrows.backup.tar');
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('sanitizeCommand stays linear on long runs of plausible JWT header candidates', () => {
|
||||
const start = Date.now();
|
||||
sanitizeCommand(`${'eyAg-'.repeat(200000)}x.y.z`);
|
||||
sanitizeCommand(`${'ewog_'.repeat(200000)}x.y.z`);
|
||||
const elapsed = Date.now() - start;
|
||||
assert.ok(elapsed < 2000, `took ${elapsed} ms`);
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('sanitizeCommand stays linear on long ey- runs followed by dots', () => {
|
||||
const start = Date.now();
|
||||
|
||||
Reference in new issue
Block a user