Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DX] Log potential redirect loops caused by forced HTTPS #27605

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

Merged

Conversation

colinodell
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27603
License MIT
Doc PR n/a

If the developer forgets/fails to set "trusted_proxies" properly, forcing the
https channel can cause infinite redirect loops. This change will hopefully
help them identify the problem faster.

See #27603

@carsonbot carsonbot added Status: Needs Review DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature labels Jun 14, 2018
@colinodell
Copy link
Contributor Author

I have also submitted symfony/symfony-docs#9924 to help point developers in the right direction via documentation. That PR does not document this change, it just provides a different avenue to notify the developer about the potential issue. Feel free to merge that instead of this (or merge both! 😃)

@nicolas-grekas nicolas-grekas added this to the next milestone Jun 14, 2018
@@ -47,6 +47,9 @@ public function handle(GetResponseEvent $event)
if ('https' === $channel && !$request->isSecure()) {
if (null !== $this->logger) {
$this->logger->info('Redirecting to HTTPS.');
if ('https' === $request->headers->get('X-Forwarded-Proto')) {
$this->logger->debug('Possible redirect loop - did you set "trusted_proxies" correctly?');
Copy link
Contributor

Choose a reason for hiding this comment

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

What about warn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This log message could be triggered by anybody who sends HTTP requests to the server with that header:

curl http://www.example.com -H 'X-Forwarded-Proto: https'

If the site is configured to log messages with a minimum severity of warn or higher then their logs could potentially be flooded with "false positives". Using debug() would prevent that from happening unless the site is configured to log debug messages (which I'd assume somebody might do if they had an unexpected redirect loop and were looking for clues).

That being said, I'm not strongly opposed to using a different log level if others feel that it is more appropriate.

Copy link
Member

Choose a reason for hiding this comment

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

since there is already an info level message, we could merge the new with the existing one:
$this->logger->info('Redirecting to HTTPS ("X-Forwarded-Proto" is set to "https" - did you set "trusted_proxies" correctly?).');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I've made it so that only one message will ever be logged.

@@ -47,6 +47,9 @@ public function handle(GetResponseEvent $event)
if ('https' === $channel && !$request->isSecure()) {
if (null !== $this->logger) {
$this->logger->info('Redirecting to HTTPS.');
if ('https' === $request->headers->get('X-Forwarded-Proto')) {
Copy link
Member

Choose a reason for hiding this comment

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

this could also handle rfc7239's "proto" parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an additional check for this parameter.

@colinodell colinodell force-pushed the feature/notify-potential-redirect-loop branch from 15748c7 to 7714655 Compare June 19, 2018 14:27
If the developer forgets/fails to set "trusted_proxies" properly, forcing the
https channel can cause infinite redirect loops. This change will hopefully
help them identify the problem faster.

See symfony#27603
@colinodell colinodell force-pushed the feature/notify-potential-redirect-loop branch from 7714655 to 53048ce Compare June 19, 2018 14:59
@fabpot
Copy link
Member

fabpot commented Jun 20, 2018

Thank you @colinodell.

@fabpot fabpot merged commit 53048ce into symfony:master Jun 20, 2018
fabpot added a commit that referenced this pull request Jun 20, 2018
…PS (colinodell)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[DX] Log potential redirect loops caused by forced HTTPS

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27603
| License       | MIT
| Doc PR        | n/a

If the developer forgets/fails to set "trusted_proxies" properly, forcing the
https channel can cause infinite redirect loops. This change will hopefully
help them identify the problem faster.

See #27603

Commits
-------

53048ce Log potential redirect loops caused by forced HTTPS
@colinodell colinodell deleted the feature/notify-potential-redirect-loop branch June 20, 2018 19:55
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants