Review main Merged

65573[BUGFIX] Use X-Forwarded-Proto header when checking for HTTPS

Thorben Nissen CR +2 V +2 Normal +163 −15 updated 03/29/25, 09:48

Commit message

TYPO3 ships with two (main) options for having TYPO3 running
behind a reverse proxy.

  $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP']

and

  $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxySSL']

The latter "reverseProxySSL" is used to tell TYPO3
which reverse proxies actually handle the SSL termination,
and ensure that only HTTPS/TLS/SSL connection are
established when the client is talking to the proxy.
The proxy / SSL terminator then builds a non SSL connection
to the app server / TYPO3.

The former "reverseProxyIp" can be used for clients
to connect via HTTP or HTTPS, so TYPO3 previously just
checked for HTTPS=on. But TYPO3 needs to know if the client
had established a secure connection, for this, the Header
X-Forwarded-Proto is available, see
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto
for more details.

This change now evaluates X-Forwarded-Proto if the
connection comes through a valid reverseProxyIp
proxy, and only in this case, because at this point
TYPO3 does not know if we have SSL or not.

In case the header is not sent, TYPO3 uses SSL evaluation
as before.

It is **essential** to evaluate X-Forwarded-Proto ONLY
when we can trust the connection to the reverseProxyIp
and otherwise never.

See also: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65550

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Benni Mack +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 3953

Show 2128 earlier messages
  1. Thorben Nissen uploaded patch set 1 09/04/20, 07:12

  2. Benni Mack commented on patch set 1 09/04/20, 07:21

    Hey Thorben, nice one. could you also update the NormalizedParams class to reflect this change?
  3. TYPO3com voted on patch set 1 V +1 09/04/20, 07:24 Completed build in 11m 28s on Fri, 4 Sep, 07:24 AM Test Summary: 73200 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5207

  4. Thorben Nissen uploaded patch set 2 09/04/20, 07:41

  5. Thorben Nissen commented on patch set 2 09/04/20, 07:42

    Didn't know about NormalizedParams. Updated that as well.
  6. TYPO3com voted on patch set 2 V -1 09/04/20, 07:53 Completed build in 11m 44s on Fri, 4 Sep, 07:53 AM Test Summary: 12 of 73685 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5209

  7. Thorben Nissen uploaded patch set 3 09/04/20, 08:52

  8. TYPO3com voted on patch set 3 V +1 09/04/20, 09:04 Completed build in 11m 33s on Fri, 4 Sep, 09:04 AM Test Summary: 73212 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5217

  9. Jörg Bösche voted on patch set 3 CR +1 09/07/20, 08:09

  10. Benni Mack uploaded patch set 4 09/27/21, 10:01

  11. core-ci voted on patch set 4 V +1 09/27/21, 10:18 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/17220

  12. Benni Mack voted on patch set 4 V +1 CR +1 09/27/21, 11:00

  13. Benjamin Franzke commented on patch set 4 CR -1 09/27/21, 12:04

    What's your usecase? Why would you use and configure reverseProxySSL and then allow HTTP on that proxy? Are there any ssl-terminiation proxies out there that are configured by default to allow HTTP and actually proxy HTTP connections to the backend instead of sending rewrites transparently? I mean, the ones I know don't do that, and if I manually configure a SSL termination proxy via nginx, I use a http->https redirect directly in nginx, and wouldn't even think of proxying non-https to the backend. (btw we fixed HTTPS to HTTPthat to work properly in TYPO3 >=10.4.17 – see https://review.typo3.org/c/Packages/TYPO3.CMS/+/66613 Therefore I think it's not a TYPO3 BUG, but actually a bug in the HTTPS termination Proxy. Currently, reverseProxySSL = '*' (or ip addres) assumes the following, and therefore I wouldn't classify as TYPO3 bug: "All my proxies will deliver HTTPS, I guarantee!" See documentation: '''*'' or list of IP addresses of proxies that use SSL (https) for the connection to the client, but an unencrypted connection (http) to the server. We would need to mention that X-Forwarded-Proto is respected and that the client connection therefore might be treated as HTTP if the proxy doesn't limit to HTTPS. But then we're reaching the fact that the non-standard header X-Forwarded-Proto becomes TYPO3-API, and I vote against that, given that there is a standard header (Forwarded) available in the meantime: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/ I don't wanna say that this patch is entirely wrong (although I still wonder which SSL termination proxies pass http to the backend), but it seems like it currently negates the effect of `reverseProxySSL` and would at least require documentation to be adapted (DefaultConfigurationDescription.yaml) I'd love to see this as a master-only FEATURE patch respecting the standardized "Forwarded" header (which will be a broader topic).
  14. Benni Mack commented on patch set 4 09/27/21, 12:59

    Reply

    Hey bnf, yes. One of my use-cases was/is: * TYPO3 is on port 80 (apache) * nginx HA does SSL termination * TYPO3 on apache is configured to deal with SSL (even though the https=on is not set) In my case, the hosting provider was not able to configure the SSL termination properly, but instead sent just HTTP_FORWARDED_FOR and that's it. In addition, the apache did not have HTTPS=on), so I had/have workarounds in my AdditionalConfiguration to figure this out. Usual TLS endpoints in my cases: nginx, HA proxy or F5 LB, or some custom chinese hosting provider solutions (non-standard). In any case, I see your point (also researched the Forwarded header), and I agree, let's have this as feature for master-only. "Forwarded" header is unfortunately 0% used in ALL of my cases. Most of the time, I get a X_FORWARDED_FOR or X_FORWARDED_PROTO information.
  15. Benni Mack voted on patch set 4 V 0 CR 0 09/27/21, 12:59

  16. Benjamin Franzke commented on patch set 4 09/27/21, 14:50

    Reply

    > In addition, the apache did not have HTTPS=on), so I had/have workarounds in my AdditionalConfiguration to figure this out. It's actually correct that the apache hasn't HTTPS=on if it runs on port 80. But that usecase used to be broken (requiring trustedHostsPattern) for me as well, but should be fixed with https://review.typo3.org/c/Packages/TYPO3.CMS/+/66613 (TYPO3 >=10.4.17).
  17. Benni Mack wrote 09/27/21, 17:49

    Removed reviewer Benni Mack.
  18. Benni Mack updated the commit message in patch set 5 11/18/21, 10:39

  19. core-ci voted on patch set 5 V +1 11/18/21, 10:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/19450

  20. Benni Mack wrote 11/29/21, 10:16

    Change destination moved from master to main
  21. Benni Mack updated the commit message in patch set 6 11/29/21, 14:08

  22. core-ci voted on patch set 6 V +1 11/29/21, 17:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/20106

  23. Jörg Bösche voted on patch set 6 CR +1 04/18/23, 07:30

  24. Thorben Nissen voted on patch set 6 CR +1 04/18/23, 07:49

  25. Stefan Bürk commented on patch set 6 04/24/23, 15:55

    Reply

    Mh. We are using this in .htacces (or a apache vhost equialent) ``` # Let apache know we're behind a SSL reverse proxy SetEnvIf X-Forwarded-Proto "https" HTTPS=on ``` on apache webservers behond loadbalancers/proxies (haproxy) etc, which recommends or provide as example for the ssl termination to inform the webserver with `HTTP_FORWARDED_FOR_PROTO or configured by 3rd party and we do not have access to it. From my experience, loadbalancers shares this header for this information mostly. Working for years now and not only with TYPO3. I guess, something similiar should be doable with ngnix, but not sure. Benjamin linked a one suggestion for a new "way". However, it says "may be". THe same documentation has this: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto where it states: > The X-Forwarded-Proto (XFP) header is a de-facto standard header for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer. From that, I would disagree here with Benjamin. There is no single official way, both are generic valid. The latter one is simple the de-facto default used in the industrie and products out there for long years. Many major applications (PHP) supports the detection based on the `X-*` headers, albeit never seen a implemetation yet with the pure `FORWARD: *` combined header. I would say, supporting the long-standing defacto standard is okay to support. In the end, we should evaluate the new header and the real usage/support - and maybe add it additionally in v13 or at a later point. Guess, this gets quite tricky to really do a chain/detection with taking all into account - which should be done. We cannot declare `X-FORWARED-*` as "unofficial" here. I think, that Benjamin is right with the point, if we introduces this it should be mentioned as it alters the behaviour - albeit not sure about the real outcome, if it would really be that bad.
  26. Benni Mack rebased onto patch set 7 CR +1 V +1 07/07/23, 13:09

  27. core-ci voted on patch set 7 V +1 07/07/23, 13:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43910

  28. Oliver Klee commented on patch set 7 07/15/23, 11:24

    How should we continue here?
  1. Simon Schaufelberger rebased onto patch set 8 V +1 11/21/23, 19:11

  2. core-ci voted on patch set 8 V +1 11/21/23, 19:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49291

  3. Simon Schaufelberger rebased onto patch set 9 V +1 06/19/24, 20:51

  4. core-ci voted on patch set 9 V +1 06/19/24, 20:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59871

  5. Benni Mack commented on patch set 9 06/25/24, 09:02

    I suggest to support both https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded and X-Forwarded-For (and X-Forwarded-Proto). "Forwarded" I would say that this is then a new feature actually (with a RST)
  6. Thorben Nissen commented on patch set 9 06/25/24, 09:26

    Reply

    @benni@typo3.org Agreed. Keep the new "Forward" header out of this change and implement it as a new feature in the master branch.
  7. Oliver Klee wrote 08/25/24, 10:11

    Removed cc Oliver Klee.
  8. Mathias Brodala updated the commit message in patch set 10 V +1 11/20/24, 13:27

  9. core-ci voted on patch set 10 V -1 11/20/24, 13:33 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69794

  10. Mathias Brodala rebased onto patch set 11 V -1 11/20/24, 13:37

  11. core-ci voted on patch set 11 V +1 11/20/24, 13:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69795

  12. Simon Schaufelberger uploaded patch set 12 V +1 12/16/24, 12:07

  13. core-ci voted on patch set 12 V +1 12/16/24, 12:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71185

  14. Benni Mack commented on patch set 12 03/22/25, 22:07

    From our latest discussions in January between bnf and myself, this is how we are going to proceed: * When reverseProxySSL requirements are met, TYPO3 assumes a HTTPS connection between client and proxy, and a HTTP connection via proxy and application server * If this is NOT the case, but (only) reverseProxy requirements are met, we evaluate "X-Forwarded-Proto" now to understand if the client connection to the proxy was done via HTTPS or HTTP. I will update the patch, make it ready for v13 and main, and also add a Important.rst
  15. Benni Mack uploaded patch set 13 V +1 03/23/25, 23:26

  16. core-ci voted on patch set 13 V +1 03/23/25, 23:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76105

  17. Benjamin Franzke commented on patch set 13 03/24/25, 08:16

    Reply

    Ack, looks good to me in general!
    yes
    I'd skip this for the sake of complexity in a backport… And to already mention that, I'd proably also skip multi values, see https://github.com/reactor/reactor-netty/issues/976 for an example. We'd otherwise need to reuse or recreate an config option like https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/Configuration/Typo3ConfVars/SYS.html#reverseproxyheadermultivalue
    You mean by checking webserver HTTPS server param? Then yes… Otherwise I'm not sure what classified as a guess.

    NormalizedParams.php:627

    If we need this condition here, it would be needed in the previous `if(` as well? I guess this is not really needed, but here to be safe(?)
  18. Benni Mack uploaded patch set 14 V +1 03/24/25, 10:44

  19. Benni Mack commented on patch set 14 03/24/25, 10:44

    Reply

    Done

    Reply

    Done

    Reply

    Done

    Reply

    Done

    NormalizedParams.php:627 Reply

    Done
  20. Benni Mack voted on patch set 14 CR +1 V +1 03/24/25, 10:44

  21. Benjamin Franzke voted on patch set 14 CR +1 03/24/25, 10:47

  22. core-ci voted on patch set 14 V +1 03/24/25, 10:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76138

  23. Benjamin Franzke commented on patch set 14 CR +2 V +2 03/24/25, 11:53

    Tested via following nginx config ``` location / { proxy_redirect off; proxy_set_header X-Forwarded-Host foobar.localhost; proxy_set_header X-Forwarded-Proto https; proxy_pass http://t3core.local; } ```
  24. Benjamin Franzke merged patch set 15 03/24/25, 12:03

  25. Lina Wolf commented on patch set 15 03/29/25, 09:48

    I need help to document this, as I dont really understand what is the change and have never used the feature. See open issue: https://github.com/TYPO3-Documentation/Changelog-To-Doc/issues/1214