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