File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -1200,6 +1200,10 @@ async function httpRedirectFetch (fetchParams, response) {
12001200 if ( ! sameOrigin ( requestCurrentURL ( request ) , locationURL ) ) {
12011201 // https://fetch.spec.whatwg.org/#cors-non-wildcard-request-header-name
12021202 request . headersList . delete ( 'authorization' )
1203+
1204+ // "Cookie" and "Host" are forbidden request-headers, which undici doesn't implement.
1205+ request . headersList . delete ( 'cookie' )
1206+ request . headersList . delete ( 'host' )
12031207 }
12041208
12051209 // 14. If request’s body is non-null, then set request’s body to the first return
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const { test } = require ( 'tap' )
4+ const { createServer } = require ( 'http' )
5+ const { once } = require ( 'events' )
6+ const { fetch } = require ( '../..' )
7+
8+ test ( 'Cross-origin redirects clear forbidden headers' , async ( t ) => {
9+ t . plan ( 5 )
10+
11+ const server1 = createServer ( ( req , res ) => {
12+ t . equal ( req . headers . cookie , undefined )
13+ t . equal ( req . headers . authorization , undefined )
14+
15+ res . end ( 'redirected' )
16+ } ) . listen ( 0 )
17+
18+ const server2 = createServer ( ( req , res ) => {
19+ t . equal ( req . headers . authorization , 'test' )
20+ t . equal ( req . headers . cookie , 'ddd=dddd' )
21+
22+ res . writeHead ( 302 , {
23+ ...req . headers ,
24+ Location : `http://localhost:${ server1 . address ( ) . port } `
25+ } )
26+ res . end ( )
27+ } ) . listen ( 0 )
28+
29+ t . teardown ( ( ) => {
30+ server1 . close ( )
31+ server2 . close ( )
32+ } )
33+
34+ await Promise . all ( [
35+ once ( server1 , 'listening' ) ,
36+ once ( server2 , 'listening' )
37+ ] )
38+
39+ const res = await fetch ( `http://localhost:${ server2 . address ( ) . port } ` , {
40+ headers : {
41+ Authorization : 'test' ,
42+ Cookie : 'ddd=dddd'
43+ }
44+ } )
45+
46+ const text = await res . text ( )
47+ t . equal ( text , 'redirected' )
48+ } )
You can’t perform that action at this time.
0 commit comments