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

Don't assume port 0 for X-Forwarded-Port #32096

Merged
merged 4 commits into from Jul 8, 2019
Merged

Don't assume port 0 for X-Forwarded-Port #32096

merged 4 commits into from Jul 8, 2019

Conversation

alexbowers
Copy link
Contributor

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? none added
Fixed tickets
License MIT
Doc PR -

If you use X-Forwarded-Host but don't provide X-Forwarded-Port, it will default to 0.0.0.0: which then assumes port 0 instead of following its default assumption based on the scheme.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jun 19, 2019
@nicolas-grekas
Copy link
Member

Could you please add a test case?

@alexbowers
Copy link
Contributor Author

@nicolas-grekas I've added a test for this.

@alexbowers
Copy link
Contributor Author

Hmm, strange, its failing on the tests. But passes locally. I'll take a look at that this evening.

@alexbowers
Copy link
Contributor Author

I'm a little confused, it is failing on php 5.5, but is fine on php 7.0+. Nothing I changed should affect 5.5, any ideas?

@xabbuh
Copy link
Member

xabbuh commented Jul 4, 2019

@alexbowers PHP changed how substr() behaved when the start parameter is the same as the length of the string (see also https://www.php.net/manual/en/function.substr.php and https://3v4l.org/tfZgp).

@alexbowers
Copy link
Contributor Author

Ah, thank you @xabbuh

@alexbowers
Copy link
Contributor Author

Hmm, can AppVeyor be re-ran?

I can't see any cause for it failing.

$request = Request::create('/');
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('X-Forwarded-Host', 'test.example.com');
$request->headers->set('X-Forwarded-Port', null);
Copy link
Member

Choose a reason for hiding this comment

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

HeaderBag::set does not accept null. Maybe you meant to use an empty string.

Copy link
Member

Choose a reason for hiding this comment

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

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

Thank you @alexbowers.

@fabpot fabpot merged commit adcdd93 into symfony:3.4 Jul 8, 2019
fabpot added a commit that referenced this pull request Jul 8, 2019
This PR was merged into the 3.4 branch.

Discussion
----------

Don't assume port 0 for X-Forwarded-Port

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | none added
| Fixed tickets |
| License       | MIT
| Doc PR        | -

If you use X-Forwarded-Host but don't provide X-Forwarded-Port, it will default to `0.0.0.0:` which then assumes port `0` instead of following its default assumption based on the scheme.

Commits
-------

adcdd93 PHP 5 compat
6c49a0c Add test case
c266d6c Update Request.php
23db9be Don't assume port 0 for X-Forwarded-Port
@alexbowers alexbowers deleted the patch-2 branch July 8, 2019 23:01
@alexbowers
Copy link
Contributor Author

@fabpot any idea when the next release will be?

This was referenced Jul 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants