#103129Modified "Host" header with invalid port leads to exception when creating the ServerRequestFactory->fromGlobals
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
Related issues 3
Files 2
History 1125
-
Stefan Bürk commented and changed status
NewNeeds 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 webserverUsually, 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. ? -
Gerrit Code Review pushed patch set 1 for main to change 83948 status
Needs FeedbackUnder Review <span data-processor="relativetime" data-value="2024-04-21T16:52:38+00:00" > 04/21/24, 16:52 </span> -
Gerrit Code Review pushed patch set 2 for main to change 83948 <span data-processor="relativetime" data-value="2024-04-21T16:53:55+00:00" > 04/21/24, 16:53 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 83948 <span data-processor="relativetime" data-value="2024-04-21T17:03:51+00:00" > 04/21/24, 17:03 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 83948 <span data-processor="relativetime" data-value="2024-04-21T17:20:35+00:00" > 04/21/24, 17:20 </span>
-
Gerrit Code Review pushed patch set 5 for main to change 83948 <span data-processor="relativetime" data-value="2024-04-21T17:20:49+00:00" > 04/21/24, 17:20 </span>
-
Gerrit Code Review pushed patch set 6 for main to change 83948 <span data-processor="relativetime" data-value="2024-04-21T17:21:43+00:00" > 04/21/24, 17:21 </span>
-
Stefan Bürk changed Related to #98264 <span data-processor="relativetime" data-value="2024-04-22T09:30:06+00:00" > 04/22/24, 09:30 </span>
-
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.
-
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. -
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.
-
Markus Klein changed Related to #105163 <span data-processor="relativetime" data-value="2024-10-04T09:43:30+00:00" > 10/04/24, 09:43 </span>
-
Markus Klein changed Related to #105194 <span data-processor="relativetime" data-value="2024-10-04T10:11:38+00:00" > 10/04/24, 10:11 </span>
-
Gerrit Code Review pushed patch set 6 for main to change 86416 <span data-processor="relativetime" data-value="2024-10-07T05:49:34+00:00" > 10/07/24, 05:49 </span>
-
Gerrit Code Review pushed patch set 7 for main to change 83948 <span data-processor="relativetime" data-value="2024-10-18T13:29:00+00:00" > 10/18/24, 13:29 </span>
-
Gerrit Code Review pushed patch set 7 for main to change 86416 <span data-processor="relativetime" data-value="2024-10-18T14:01:00+00:00" > 10/18/24, 14:01 </span>
-
Gerrit Code Review pushed patch set 8 for main to change 86416 <span data-processor="relativetime" data-value="2024-11-15T09:36:24+00:00" > 11/15/24, 09:36 </span>
-
Gerrit Code Review pushed patch set 9 for main to change 86416 <span data-processor="relativetime" data-value="2024-11-18T10:25:16+00:00" > 11/18/24, 10:25 </span>
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 87181 <span data-processor="relativetime" data-value="2024-11-22T09:55:19+00:00" > 11/22/24, 09:55 </span>
-
Gerrit Code Review pushed patch set 1 for 12.4 to change 87182 <span data-processor="relativetime" data-value="2024-11-22T09:55:33+00:00" > 11/22/24, 09:55 </span>
-
Markus Klein commented and changed status
Under ReviewResolved done0 %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.
-
Gerrit Code Review pushed patch set 2 for 12.4 to change 87182 status
ResolvedUnder Review <span data-processor="relativetime" data-value="2024-11-22T10:07:53+00:00" > 11/22/24, 10:07 </span> -
Markus Klein commented and changed status
Under ReviewResolved <span data-processor="relativetime" data-value="2024-11-22T12:20:08+00:00" > 11/22/24, 12:20 </span>Applied in changeset commit:4148f82e9e800f725746f43774f57592e802a1fa.
-
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2025-12-02T14:33:20+00:00" > 12/02/25, 14:33 </span>
Idea is to catch invalid argument exception in AbstractApplication->run (dev-main), and then deliver a 400 response with no content.