Problem/Motivation
symfony/http-foundation released a security update so we updated our Drupal 10.3 site to version 6.4.14 from 6.4.12. Here is the diff.
We noticed that after doing that the site worked but the Views UI page /admin/structure/views was not loading and this error appeared in watchdog:
Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Invalid URI: A URI must not start nor end with ASCII control characters or spaces. in Symfony\Component\HttpKernel\HttpKernel->handle() (line 83 of /var/www/vendor/symfony/http-kernel/HttpKernel.php).
Turns out a trailing space in one of our view's paths caused the above error. That error was a new exception that was added to symfony/http-foundation. So I think Views UI potentially should be looking for bad characters and fail more gracefully.
I am not sure if this affects Drupal 11 yet but will try that next. Affects Drupal 11 as well.
Steps to reproduce
1. Create a view and add a trailing space to the path.
2. Update to latest version of symfony/http-foundation if you have not.
3. Try to load /admin/structure/views or that view.
Proposed resolution
TBD
Remaining tasks
- Test against Drupal 11. - Drupal 11 with version 7.1.7 of symfony/http-foundation.
- Figure out how to handle such an exception in Views UI.
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #46 | 3486195-46.patch | 2.4 KB | ericpoir |
| #13 | Selection_403.png | 11.31 KB | sivaji_ganesh_jojodae |
Issue fork drupal-3486195
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:
- 3486195-an-update-to
changes, plain diff MR !10138
- 3486195-10.5.x
changes, plain diff MR !10140
Comments
Comment #2
dmundraConfirmed this also happens on Drupal 11 with version 7.1.7 of symfony/http-foundation.
Comment #3
dmundraComment #4
dmundraComment #5
dmundraComment #6
emptyvoid commentedwas this included in the Drupal 10.3.7 release because now all of my views and search API displays are borked throwing this error.
Comment #7
catchBumping to critical.
Comment #8
sivaji_ganesh_jojodae commentedFacing the same issue with the views admin page. Downgrading symfony/http-foundation to 6.4.12 makes the error go away. Not sure what will be the reliable fix for the issue.
Comment #9
alexpottWe already trim the path on updating the path - see
\Drupal\views\Plugin\views\display\PathPluginBase::validateOptionsForm()- so it'd be interesting to know how the space got into the path in the first place. Could people confirm if these has occurred on sites that have been migrated from Drupal 7 or do the views use a different plugin that provides a path?Comment #10
longwaveIf you are affected by this issue, are you able to provide a config export of the view?
Comment #11
alexpottI've tried to recreate this bug on Drupal 11. Here are the steps I've followed:
What I am missing?
Comment #12
longwave.
Comment #13
sivaji_ganesh_jojodae commentedOne of the views has the URL ending with a space. I used ctrl+F on pattern "[space])" to find the occurrence.
See the screenshot below,
Seems like it was configured incorrectly in the first place.
Google search says "No, a URL cannot end with a space". Could be a loose input validation of views?
Comment #14
alexpottImplemented @longwave's suggestion. I guess we could use a test.
Comment #15
alexpottNote that the router entry for a view (even a REST view with a space on the end is fine because this is fixed in \Symfony\Component\Routing\Route::setPath()
Comment #17
longwaveExtended the existing XssTest to use a view with a path containing a space, as well as the listing page the view edit page also has the same bug which the test found for me.
Comment #18
alexpottThe test is not going to fail until we update Symfony but running locally I can confirm it fails as expected.
Comment #21
catchCommitted/pushed to 11.x and cherry-picked to 11.1.x, thanks!
This doesn't cherry-pick cleanly to 11.0.x or 10.x but I think we might want a backport?
Comment #23
longwaveWe cleaned up unused variables in 11 but didn't backport that to 10.
Comment #28
catchThanks new branch looks good - went ahead and committed that to 11.0.x and cherry-picked back through to 10.3.x, thanks!
Comment #31
dmundraThank you @longwave, @catch, and @alexpott for fixing it so quickly.
Comment #33
wim leersWow, what an edge case! 😄
Comment #34
maxilein commentedI am still getting this on the home page which is configured with: /node
No blanks before or after.
D10.3.8
The /node only contains blocks configured via the block layout.
None of them has a path.
but all the blocks names are None.
Could that be related?
What do I need to look for?
Could we add a warning to the log IF the new patch finds an invalid character in one of the paths so one can identify the problem any better.
Comment #35
longwave@maxilein this is likely slightly a different problem, please open a new issue with a full stack trace of the error, and if you think it is related to a view then a YAML export of the view would help too.
Comment #36
maxilein commentedThank you longwave. I tracked it down to a very similar issue with blanks in parameters. I mention this here in case it helps anybody else. it was hard to track down for me.If your view uses a viewfield with blanks in calling parameters D10.3.8 seems to handle it differently than before. This patch made my Frontpage with its views come backSorry please ignore. I made a mistake.
Comment #37
maxilein commentedComment #38
alfthecat commentedI have this issue after upgrading to 10.3.9, I don't see any spaces in my views URLs on the main views admin page.
Comment #39
alfthecat commentedAfter the update one particular views node display is no longer rendering and seems to be the cause of the client error. It uses a contextual filter "content id from URL" which in turn uses a relationship. There is no page display in the view.
There are no spaces in the URL of the node.
Comment #40
maxilein commentedI also had this problem on blocks.
My viewfields were all blocks.
I created URLS using twig and they only had trailing spaces.
See this issue: https://www.drupal.org/project/viewfield/issues/3487798
Comment #41
alfthecat commentedWith appreciation for the work on this, I've just tested this by upgrading to Drupal 10.3.x-dev from November 21st but the problem still persists.
To re-iterate, my case does not involve a space in a URL, it is triggered by views block displays that use a contextual filter on URL (raw value/content id, etc).
The views involved don't contain a page display. Removing all views blocks from the page returns the page again.
I'm unable to update to the latest security release due to this issue.
Comment #42
longwave@alfthecat Your issue is not the same as the one described here, although the end result is the same. Please open a new issue, and include a config export of a view that demonstrates the problem.
Comment #43
leonardo.montenegro commentedIn my case, the site continues to work fine, but whenever I clear Drupal cache, I get the following error:
Symfony\Component\HttpFoundation\Exception\BadRequestException: Invalid URI: A URI must not start nor end with ASCII control characters or spaces. in Symfony\Component\HttpFoundation\Request::create() (line 371 of /var/www/vendor/symfony/http-foundation/Request.php).Is it somehow related to the bug reported here?
Comment #44
alfthecat commented@longwave thanks, I opened #3489329: symfony/http-foundation commit 32310ff breaks PathValidator.
Comment #45
mfbTagging needs followup because I'm not sure work here is complete. The Drupal\Core\Url methods are not actually documented to throw a BadRequestException. Either this exception shouldn't be thrown, or should be caught and re-thrown as a different exception, or should be documented.
Comment #46
ericpoir commentedI created a patch based on the work that was done in the issue that is shared in comment #44 which fixes error handling for 10.3.x on my end.
Comment #47
frondeau commentedHello @ericpoir,
Thank you for your first patch (3486195-46.patch) which seams to suit to my use case, when running drush updb after updating to Drupal 10.3.10: the messages at the end of updb is "
"
Regards.
Comment #48
rang501 commentedThe patch in #46 fixes the issue for me as well.
Thanks!
Comment #49
nate covington commentedConfirming, #46 works for me, too.
Comment #50
gilles_webstanz commentedThank you for the fix ! Works for me. #46
Comment #51
thalemn commentedPatch in #46 appears to fix the issue for my install. Using 10.3.10.
Comment #52
ericpoir commentedThe changes in the patch #46 seems to be available in 10.4.0 now.
Comment #54
anacolautti commentedI had an issue with the edit forms, sometimes I would get this error too. I know it is not the same issue, but the patch in #46 fixed my issue.
Is this going to be added anytime soon? I am on Drupal 10.3. Thanks.I upgraded to Drupal 10.4.1 and the issue was fixed as well.Comment #55
safoora_mir commentedWe encountered an issue where a view using faceted filters triggered an error during an AJAX request. The error seemed related to invalid paths, but it only occurred once, and we have not been able to reproduce it since.
The error we noticed was:
Could this issue be related to the problem addressed by this patch? If so, would applying this patch be a good preventive measure to avoid similar events in the future?
Any guidance would be greatly appreciated.
Comment #56
dmundra@safoora_mir I believe the error is thrown in search faceted if your filter text or someone's text includes a trailing space. I was able to recreate it with a trailing space.
Comment #57
pheudo commented@safoora_mir I can confirm the issue.
I have the same error when I put a whitespace or a string that ends with a whitespace as a view parameter with AJAX that uses a facet search box of a facet source that uses the URL Processor Query string.
Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Invalid URI: A URI must not start nor end with ASCII control characters or spaces. in Symfony\Component\HttpKernel\HttpKernel->handle() (line 83Comment #58
jalpesh commentedFacing exactly same issue for facet. What was the fix suggested?
Exception 'Symfony\Component\HttpKernel\Exception\BadRequestHttpException' with message 'Invalid URI: A URI must not start nor end with ASCII control characters or spaces.' in /var/www/html/vendor/symfony/http-kernel/HttpKernel.php:83