Issue Bug Closed

#103129Modified "Host" header with invalid port leads to exception when creating the ServerRequestFactory->fromGlobals

Johannes Schlier 02/15/24, 11:56 updated 12/02/25, 14:33

Description

When a request is passed to TYPO3 that has an invalid port within the “Host” header (e. g. a non-numeric port “aaa” or too many numerals “123123123”) TYPO3 pretty quickly runs into an error and returns an exception, including an HTTP 500 error.
In my opinion it would be preferable to silently ignore those invalid settings and either continue the request normally, or at least return a clean error (400 – Bad Request).

The attached screenshots are the complete stack trace of such a request.
This was reproduced with TYPO3 12.4.10 and 12.4.11.

Reviews 4

Files 2

History 1125

  1. Benni Mack commented <span data-processor="relativetime" data-value="2024-02-24T01:03:25+00:00" > 02/24/24, 01:03 </span>

    Idea is to catch invalid argument exception in AbstractApplication->run (dev-main), and then deliver a 400 response with no content.

  2. Stefan Bürk commented and changed status New Needs Feedback assigned to Stefan Bürk <span data-processor="relativetime" data-value="2024-04-21T01:16:29+00:00" > 04/21/24, 01:16 </span>

    How did you managed to get this down to TYPO3 (or a PHP application). I cannot reproduce
    this in anyway with differnt browsers or curl (cli) directly. neither with direct local
    LAMP setups nor ddev (like it seems you are using) – neighter with APACHE2 or NGNIX ?!

    Literally, a invalid port part in a URI should be handled

    1) by the client
    2) by the webserver

    Usually, the webserver could not be reached with a invalid port as it should not be
    listening on that port. So even if the client does not handle it, it should be handled
    on the webserver level. If a Webserver catches this, maybe because of the `https` protocol
    in the uri IT still must decline the request because of the invalid port part – or remove
    it when passing further down (stripping it from request uri).

    So I’m with you – it should be corrected or a 400 Bad Request thrown, but that is not the
    task of the PHP application. There is something badly wrong before the application ever
    should be reached with such a port.

    Silenty handling it on the TYPO3 side would only hide the “server configuration” issue.

    I’m really interessted how you could pass such a invalid uri down to TYPO3.

    Beside that, I’m with benni that we can add a 400 Bad Request for that case in a early
    state, but silently passing it down would open for a lot of other issues anyway. Will
    have a look the next day for a implementation.

    Can you provide more information how you could triggered that at all ? Operating System,
    browser, ddev config etc. ?

  3. Gerrit Code Review pushed patch set 1 for main to change 83948 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2024-04-21T16:52:38+00:00" > 04/21/24, 16:52 </span>

  4. S P commented <span data-processor="relativetime" data-value="2024-04-23T05:14:18+00:00" > 04/23/24, 05:14 </span>

    @stefan.buerk PHP also provides a dedicated built-in webserver. Start it with “php -S”. Then your PHP code must handle these cases.

  5. Stefan Bürk commented <span data-processor="relativetime" data-value="2024-04-23T23:20:01+00:00" > 04/23/24, 23:20 </span>

    Stefan P wrote in #note-10:
    > @stefan.buerk PHP also provides a dedicated built-in webserver. Start it with “php -S”. Then your PHP code must handle these cases.

    Sidenote: PHP -S is not an official supported webserver nor a production ready webserver. See https://www.php.net/manual/en/features.commandline.webserver.php

    > Warning: This web server is designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

    Even with that information – php build-in webserver won’t start with such an invalid port, and I still could not find a way or client to “reach” port 443 or 80 or any other valid port where a webserver is listening) and having a manipulated header with a wrong port in it. I search for a way to create such a malformed request.

    The related issue was about a invalid HTTP method – which can be done, for example using curl. But for an invalid port ?

    I created a change – but detected that another (WIP) change from 2022 is hanging around with a literlly better approach.
    Reading through it, sub-requests are mentioned which make literally sense to mitigate issues there also. I pinged the
    author and core mergers discussion it back then, and we will see how to proceed here. I already linked the other issue
    and with that the other change.

  6. Benni Mack commented <span data-processor="relativetime" data-value="2024-05-21T14:44:09+00:00" > 05/21/24, 14:44 </span>

    Stefan (Buerk),

    tbh, I have seen this issue in production AND with “the recommended local dev environment for TYPO3” — DDEV, with unmodified changes (nginx). Here is an example:

    curl \
     --compressed \
     -H "Accept: */*" \
     -H "Accept-Encoding: gzip" \
     -H "Content-Length: " \
     -H "Content-Type: " \
     -H "Host: mysite.ddev.site:benni" \
     -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36" \
     "https://mysite.ddev.site/?ttrp672686=ttrp151800"

    I even tried some domains I will not mention in this document. I guess this is related to the default nginx configuration that has been documented for decades.

  7. Markus Klein commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2024-11-22T10:00:09+00:00" > 11/22/24, 10:00 </span>

    Applied in changeset commit:d21846771aa9c8286b5de2e17c4b76637142a2fa.

  8. Gerrit Code Review pushed patch set 2 for 12.4 to change 87182 status Resolved Under Review <span data-processor="relativetime" data-value="2024-11-22T10:07:53+00:00" > 11/22/24, 10:07 </span>

  9. Markus Klein commented and changed status Under Review Resolved <span data-processor="relativetime" data-value="2024-11-22T12:20:08+00:00" > 11/22/24, 12:20 </span>

    Applied in changeset commit:4148f82e9e800f725746f43774f57592e802a1fa.