Skip to content

[DX][RFC] Forcing to https causes a lot of troubles #27603

Closed
@Aerendir

Description

@Aerendir

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

  1. Force to https, as described here, putting this in security.yaml
security:
    access_control:
        - { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
  1. Deploy for example, to Heroku.
  2. 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:

  1. Manually adding the required $_SERVER variables:
// SF4: public/index.php
// SF 2||3: web/app.php

if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
{
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}
  1. Adding trusted proxies to framework:
framework:
    trusted_proxies:  [127.0.0.1, ::1]
  1. Adding to the documentation a note about this common error and the possible solutions

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)RFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions