File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -43,13 +43,21 @@ function simpleGet (opts, cb) {
43
43
if ( opts . json ) opts . headers . accept = 'application/json'
44
44
if ( opts . method ) opts . method = opts . method . toUpperCase ( )
45
45
46
+ const originalHost = opts . hostname // hostname before potential redirect
46
47
const protocol = opts . protocol === 'https:' ? https : http // Support http/https urls
47
48
const req = protocol . request ( opts , res => {
48
49
if ( opts . followRedirects !== false && res . statusCode >= 300 && res . statusCode < 400 && res . headers . location ) {
49
50
opts . url = res . headers . location // Follow 3xx redirects
50
51
delete opts . headers . host // Discard `host` header on redirect (see #32)
51
52
res . resume ( ) // Discard response
52
53
54
+ const redirectHost = url . parse ( opts . url ) . hostname // eslint-disable-line node/no-deprecated-api
55
+ // If redirected host is different than original host, drop headers to prevent cookie leak (#73)
56
+ if ( redirectHost !== null && redirectHost !== originalHost ) {
57
+ delete opts . headers . cookie
58
+ delete opts . headers . authorization
59
+ }
60
+
53
61
if ( opts . method === 'POST' && [ 301 , 302 ] . includes ( res . statusCode ) ) {
54
62
opts . method = 'GET' // On 301/302 redirect, change POST to GET (see #35)
55
63
delete opts . headers [ 'content-length' ] ; delete opts . headers [ 'content-type' ]
You can’t perform that action at this time.
0 commit comments