Skip to content

Commit

Permalink
Clear auth on redirect
Browse files Browse the repository at this point in the history
Fixes #1309
  • Loading branch information
kornelski committed Nov 8, 2017
1 parent 4108c34 commit 087edaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ Request.prototype._redirect = function(res){

let headers = this.req._headers;

const shouldStripCookie = parse(url).host !== parse(this.url).host;
const changesOrigin = parse(url).host !== parse(this.url).host;

// implementation of 302 following defacto standard
if (res.statusCode == 301 || res.statusCode == 302){
// strip Content-* related fields
// in case of POST etc
headers = utils.cleanHeader(this.req._headers, shouldStripCookie);
headers = utils.cleanHeader(this.req._headers, changesOrigin);

// force GET
this.method = 'HEAD' == this.method
Expand All @@ -437,7 +437,7 @@ Request.prototype._redirect = function(res){
if (res.statusCode == 303) {
// strip Content-* related fields
// in case of POST etc
headers = utils.cleanHeader(this.req._headers, shouldStripCookie);
headers = utils.cleanHeader(this.req._headers, changesOrigin);

// force method
this.method = 'GET';
Expand Down
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ exports.parseLinks = function(str){
* @api private
*/

exports.cleanHeader = function(header, shouldStripCookie){
exports.cleanHeader = function(header, changesOrigin){
delete header['content-type'];
delete header['content-length'];
delete header['transfer-encoding'];
delete header['host'];
if (shouldStripCookie) {
// secuirty

This comment has been minimized.

Copy link
@paul-cipherlex

paul-cipherlex Nov 8, 2017

spelling in comment. s/secuity/security

Other than that, looks good. Thanks!

if (changesOrigin) {
delete header['authorization'];
delete header['cookie'];
}
return header;
Expand Down

0 comments on commit 087edaf

Please sign in to comment.