Skip to content

Commit 6e21f5e

Browse files
authored
code style
1 parent 489f743 commit 6e21f5e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ function simpleGet (opts, cb) {
3434
opts.headers['content-type'] = 'application/x-www-form-urlencoded'
3535
}
3636

37-
const ohost = opts.hostname
38-
3937
if (body) {
4038
if (!opts.method) opts.method = 'POST'
4139
if (!isStream(body)) opts.headers['content-length'] = Buffer.byteLength(body)
@@ -46,16 +44,17 @@ function simpleGet (opts, cb) {
4644
if (opts.json) opts.headers.accept = 'application/json'
4745
if (opts.method) opts.method = opts.method.toUpperCase()
4846

47+
const originalHost = opts.hostname // hostname before potential redirect
4948
const protocol = opts.protocol === 'https:' ? https : http // Support http/https urls
5049
const req = protocol.request(opts, res => {
5150
if (opts.followRedirects !== false && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
5251
opts.url = res.headers.location // Follow 3xx redirects
5352
delete opts.headers.host // Discard `host` header on redirect (see #32)
5453
res.resume() // Discard response
5554

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) {
5958
delete opts.headers.cookie
6059
delete opts.headers.authorization
6160
}

0 commit comments

Comments
 (0)