Skip to content

Fixes manipulated location header in Hosting emulator proxy logic#3105

Merged
bkendall merged 9 commits into
masterfrom
bk-3097
Feb 4, 2021
Merged

Fixes manipulated location header in Hosting emulator proxy logic#3105
bkendall merged 9 commits into
masterfrom
bk-3097

Conversation

@bkendall

@bkendall bkendall commented Feb 3, 2021

Copy link
Copy Markdown
Contributor

Description

Fixes #3097

Node fetch attempts to make life easier, but in fact changes behavior that's defined in the spec and doesn't currently document it: https://github.com/node-fetch/node-fetch/blob/4abbfd231f4bce7dbe65e060a6323fc6917fd6d9/src/index.js#L117-L120

I've filed a bug with them: node-fetch/node-fetch#1086

For now, the best we can do is attempt to fix the location header that comes back if it's a resolved URL and that URL points us to the same origin as our original proxy request. This allows valid URLs to come back from the proxy target and only strips the origin if it's a redirect to the same origin.

Scenarios Tested

I have a manual setup where a redirect is returned. I see now that the location header is what I expect:

before:

» curl -I http://localhost:5000/start
HTTP/1.1 302 Found
x-powered-by: Express
location: http://localhost:5001/somewhereelse

after:

» curl -I http://localhost:5000/start
HTTP/1.1 302 Found
x-powered-by: Express
location: /somewhereelse

@bkendall bkendall added the cleanup: request PRs for removing the request module from the CLI label Feb 3, 2021
@google-cla google-cla Bot added the cla: yes Manual indication that this has passed CLA. label Feb 3, 2021
Comment thread src/hosting/proxy.ts
@bkendall bkendall merged commit d162aec into master Feb 4, 2021
@bkendall bkendall deleted the bk-3097 branch February 4, 2021 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Manual indication that this has passed CLA. cleanup: request PRs for removing the request module from the CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic content functions redirect in emulators to :5001 port instead of :5000

2 participants