fix(memory): Set-Cookie header, curl segment prefixes

Header rule names Set-Cookie again behind the lookbehind. The curl
segment test admits sudo, rtk, NAME=value, NAME=$( and $( prefixes.
This commit is contained in:
bchanot committed 2026-11-04 15:33:33 +01:00
1 parent 08e36dcc0b
commit 5d55585ea5
2 files changed
+31 -4

No files matched your search

+25
View File
@@ -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: <redacted>')
})
test('-b is redacted behind sudo, rtk, env and $( prefixes', () => {
expect(redact('sudo curl -b "sid=abc" h')).toBe('sudo curl -b <redacted> h')
expect(redact('x=$(curl -b "sid=abc" h)'))
.toBe('x=$(curl -b <redacted> h)')
expect(redact('X=1 rtk curl -b a=b h')).toBe('X=1 rtk curl -b <redacted> 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)
}
})
+6 -4
View File
@@ -83,8 +83,8 @@ const REDACTIONS: [RegExp, string][] = [
[/npm_[A-Za-z0-9]{10,}/g, '<redacted:npm>'],
[/--(token|api-key|secret)(?:=|[ \t]{1,5})\S*/g, '--$1 <redacted>'],
[new RegExp(
'(?<![A-Za-z0-9-])([A-Za-z0-9-]{0,30}api[_-]?key|PRIVATE-TOKEN|Cookie):' +
'[ \\t]{0,5}[^\\n]*',
'(?<![A-Za-z0-9-])([A-Za-z0-9-]{0,30}api[_-]?key|PRIVATE-TOKEN|' +
'(?:Set-)?Cookie):[ \\t]{0,5}[^\\n]*',
'gi',
), '$1: <redacted>'],
[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')