diff --git a/mods/memory/hooks/register.test.ts b/mods/memory/hooks/register.test.ts index 8af39f5..a2ceb6a 100644 --- a/mods/memory/hooks/register.test.ts +++ b/mods/memory/hooks/register.test.ts @@ -1541,3 +1541,28 @@ test('TIME1: round 3 shapes stay fast on 64 KiB', () => { expect(now() - t0).toBeLessThan(50) } }) + +// ---- round 4: Set-Cookie, curl segment prefixes -------------------------- + +test('a Set-Cookie response header is redacted', () => { + expect(redact('< Set-Coo' + 'kie: session=abc123def; Path=/')) + .toBe('< Set-Cookie: ') +}) + +test('-b is redacted behind sudo, rtk, env and $( prefixes', () => { + expect(redact('sudo curl -b "sid=abc" h')).toBe('sudo curl -b h') + expect(redact('x=$(curl -b "sid=abc" h)')) + .toBe('x=$(curl -b h)') + expect(redact('X=1 rtk curl -b a=b h')).toBe('X=1 rtk curl -b h') + expect(redact('echo -b a')).toBe('echo -b a') +}) + +test('TIME1: curl prefix shapes stay fast on 64 KiB', () => { + for (const unit of ['x=$(curl -b a;', 'sudo '.repeat(3) + 'x=1 ', 'X=1 ']) { + const text = unit.repeat(Math.ceil(65536 / unit.length)) + redact(text.slice(0, 1024)) + const t0 = now() + redact(text) + expect(now() - t0).toBeLessThan(30) + } +}) diff --git a/mods/memory/hooks/register.ts b/mods/memory/hooks/register.ts index 7530d66..958ac1e 100644 --- a/mods/memory/hooks/register.ts +++ b/mods/memory/hooks/register.ts @@ -83,8 +83,8 @@ const REDACTIONS: [RegExp, string][] = [ [/npm_[A-Za-z0-9]{10,}/g, ''], [/--(token|api-key|secret)(?:=|[ \t]{1,5})\S*/g, '--$1 '], [new RegExp( - '(?'], [new RegExp( @@ -103,9 +103,11 @@ const REDACTIONS: [RegExp, string][] = [ const QUOTED = /'[^'\n]*'|"[^"\n]*"/g const SEPARATOR = /[;&|\n]+/g +// before `curl`: ( $( NAME=value NAME=$( sudo rtk const CURL_SEGMENT = new RegExp( - '^[ \\t(]{0,5}(?:rtk[ \\t]{1,5})?' + - '(?:[A-Za-z_]\\w{0,60}=\\S{0,200}[ \\t]{1,5}){0,10}curl\\b', + '^[ \\t(]{0,5}(?:\\$\\()?(?:[A-Za-z_]\\w{0,60}=' + + '(?:\\S{0,200}[ \\t]{1,5}|\\$\\()|(?:sudo|rtk)[ \\t]{1,5}){0,10}' + + 'curl\\b', ) const COOKIE_FLAG = new RegExp(`(?<=^|\\s)-b[ \\t]{1,5}${VALUE}`, 'g')