Skip to content

Commit 6805746

Browse files
authored
Merge pull request from GHSA-m4v8-wqvr-p9f7
Signed-off-by: Matteo Collina <[email protected]>
1 parent ee5f892 commit 6805746

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

lib/handler/redirect-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ function shouldRemoveHeader (header, removeContent, unknownOrigin) {
201201
if (removeContent && util.headerNameToString(header).startsWith('content-')) {
202202
return true
203203
}
204-
if (unknownOrigin && (header.length === 13 || header.length === 6)) {
204+
if (unknownOrigin && (header.length === 13 || header.length === 6 || header.length === 19)) {
205205
const name = util.headerNameToString(header)
206-
return name === 'authorization' || name === 'cookie'
206+
return name === 'authorization' || name === 'cookie' || name === 'proxy-authorization'
207207
}
208208
return false
209209
}

test/redirect-cross-origin-header.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict'
2+
3+
const { test } = require('node:test')
4+
const { tspl } = require('@matteo.collina/tspl')
5+
const { createServer } = require('node:http')
6+
const { once } = require('node:events')
7+
const { request } = require('..')
8+
9+
test('Cross-origin redirects clear forbidden headers', async (t) => {
10+
const { strictEqual } = tspl(t, { plan: 6 })
11+
12+
const server1 = createServer((req, res) => {
13+
strictEqual(req.headers.cookie, undefined)
14+
strictEqual(req.headers.authorization, undefined)
15+
strictEqual(req.headers['proxy-authorization'], undefined)
16+
17+
res.end('redirected')
18+
}).listen(0)
19+
20+
const server2 = createServer((req, res) => {
21+
strictEqual(req.headers.authorization, 'test')
22+
strictEqual(req.headers.cookie, 'ddd=dddd')
23+
24+
res.writeHead(302, {
25+
...req.headers,
26+
Location: `http://localhost:${server1.address().port}`
27+
})
28+
res.end()
29+
}).listen(0)
30+
31+
t.after(() => {
32+
server1.close()
33+
server2.close()
34+
})
35+
36+
await Promise.all([
37+
once(server1, 'listening'),
38+
once(server2, 'listening')
39+
])
40+
41+
const res = await request(`http://localhost:${server2.address().port}`, {
42+
maxRedirections: 1,
43+
headers: {
44+
Authorization: 'test',
45+
Cookie: 'ddd=dddd',
46+
'Proxy-Authorization': 'test'
47+
}
48+
})
49+
50+
const text = await res.body.text()
51+
strictEqual(text, 'redirected')
52+
})

0 commit comments

Comments
 (0)