Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: thirdparty site cookie leak #73

Merged
merged 3 commits into from Jan 25, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions index.js
Expand Up @@ -34,6 +34,8 @@ function simpleGet (opts, cb) {
opts.headers['content-type'] = 'application/x-www-form-urlencoded'
}

const ohost = opts.hostname

if (body) {
if (!opts.method) opts.method = 'POST'
if (!isStream(body)) opts.headers['content-length'] = Buffer.byteLength(body)
Expand All @@ -51,6 +53,13 @@ function simpleGet (opts, cb) {
delete opts.headers.host // Discard `host` header on redirect (see #32)
res.resume() // Discard response

const rhost = url.parse(opts.url).hostname // eslint-disable-line node/no-deprecated-api
// if redirected host is different than original host then drop cookie header to prevent cookie leak in thirdparty site redirect
if (rhost !== null && rhost !== ohost) {
delete opts.headers.cookie
delete opts.headers.authorization
}

if (opts.method === 'POST' && [301, 302].includes(res.statusCode)) {
opts.method = 'GET' // On 301/302 redirect, change POST to GET (see #35)
delete opts.headers['content-length']; delete opts.headers['content-type']
Expand Down