Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.#26973

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@kmadejski
Copy link
Contributor

@kmadejskikmadejski commentedApr 18, 2018
edited
Loading

QA
Branch?2.7 and up
Bug fix?improvement
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets---
LicenseMIT
Doc PR---

SubRequest used inInlineFragmentRendered explicitly sets$server['REMOTE_ADDR'] to127.0.0.1. Therefore, it's required to configure127.0.0.1 address in TRUSTED_PROXIES environment variable. Without that,Request::isFromTrustedProxy() will return false.
The current behavior might be a little bit problematic, for instance, in case where images are rendered through subrequests. These might end-up with an incorrect schema in URL (http instead ofhttps).

adamwojs and andrerom reacted with thumbs up emoji
Copy link

@andreromandrerom left a comment
edited
Loading

Choose a reason for hiding this comment

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

👍 Seems to be same logic as inHttpCache::forward()

@nicolas-grekas
Copy link
Member

Can you add a test case please?

@kmadejski
Copy link
ContributorAuthor

@nicolas-grekas sure, added in3b3d590

@nicolas-grekasnicolas-grekas added this to the2.7 milestoneApr 18, 2018
@stof
Copy link
Member

I see a big issue with this change: the local IP will stay trusted even after the end of handling this sub-request

@kmadejski
Copy link
ContributorAuthor

kmadejski commentedApr 18, 2018
edited
Loading

@stof you are right, local IP will be trusted for all subrequest within the master request, but I don't see any problem regarding that. Could you please explain or describe some use-case where it might be an issue?

@nicolas-grekas
Copy link
Member

describe some use-case where it might be an issue

instead of trying to answer this question, would it be possible to restore the list to the previous state?

@kmadejski
Copy link
ContributorAuthor

kmadejski commentedApr 20, 2018
edited
Loading

@nicolas-grekas probably yes, but I think that it might be tricky.

At first, it would be necessary to change this line:https://github.com/kmadejski/symfony/blob/3b3d5903109feadbdf4b40fb9f11929cdcc617ac/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php#L79 and storeResponse in some local variable, remove previously added local IP address from trusted proxies and finally returnResponse.

Secondly, we would have to set some flag because127.0.0.1 might have been intentionally set inTRUSTED_PROXIES and we need to know whether it should be removed after controller action execution or not.

Of course, if you think that it's a good idea then I can try to do the change as described.
However, correct me if I'm wrong, but it seems that127.0.0.1 isalways in trusted proxies when SymfonyHttpCache is enabled, right? (thanks to this piece of code:https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php#L479-%23L483). For what reason it is considered as an issue when not using Symfony proxy?

@andrerom
Copy link

andrerom commentedApr 20, 2018
edited
Loading

For what reason it is considered as an issue here?

When not using Symfony proxy (so Varnish, Fastly, Nginx cache, ..)

naming ;)

kmadejski reacted with thumbs up emoji

@kmadejski
Copy link
ContributorAuthor

@nicolas-grekas I see that you've changed the status of this PR, should I assume that you prefer the way of trying to restore the list of trusted proxies back to the previous state?

@nicolas-grekas
Copy link
Member

The best would be to not alter the global state at all.
Would it make sense to set the remote address to the first trusted proxy instead of 127.0.0.1 when there is one?

@andrerom
Copy link

andrerom commentedApr 29, 2018
edited
Loading

The best would be to not alter the global state at all.

true.

Would it make sense to set the remote address to the first trusted proxy instead of 127.0.0.1 when there is one?

Alternatively, could we skip setting it? Tried to check blame a few rounds back for why ip is set to localhost in the first place, but seems to have been added when logic was moved in#6459. So not sure why it's done like that, but back then localhost seems to have been considered trusted:https://github.com/symfony/symfony/pull/6459/files#diff-5a6abcbb3081371c8f5e3b9434c1ec18R87

@kmadejski
Copy link
ContributorAuthor

Would it make sense to set the remote address to the first trusted proxy instead of 127.0.0.1 when there is one?

@nicolas-grekas I did as you propose and it seems to be a pretty good solution which solves our issue. See changes in434a6a1.

@kmadejskikmadejski changed the title[HttpKernel] Explicitly set 127.0.0.1 as a trusted proxy[HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.May 14, 2018

$server['REMOTE_ADDR'] ='127.0.0.1';
$trustedProxies = Request::getTrustedProxies();
$server['REMOTE_ADDR'] =isset($trustedProxies[0]) ?$trustedProxies[0] :'127.0.0.1';
Copy link

@andreromandreromMay 14, 2018
edited
Loading

Choose a reason for hiding this comment

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

Should this rather pick the last/closest one?(unsure if it makes a difference tough)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure if there is any significant difference,@nicolas-grekas what do you think?

Choose a reason for hiding this comment

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

just to be bullet proof:
$trustedProxies ? reset($trustedProxies) : '127.0.0.1';
then the first LGTM

Copy link
ContributorAuthor

@kmadejskikmadejskiMay 15, 2018
edited
Loading

Choose a reason for hiding this comment

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

@kmadejskikmadejskiforce-pushed theinline_rendered_trusted_proxy branch from434a6a1 to954c024CompareMay 15, 2018 10:34
@kmadejski
Copy link
ContributorAuthor

@nicolas-grekas JFYI: I've pushed again last commit with force to restart AppVeyor build which has been failed for the unknown reason previously.

@fabpotfabpot changed the base branch from2.7 to2.8May 27, 2018 07:43
@fabpotfabpotforce-pushed theinline_rendered_trusted_proxy branch from4fb6e03 to18f55feCompareMay 27, 2018 07:44
@fabpot
Copy link
Member

Thank you@kmadejski.

@fabpotfabpot merged commit18f55fe intosymfony:2.8May 27, 2018
fabpot added a commit that referenced this pull requestMay 27, 2018
…ineFragmentRenderer. (kmadejski)This PR was squashed before being merged into the 2.8 branch (closes#26973).Discussion----------[HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.| Q             | A| ------------- | ---| Branch?       | 2.7 and up| Bug fix?      | improvement| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | ---| License       | MIT| Doc PR        | ---SubRequest used in `InlineFragmentRendered` explicitly sets `$server['REMOTE_ADDR']` to `127.0.0.1`. Therefore, it's required to configure `127.0.0.1` address in TRUSTED_PROXIES environment variable. Without that, `Request::isFromTrustedProxy()` will return false.The current behavior might be a little bit problematic, for instance, in case where images are rendered through subrequests. These might end-up with an incorrect schema in URL (`http` instead of `https`).Commits-------18f55fe [HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.
This was referencedJun 25, 2018
@cybernet
Copy link
Contributor

1.1.1.1 is actually a valid IP. is that a good ideea ?

@andrerom
Copy link

@cybernet that is the test code, or are you talking about something else?

dmaicher reacted with thumbs up emoji

@artursvonda
Copy link
Contributor

Came across issue with this fix. We specify range (xxx.xxx.xxx.xxx/8) for trusted IPs which cause this solution to fail. Might not be the best practice, but it should not cause the request to fail.

@kmadejski
Copy link
ContributorAuthor

@artursvonda it seems that you are right. As a workaround, for now, you can simply set127.0.0.1 as your first trusted proxy and everything should be fine.

@nicolas-grekas I think that dealing with getting the first valid IP within given CIDR is too much forInlineFragmentRendered, therefore I would like to propose to fix it by setting fallback to127.0.0.1 in case of first trusted proxy defined in CIDR notation. WDYT about something like:

$trustedProxies = Request::getTrustedProxies();$firstTrustedProxy = reset($trustedProxies);$server['REMOTE_ADDR'] = $firstTrustedProxy && false === strpos($firstTrustedProxy, '/') ? $firstTrustedProxy : '127.0.0.1';

If you agree then I will create a new PR with the proposed change.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@andreromandreromandrerom approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

8 participants

@kmadejski@nicolas-grekas@stof@andrerom@fabpot@cybernet@artursvonda@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp