Skip to content

fix: Update host if there's a redirection#596

Closed
abruzzihraig wants to merge 2 commits intonode-fetch:3.xfrom
abruzzihraig:master
Closed

fix: Update host if there's a redirection#596
abruzzihraig wants to merge 2 commits intonode-fetch:3.xfrom
abruzzihraig:master

Conversation

@abruzzihraig
Copy link
Copy Markdown

@abruzzihraig abruzzihraig commented Mar 28, 2019

Closes #570

@keepcosmos
Copy link
Copy Markdown

I have same issue. please merge this.

isaacs added a commit to npm/minipass-fetch that referenced this pull request Oct 20, 2019
@xxczaki xxczaki mentioned this pull request Nov 6, 2019
35 tasks
@Richienb Richienb changed the base branch from master to 3.x January 3, 2020 06:16
@Richienb Richienb requested review from bitinn and xxczaki January 3, 2020 06:16
@Richienb Richienb changed the title fix #570 (redirect): should update host if there's a redirection fix: Update host if there's a redirection Jan 3, 2020
@Richienb
Copy link
Copy Markdown
Member

Richienb commented Jan 3, 2020

We probably need to unit test this.

Copy link
Copy Markdown
Collaborator

@bitinn bitinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take: this is an edge case where users specify the Host header manually (which is forbidden on client-side fetch) and somehow expect node-fetch to update it automatically using the Location header as source (which is basically taking remote user input).

I haven't thought through the security implication here but I prefer not to go down this route. I would prefer to drop Host header if redirect happens (or just prevent users from doing this when redirect option is follow, because something clearly isn't quite right).

But the real solution here is, users should know what they are doing.

(If my analysis is wrong, please provide us with a better test case to illustrate that this issue should be handled by node-fetch.)

@bitinn
Copy link
Copy Markdown
Collaborator

bitinn commented Jan 4, 2020

There is one thing I do think could be improved though: our error message is misleading in this case, we might throw a FetchError here just for mismatching Host and Location header.

@abruzzihraig
Copy link
Copy Markdown
Author

Sorry guys, I tried to remember what case I'd had when I was dealing with this issue. I just remember it was a very popular domain, and the redirect flow was like http://google.com -> http://www.google.com -> https://www.google.com or something. But I cannot reproduce it anymore even based on fetch@2.3.0.

The fix I've made is not that safe and reliable. It was more like a patch for solving my urgent need at that moment. I didn't pay much time into the whole context to ensure the change is reasonable.

I agree with @bitinn and hope you guys can make a better decision to simply ignore this PR or improve it by other ways. Thanks.

@jimmywarting jimmywarting deleted the branch node-fetch:3.x September 4, 2021 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants