Skip to content

Commit 20d9ec5

Browse files
Merge commit from fork
* fix: trim horizontal tabs (HTAB) in multi-entry X-Forwarded-For parser RFC 7230 §3.2.3 defines OWS as *( SP / HTAB ). The multi-entry parser only recognized SP (0x20) but not HTAB (0x09), leaving tab characters preserved in returned address strings. This allowed security-control evasion via exact-string-match bypasses when the header has 2+ comma- separated values. The single-entry fast path was unaffected because it uses JavaScript's built-in .trim(), which already strips tabs. Fixes GHSA-2849-m2w7-xm8f. * test: cover HTAB (tab) OWS trimming Ref: GHSA-2849-m2w7-xm8f --------- Co-authored-by: Ulises Gascon <ulisesgascongonzalez@gmail.com>
1 parent 1b45df7 commit 20d9ec5

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function parse (header, socketAddr) {
3939

4040
for (i = end - 1; i >= 0; --i) {
4141
char = header[i]
42-
if (char === ' ') {
42+
if (char === ' ' || char === '\t') {
4343
(start === end) && (start = end = i)
4444
} else if (char === ',') {
4545
(start !== end) && result.push(header.slice(start, end))

test/test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@ test('should trim trailing OWS after a comma', function (t) {
114114
])
115115
})
116116

117+
test('should trim leading OWS with tabs (HTAB)', function (t) {
118+
t.plan(1)
119+
const req = createReq('127.0.0.1', {
120+
'x-forwarded-for': '\t10.0.0.2\t,\t10.0.0.1'
121+
})
122+
t.assert.deepStrictEqual(forwarded(req), [
123+
'127.0.0.1',
124+
'10.0.0.1',
125+
'10.0.0.2'
126+
])
127+
})
128+
129+
test('should trim trailing OWS with tabs (HTAB)', function (t) {
130+
t.plan(1)
131+
const req = createReq('127.0.0.1', {
132+
'x-forwarded-for': '10.0.0.2\t,\t10.0.0.1\t'
133+
})
134+
t.assert.deepStrictEqual(forwarded(req), [
135+
'127.0.0.1',
136+
'10.0.0.1',
137+
'10.0.0.2'
138+
])
139+
})
140+
117141
function createReq (socketAddr, headers) {
118142
return {
119143
socket: {

0 commit comments

Comments
 (0)