Problem/Motivation
If you visit /index.php.php path, the PHP warning occurs and a log record is created:
Notice: Undefined offset: 1 in template_preprocess_html() (line 1343 of core/includes/theme.inc).
template_preprocess_html(Array, 'html', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Steps to reproduce
1) First case: Visit your.site/index.php. or your.site/index.php.php
2) Second case:
- Clean Drupal installation
- Go to admin/structure/block, edit any (for example: Search) block that appears on the frontpage
- Go to pages tab and set
/user/*and click "Show for the listed pages" - Go to your.site/index.php.php
- There is an exception:
InvalidArgumentException: Source path .php has to start with a slash. in Drupal\Core\Path\AliasManager->getAliasByPath() (line 229 of core/lib/Drupal/Core/Path/AliasManager.php).
Proposed resolution
1) Adjust Drupal\system\Plugin\Condition\RequestPath to request a path with a slash.
2) Fix template_preprocess_html() so it doesn't show a warning if there is an extra dot when resolving route path.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
The function CurrentPathStack::getPath() now returns the path with leading slashes. This change was made because paths with leading slashes are almost always correct in Drupal.
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | 3167426-51.patch | 5.5 KB | georob |
| #46 | 3167426-45-interdiff.txt | 543 bytes | berdir |
| #46 | 3167426-45.patch | 5.48 KB | berdir |
| #42 | 3167426-42.patch | 5.44 KB | ranjith_kumar_k_u |
| #38 | interdiff-3167426-24-37.txt | 2.21 KB | mohit_aghera |
Issue fork drupal-3167426
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:
- 3167426-currentpathstackgetpath-should-always
changes, plain diff MR !8485
Comments
Comment #2
mbovan commentedThis conditionally sets the route path if the first item of the system path is available.
Comment #3
mbovan commentedComment #4
mbovan commentedUpdated the issue title and description to cover #3043779.18.
Comment #5
mbovan commentedComment #6
mbovan commentedUpdates:
Comment #9
berdirBoth cases use path.current, could we enforce within that that it always returns a leading /?
This is touching an existing point about the incorrect documentation on \Drupal\Core\Path\CurrentPathStack::getPath(), I thought we had an issue but can't find it right now, which says it is without leading / but that's clearly wrong and code expects it to be otherwise.
\Symfony\Component\HttpFoundation\Request::getPathInfo() documents that there is a case when it returns an empty string, although I'm a bit confused about that.
Comment #10
berdirwhy the split of the extra $edit addition and manually requesting the path first, can't we just put it all in the initial $edit definition and add the path to drupalPostForm() so it requests it first internally?
Comment #11
mbovan commented#9 Makes sense to move the logic to
getPath()instead.#10 Fixed.
There is #2430805: Fix CurrentPathStack::getPath() documentation that says it has no leading / (and make it easier to actually get that?) that aims to fix the documentation.
Comment #13
mbovan commentedThere are more places where this needs to be fixed to address the original problem...
To catch all the places, this would need to be fixed in
Symfony\Component\HttpFoundation\Request::preparePathInfoIMHO.Comment #14
larowlancould we use
ltrimhere and then just add back?Comment #15
mbovan commented#14 That reads eaiser, thanks!
Comment #16
berdirnitpick: extra spaces here.
Wondering if we want to merge the old issue about the documentation into this, it got stuck in 2018 and kind of makes sense to fix the documentation as we are fixing bugs the implementation?
Comment #17
mbovan commentedRemoved the extra spaces and fixed docs based on #2430805: Fix CurrentPathStack::getPath() documentation that says it has no leading / (and make it easier to actually get that?).
Since the fix is going into direction of fixing
Drupal\Core\Path\CurrentPathStack::getPath, I improved the issue title as well.Comment #18
berdirLooks good to me. We can decide what to do with the other issue when this is committed? Possibly fine to close as duplicate although there's another change in those patches that I'm not sure still makes sense or not.
Comment #19
catchI think we should have a change record for this, and a small release note - seems like there's a small chance that contrib or custom code could be relying on the buggy behaviour (which I think the 500 error in core overrides).
Comment #20
adamps commentedDone change record and release note snippet.
Comment #23
berdirLooks like this was set back to need work due to a random fail?
Rebased on 9.2.x, also noticed that we were using a bunch of deprecated methods in the test and updated that.
Comment #24
acbramley commentedLooks like new checks for spelling were added since #17
Comment #26
acbramley commentedFail was a rando
Comment #27
guilhermevp commentedFollowed step 2 and was able to successfully reproduce the error. After applying the patch, could verify that accessing index.php.php don't returns error anymore.
RTBC +1
Comment #28
adamps commentedLooks good to me thanks for the new patches
Comment #30
benjifisherPlease do not ask the testbot to try again until #3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest is fixed.
Comment #31
alexpott#3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest is fixed. I have not reviewed the code.
Comment #32
alexpottCommitted 3b40d8c and pushed to 9.2.x. Thanks!
Before publishing the CR I'm going to ping catch about this going in 9.1.x and maybe even 8.9.x since this bug is causing pages to be 200 when they should be a 404 - which makes this a major.
Comment #33
acbramley commentedThanks @alexpott, it looks like that commit link is 404ing, maybe a forgotten push?
Comment #34
alexpottWoke up thinking that I'd committed this prematurely so not going to push.
This changes deserve there own tests - unit or kernel somewhere.
I think this test only needs one of these requests. The other should be in \Drupal\Tests\system\Functional\System\IndexPhpTest because the 404 is not really part of the block visibility stuff and if we refactored this test in the future because of changes to how block visibility work then we might remove this important coverage.
Comment #35
alexpottI also woke up wondering if this is a Symfony bug. I think if we reported this to Symfony they would point us to https://github.com/symfony/recipes-contrib/blob/master/symfony/apache-pa... and say that Drupal shouldn't serve duplicated content on / and /index.php but I think regardless \Symfony\Component\HttpFoundation\Request::preparePathInfo() should always return a leading slash. I've opened https://github.com/symfony/symfony/pull/40750 to fix this upstream.
Comment #36
mohit_aghera commentedComment #37
mohit_aghera commented- Refactoring the tests as suggested in #34
- Added new test cases to validate prependSlash method.
Comment #38
mohit_aghera commented- Uploading interdiff for the above patch.
Comment #42
ranjith_kumar_k_u commentedRerolled #37 for 9.5
Comment #43
adamps commentedThe requested comments have been made so back to RTBC
Comment #44
alexpottAs per #35 I think the correct place to fix this is upstream - see https://github.com/symfony/symfony/pull/40750 - I'll push on that again and see if I can get it moving.
Going to postpone this one depending on the outcome.
Comment #46
berdirRe #44: fair, I do think we could get a workaround in core while we push for upstream, but up to you. Just a reroll for now to update this for D10. Patch still applied but is not compatible with Symfony 6.
Comment #48
damienmckennaWe ran into this bug on a site when someone loaded an oddly formatted URL. In fairness it was a bot trying to find an attack vector on the site, but it still shouldn't have caused an error when it should have been displaying a 404 error page.
Comment #49
joelpittetPatch in #46 totally puts a dent in this for us, we got around 600+ logs directly related to this. Thanks @Berdir.
Thanks @alexpott for taking this upstream as well though it looks like it might have stalled?
Comment #51
georob commentedRerolled the patch from #46 for 10.3. Applies successfully. Successfully addresses the test criteria still.
Comment #53
alexpottThis finally got fixed in Symfony - in a security issue no less! https://github.com/symfony/symfony/security/advisories/GHSA-3rg7-wf37-54rm and 10.6 has the fixed version of Symfony.