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

Add Forwarded headers to the fetch request. #382

Merged
merged 2 commits into from
Jan 17, 2020

Conversation

twifkak
Copy link
Member

@twifkak twifkak commented Jan 17, 2020

To be cautious re: privacy/security, specify only host. Note that this
changes behavior for anybody who was previously including "Forwarded" or
"X-Forwarded-Host" in their ForwardedRequestHeaders in the config.

Fixes #260.

To be cautious re: privacy/security, specify only host. Note that this
changes behavior for anybody who was previously including "Forwarded" or
"X-Forwarded-Host" in their ForwardedRequestHeaders in the config.
@twifkak twifkak requested a review from banaag January 17, 2020 00:57
@@ -183,6 +183,8 @@ func (this *SignerSuite) TestSimple() {
this.Assert().Equal(fakePath, this.lastRequest.URL.String())
this.Assert().Equal(userAgent, this.lastRequest.Header.Get("User-Agent"))
this.Assert().Equal("1.1 amppkg", this.lastRequest.Header.Get("Via"))
this.Assert().Equal(`host="example.com"`, this.lastRequest.Header.Get("Forwarded"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a test that has other parameters apart from host?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are no other parameters in the prod code:

req.Header.Set("Forwarded", `host=` + quotedHost)

I think the only thing I didn't add a test for is the concatenation if the upstream request has an XFH header:

if oldXFH := serveHTTPReq.Header.Get("X-Forwarded-Host"); oldXFH != "" {
xfh = oldXFH + "," + xfh
}

Is that what you want me to add a test for?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can add a test for that, too if you'd like. I was more looking at the comment:
// TODO(twifkak): Extract host from upstream Forwarded header
// and concatenate. (Do not include any other parameters, as
// they may lead to over-signing.)
If you can add a test where the over-signing doesn't happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, my mistake. Good idea. Done, PTAL.

@twifkak twifkak merged commit b4be29b into ampproject:master Jan 17, 2020
@twifkak twifkak deleted the forwarded branch January 17, 2020 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants