@@ -34,8 +34,6 @@ function simpleGet (opts, cb) {
34
34
opts . headers [ 'content-type' ] = 'application/x-www-form-urlencoded'
35
35
}
36
36
37
- const ohost = opts . hostname
38
-
39
37
if ( body ) {
40
38
if ( ! opts . method ) opts . method = 'POST'
41
39
if ( ! isStream ( body ) ) opts . headers [ 'content-length' ] = Buffer . byteLength ( body )
@@ -46,16 +44,17 @@ function simpleGet (opts, cb) {
46
44
if ( opts . json ) opts . headers . accept = 'application/json'
47
45
if ( opts . method ) opts . method = opts . method . toUpperCase ( )
48
46
47
+ const originalHost = opts . hostname // hostname before potential redirect
49
48
const protocol = opts . protocol === 'https:' ? https : http // Support http/https urls
50
49
const req = protocol . request ( opts , res => {
51
50
if ( opts . followRedirects !== false && res . statusCode >= 300 && res . statusCode < 400 && res . headers . location ) {
52
51
opts . url = res . headers . location // Follow 3xx redirects
53
52
delete opts . headers . host // Discard `host` header on redirect (see #32)
54
53
res . resume ( ) // Discard response
55
54
56
- const rhost = url . parse ( opts . url ) . hostname // eslint-disable-line node/no-deprecated-api
57
- // if redirected host is different than original host then drop cookie header to prevent cookie leak in thirdparty site redirect
58
- if ( rhost !== null && rhost !== ohost ) {
55
+ const redirectHost = url . parse ( opts . url ) . hostname // eslint-disable-line node/no-deprecated-api
56
+ // If redirected host is different than original host, drop headers to prevent cookie leak (#73)
57
+ if ( redirectHost !== null && redirectHost !== originalHost ) {
59
58
delete opts . headers . cookie
60
59
delete opts . headers . authorization
61
60
}
0 commit comments