Description
Symfony version(s) affected: from 2.8 I think, for sure from 3.4
Description
Forcing to https
may lead to an infinite loop in some (unclear for me) circumstances.
It is something related to load balancers and trusted proxies.
How to reproduce
- Force to
https
, as described here, putting this insecurity.yaml
security:
access_control:
- { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
- Deploy for example, to Heroku.
- Access the home page and you will get an error about too many redirects.
Possible Solution
There are two possible solutions to this problem and a required docs improvement:
// SF4: public/index.php
// SF 2||3: web/app.php
if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
{
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}
framework:
trusted_proxies: [127.0.0.1, ::1]
- Adding to the documentation a note about this common error and the possible solutions
- How to Force HTTPS or HTTP for different URLs
- Maybe here, too: How to Force Routes to Always Use HTTPS or HTTP (I didn't verified if the error happens also forcing
https
using annotations)
WHAT I'M ASKING FOR
A simpler way to understand that there is a problem with the https
redirection.
Maybe a clear exception in case of excessive number of redirects that tells the developer that it should either implement solution one or solution two.
This takes me 2 days to be solved now that I migrated to SF4 and takes some more days when I implemented https
forcing using SF3.4 (I forgot about the problem, so I had to discover the solution two times, damn!).
Any opinions about this?