Problem/Motivation
Due to https://github.com/advisories/GHSA-mrqx-rp3w-jpjp symfony/http-foundation 7.1.7 and 6.4.14 patched Request::create() to throw a BadRequestException exception on certain invalid URLs. When processing such an invalid path, PathBasedBreadcrumbBuilder now throws this new exception.
Steps to reproduce
Visit certain invalid paths such as /:123/foo - an exception will be thrown by PathBasedBreadcrumbBuilder (as can be seen by inspecting the stacktrace of one of the chained exceptions)
Proposed resolution
PathBasedBreadcrumbBuilder should instead catch the new exception and return NULL, which indicates "the path couldn't be matched" and skips this breadcrumb, as it did before the symfony/http-foundation update.
Remaining tasks
Backport/reapply to the 10.5.x and 10.4.x branches.
User interface changes
Sites will once again respond with the 404 error page when such invalid URLs are requested, as they did before the symfony/http-foundation update.
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3490710
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3490710-backport
changes, plain diff MR !10485
- 3490710-catch-potential-exception
changes, plain diff MR !10398
Comments
Comment #3
smustgrave commentedThe wording seems like maybe a regression was introduced? Think we should have test coverage for the scenario described
Comment #4
mfbComment #5
smustgrave commentedTest coverage looks good https://git.drupalcode.org/issue/drupal-3490710/-/jobs/3540197
Comment #9
catchCommitted/pushed to 11.x and cherry-picked back through to 10.3.x, thanks!
Comment #14
spokjeThis broken HEAD on 10.5.x and 10.4.x with a cheery:
Unsure why it works on 11.x with Symfony 7.2, where I would expect the deprecation throwing code would be removed, but it does.
As an added weirdness-bonus, the test fails, making the unit-test job fail on GitLab, but the specific error doesn't show up in the report. I can only find it in the raw output of the unit-test job.
But that's probably because it's a deprecation error, not an "actual" error?
Comment #15
spokjeComment #18
catchReverted from 10.5.x and 10.4.x
Comment #19
spokje_tips hat_
Comment #20
mfbSo it looks like this is specifically for the case where parse_url() returns FALSE.
I was discussing this over in https://www.drupal.org/project/drupal/issues/3489329#comment-15880688
The PHP docs for parse_url() say "This function may not give correct results for relative or invalid URLs, and the results may not even match common behavior of HTTP clients. If URLs from untrusted input need to be parsed, extra validation is required, e.g. by using filter_var() with the FILTER_VALIDATE_URL filter."
So, technically speaking, maybe Request::create() should not rely on parse_url() for parsing relative URLs, or Drupal core should not rely on Request::create() to parse relative URLs/paths.
However, so far I've only noticed parse_url() returning FALSE for "weird" relative URLs (in my case, requests made by a bot), not something that I would have expected to work. So a quick fix could be to test the relative URL with parse_url() and return NULL, before calling Request::create()
Comment #21
mfbI think this can be fixed on all branches by simply updating the symfony/http-foundation requirement to a more recent version that throws the exception, rather than triggering the deprecation? I.e. bump from 6.4.15 to at least 6.4.16?
My workaround in #20 would only be needed if there is a requirement to support older versions of symfony/http-foundation
Comment #23
mfbComment #24
mfbComment #25
catchWe need to do that anyway, makes sense to me.
Comment #28
longwavesymfony/http-foundationwas updated in #3490183: Update Composer dependencies for 10.4.0 so from here I have just committed the fix and test.Committed and pushed c6143563c31 to 10.5.x and 3116614f706 to 10.4.x. Thanks!
Comment #30
eric_a commentedSo now there's only a choice between either running an insecure 10.3 application or live with an 10.3 application having the out of memory loop issue?
What is the point of having a security supported core version if you cannot update to secure symfony dependencies?
Comment #31
eric_a commentedMy bad. The loop with the out-of-memory was mentioned in #3486972: DefaultExceptionHtmlSubscriber should not clone the request for 400/BadRequestException.
The point more or less remains though. Without this fix in 10.3.x it's a choice between secure dependencies or a pretty broken site.
Granted that out of memory seems to be more of a problem then "just" an exception.
Comment #32
catchI think we can probably backport this to 10.3.x too.
Comment #33
eric_a commentedComment #34
spokjeSeems to have broken HEAD of 11.0.x: https://git.drupalcode.org/project/drupal/-/pipelines/382966/test_report...
Comment #36
catchReverted from 11.0.x too.
Comment #37
mfbWhat's the policy for security updates of dependencies on security-only branches? Assuming it's ok and/or required to do so, the composer update could be applied on that branch
Comment #38
catch@mfb we can update, but this was quite a minor security fix (at least for us) whereas the function regressions have been quite serious, and there are multiple contexts where this error can be thrown, so I would personally prefer us to keep fixing these bugs and then only update the constraints if we really need to - individual sites can update with composer update whenever they want.
Comment #40
quietone commentedThis was applied to 10.3.x, 10.4.x, 10.5.x, 11.1.x, and 11.x. It was applied to 11.0.x, which is no longer supported, but then reverted.
Therefore restoring the fixed status.