Review main Merged

86416[BUGFIX] Return HTTP 400 if request is invalid

Markus Klein CR +2 V +2 Easy +29 −9 updated 11/22/24, 09:55

Commit message

The request may be an unparsable URL or might
have other defects.

Specifically, the URI class may throw an
exception if something is wrong.
Catch this exception and bail out with a
400 bad request status.

Review

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

Issues 2

Files 5

Review log 4149

Show 2024 earlier messages
  1. Markus Klein uploaded patch set 1 10/04/24, 10:22

  2. core-ci voted on patch set 1 V +1 10/04/24, 10:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67067

  3. Mathias Brodala commented on patch set 1 CR -1 10/04/24, 10:49

    AbstractApplication.php:95

    This should not be silently dropped but at least logged instead. Taking into account the original intention maybe a lower priority log level can be used instead of CRITICAL. This way the logging will not happen by default but only if configured accordingly. Also IMO this code should be reduced to an early return within "catch" instead. This avoids the additional check below which would be done on every single request whereas the "catch" only occurs in, well, exceptional cases.
  4. Andreas Kienast commented on patch set 1 10/04/24, 10:51

    AbstractApplication.php:93

    This code looks very verbose. What's wrong with ```php try { $response = $this->handle(ServerRequestFactory::fromGlobals()); } catch (\InvalidArgumentException) { $response = GeneralUtility::makeInstance(ResponseFactory::class)->createResponse(400); } ```
  5. Markus Klein commented on patch set 1 10/04/24, 11:21

    AbstractApplication.php:93 Reply

    I do not want to catch any InvalidArgumentException that may occur within ->handle(). We could add a check for the precise exception code though

    AbstractApplication.php:95 Reply

    The whole point is NOT to log this at all. Please take a look at the issue. There is absolutely no point in logging any bullsh** request that is thrown against your server. We are really fed up with this.
  6. Andreas Kienast commented on patch set 1 10/04/24, 11:24

    AbstractApplication.php:93 Reply

    Fair point
  7. Benjamin Franzke uploaded patch set 2 CR -1 V +1 10/04/24, 11:30

  8. Benjamin Franzke commented on patch set 2 10/04/24, 11:30

    AbstractApplication.php:93 Reply

    ack, but we should terminate within catch anyway. adapted.

    AbstractApplication.php:95 Reply

    yes, but you want to be able to debug this. A notice is correct IMO.
  9. core-ci voted on patch set 2 V +1 10/04/24, 11:45 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67076

  10. Mathias Brodala commented on patch set 2 10/04/24, 12:16

    AbstractApplication.php:95 Reply

    @markus.klein@typo3.org I know you are fed up but please read my comment again. I understood the issue and what you want to achieve. At the same time I did show a way to have both requirements satisifed: no logging by default with the option to enable it if necessary.
  11. Mathias Brodala voted on patch set 2 CR +1 10/04/24, 12:18

  12. Markus Klein commented on patch set 2 10/04/24, 12:25

    AbstractApplication.php:95 Reply

    Not sure, but we usually do not use log messages to debug things, especially if there is not even a stack trace. (which is the case currently) But, as always, feel free to add/ to improve the patch! (Personally, I do not need any logging at all, not even on Notice level. :-) )
  13. Mathias Brodala commented on patch set 3 CR +1 V +1 10/04/24, 12:30

    Published edit on patch set 2.
  14. Mathias Brodala commented on patch set 3 CR +1 10/04/24, 12:30

    AbstractApplication.php:95 Reply

    Nice catch/notice (heh) about the missing "exception". Added now.
  15. Mathias Brodala commented on patch set 4 CR +1 10/04/24, 12:31

    Published edit on patch set 3.
  16. Mathias Brodala commented on patch set 4 CR +1 10/04/24, 12:31

    Fixed placeholder for exception code.
  17. Markus Klein commented on patch set 4 10/04/24, 12:32

    AbstractApplication.php:95 Reply

    thx
  18. Markus Klein commented on patch set 4 10/04/24, 12:33

    AbstractApplication.php:102

    Not sure if we need both: placeholders and the raw exception
  19. Mathias Brodala commented on patch set 4 CR 0 10/04/24, 12:36

    AbstractApplication.php:102 Reply

    Yeah, likely not that useful. This is actually not really done anywhere else in TYPO3 in case the full exception is provided. Will adjust.
  20. Mathias Brodala commented on patch set 5 10/04/24, 12:40

    Published edit on patch set 4.
  21. Mathias Brodala commented on patch set 5 10/04/24, 12:41

    AbstractApplication.php:102 Reply

    Opted for keeping at least the message inline for quick lookup/message grouping without having to wade through the exception trace.
  22. Markus Klein commented on patch set 5 10/04/24, 12:44

    AbstractApplication.php:102 Reply

    Acknowledged
  23. core-ci voted on patch set 3 V +1 10/04/24, 12:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67082

  24. core-ci voted on patch set 4 V +1 10/04/24, 12:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67084

  1. Benjamin Franzke commented on patch set 5 10/04/24, 12:54

    AbstractApplication.php:95 Reply

    why do we need the entire stack trace here? code was sufficient IMO…
  2. core-ci voted on patch set 5 V +1 10/04/24, 12:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67085

  3. Markus Klein commented on patch set 5 10/04/24, 13:14

    AbstractApplication.php:95 Reply

    my POV: if we log, log as much context as possible. but really no hard feeling here.
  4. Mathias Brodala commented on patch set 5 10/04/24, 13:28

    AbstractApplication.php:95 Reply

    I agree, if we have an exception at hand, we should fully log it, just like everywhere in TYPO3. Otherwise the log entry is only half as useful. Once again: this does not affect default logging which starts at WARNING and higher. So "size" should not matter.
  5. Benjamin Franzke commented on patch set 5 CR +1 V +1 10/04/24, 14:19

    AbstractApplication.php:95 Reply

    I really hate full exceptions in logs instead of the equal information in short form (remember: code in unique in TYPO3 core) – that maekes logs unreadable, but don't care enough right now.
  6. Mathias Brodala commented on patch set 5 10/04/24, 14:21

    AbstractApplication.php:95 Reply

    Actually both make sense. Especially if you use log aggregation solutions which actually parse the exception trace. But that depends on the setup. I'm also fine with any solution, as long as we optionally log at least something.
  7. Benjamin Franzke updated the commit message in patch set 6 CR +1 V +1 10/07/24, 05:49

  8. Benjamin Franzke voted on patch set 6 CR +1 V +1 10/07/24, 05:49

  9. core-ci voted on patch set 6 V +1 10/07/24, 06:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67202

  10. Oliver Hader updated the commit message in patch set 7 CR +1 V +1 10/18/24, 14:00

  11. Oliver Hader rebased onto patch set 8 11/15/24, 09:36

  12. core-ci voted on patch set 8 V +1 11/15/24, 09:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69467

  13. Benni Mack voted on patch set 8 CR +1 V +1 11/15/24, 10:00

  14. Josef Glatz voted on patch set 8 CR +1 11/17/24, 03:53

  15. Josef Glatz commented on patch set 8 V +1 11/17/24, 04:12

    I really like this approach! Is there a important rST necessary which could be interested for setups behind reverse proxies? e.g. filtering http error from application on "reverse proxy / load balancer layer"?
  16. Benjamin Franzke commented on patch set 8 CR -1 11/18/24, 09:07

    AbstractApplication.php:102

    Not a notice, this is debug. Notice is something that *may* need action by the admin. An invalid request is really just debug.
  17. Markus Klein commented on patch set 9 CR +1 V +1 11/18/24, 10:25

    Published edit on patch set 8.
  18. Markus Klein commented on patch set 9 11/18/24, 10:25

    AbstractApplication.php:102 Reply

    Good catch. Thanks.
  19. Markus Klein commented on patch set 9 11/18/24, 10:26

    Reply

    Talked to Josef on Slack. Not necessary.
  20. core-ci voted on patch set 9 V +1 11/18/24, 10:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69582

  21. Benni Mack voted on patch set 9 CR +1 V +1 11/18/24, 13:24

  22. Josef Glatz voted on patch set 9 CR +1 V +1 11/18/24, 14:10

  23. Benjamin Franzke voted on patch set 9 CR +1 11/22/24, 09:38

  24. Benni Mack voted on patch set 9 CR +2 V +2 11/22/24, 09:55

  25. Benni Mack merged patch set 10 11/22/24, 09:55