Problem/Motivation
When hitting a site with at least one block configured with a request_path condition on any URL prefixed with index.php (i.e example.com/index.phpfoo, the following error is thrown (truncated stacktrace for brevity)
InvalidArgumentException: Source path foo has to start with a slash. in Drupal\path_alias\AliasManager->getAliasByPath() (line 185 of core/modules/path_alias/src/AliasManager.php).
Drupal\system\Plugin\Condition\RequestPath->evaluate() (Line: 77)
Drupal\Core\Condition\ConditionManager->execute() (Line: 84)
Drupal\Core\Condition\ConditionPluginBase->execute() (Line: 26)
Steps to reproduce
- 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
option 1 - Potentially always prefix $path with a forward slash https://git.drupalcode.org/project/drupal/-/merge_requests/11348
option 2 - Fix RequestPath condition plugin directly https://git.drupalcode.org/project/drupal/-/merge_requests/13580
| Comment | File | Size | Author |
|---|
Issue fork drupal-3043779
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:
Comments
Comment #2
pk_uk commentedhave this issue also v8.6.5
Comment #3
hmdnawaz commentedI am getting the same error on the same page in 8.7.8.
Comment #4
hmdnawaz commentedPatch is attached.
Comment #5
hmdnawaz commentedComment #6
hmdnawaz commentedComment #7
ious commentedHello, I have the same issue on 8.8.4. #4 patch fix the error, and display the following warning : "Warning: array_key_exists(): The first argument should be either a string or an integer in Drupal\Core\Path\AliasWhitelist->get() (line 120 of core/lib/Drupal/Core/Path/AliasWhitelist.php)."
Comment #8
dipayanpramanik5 commentedHi,
This patch is for drupal 8.7.x version and it also covers the issue mentioned in comment #7
Comment #9
honza pobořil commentedPatch #8 fixed issue on Drupal 8.9.0.
Btw haven't faced this issue on version 8.8.5.
Comment #11
pameeela commentedAdded credit for drupert55 based on the report and follow up from #2763953: Certain characters in a site name lead to InvalidArgumentException: "Source path has to start with a slash." when Drupal installed in a subdirectory now marked as a duplicate.
Comment #14
pameeela commentedAdding ml1 and haseebjamal as credited too.
Also noting that two reporters on #2763953: Certain characters in a site name lead to InvalidArgumentException: "Source path has to start with a slash." when Drupal installed in a subdirectory had this problem when there were special characters in their directory name, and were able to resolve it by removing those. Another user reported it whenever they had a port number appended to the URL.
Comment #15
pameeela commentedComment #16
Yuri commentedUsing Drupal 9.0.3, patches not working,
InvalidArgumentException: Source path has to start with a slash. in Drupal\path_alias\AliasManager->getAliasByPath() (line 189 of core/modules/path_alias/src/AliasManager.php).In my case it is not caused by special characters in their directory name.
[EDIT] I had unchecked (on purpose) the permission "View published content" for anonymous users.
For anonymous users, for the front page this resulted in this error, for other pages it showed the expected 'Access denied'.
Comment #17
mbovan commentedI couldn't reproduce this in the default installation, but I am getting the same error when there is a block with
request_pathcondition.Updated Steps to reproduce accordingly.
Related: #3167426: CurrentPathStack::getPath should always return a path with leading slashes, #2707991: Misleading error: "InvalidArgumentException: Source path has to start with a slash." when user cannot access the front page
Comment #18
mbovan commentedTest only patch for #17.
Comment #19
mbovan commentedI am not sure if this issue aims to cover more cases than I encountered in #17.
For that reason, I moved the patches/updates to #3167426: CurrentPathStack::getPath should always return a path with leading slashes.
Comment #21
desoi commentedI'm still seeing this a lot in the recent log messages with Drupal 9.0.7. In my case, it looks like stupid bots trying a bunch of random URLs. I can easily reproduce the error by going to /index.php.php on the website.
I don't understand why this should generate a PHP (500) error instead of just a not found (404) error.
Comment #22
vuilI have the same issue on Drupal 9.0.6 core version with missing
front:page insystem.site.ymlbecause we have different front page per environment (LOCAL/DEMO/DEV/TEST/STAGE/PROD). And sometimes front page setting is missing which is not an error.Comment #23
vuilI found a solution in
Drupal/system/Form/SiteInformationForm->buildForm()line 125:I'm just adding
&& !empty($site_config->get('page.front')which resolve the issue in my case.Comment #24
vuilI post the patch of #23.
I already tested on the both of D8.9.x and D9.0.x branch and it is working fine.
Comment #25
alexrayu commentedApplied the patch from #24 and tested successfully. Thanks for the fix @vuil!
Comment #26
vuilI set the issue status to RTBC.
Comment #27
sershevchykI have used patch #24 and see error:
InvalidArgumentException: Source path https://example.lndo.site/catalog-search?sort_bef_combine=published_date_ASC&f[0]=tracks:242&title= has to start with a slash. in Drupal\Core\Path\AliasManager->getAliasByPath() (line 229 of /app/web/core/lib/Drupal/Core/Path/AliasManager.php).Looks like it's another string in the same file
Comment #28
alexpottThis issue appears to have changed direction in between #18 and #22 and there's no tests in the latest patch. Also the patch in #24 doesn't apply to 9.2.x and doesn't solve the steps to reproduce in the issue summary.
That said, I think we should be triggering a 404 if someone hits index.php.php... as we should for index.phpbbhgfbg which also produces the same error.
Comment #29
alexpottI think the problem in #24 is a separate issue. FWIW if the system.site:page.front setting is empty then your frontpage will be a 404 and if we do the fix in #24 and then goto the site information page and press save it'll change the empty setting back to user/login... so that needs more work.
Oh interesting it seems now the first bug this issue fix is now #3167426: CurrentPathStack::getPath should always return a path with leading slashes so this issue can become about the SystemInformationForm :) I think this is a normal bug because via the UI it is impossible to set the config value to an empty string.
Comment #30
dimaboychev commentedIf you go to /index.php5 or /index.php.htm, index.phpblahblahblah or /index.php{anything without a leading slash}, it will throw this error from line 229 of AliasManager.php
InvalidArgumentException: Source path {whatever} has to start with a slash. in Drupal\Core\Path\AliasManager->getAliasByPath() (line 229 of core/lib/Drupal/Core/Path/AliasManager.php).Comment #33
odai atiehUpdated patch, also you need to use another patch from here to fix the warning #3215098: AliasManager->getAliasByPath('//') PHP Warning
Comment #34
odai atiehComment #35
canardesign commentedDrupal Version
9.3.13
Domain module version
8.x-1.0-beta6
Expected Behavior
Navigate to https://mydomain.com/node/xxx to view or edit node when this node domain source field is filled
Actual Behavior
I got an error :
InvalidArgumentException: Source path http://mydomain.com/node/1219/edit has to start with a slash. in Drupal\path_alias\AliasManager->getAliasByPath() (line 185 of core\modules\path_alias\src\AliasManager.php).
Steps to reproduce
Note that no error occurs if node domain source field is null.
Applied https://www.drupal.org/files/issues/2022-02-20/3043779-31.patch with no luck.
Comment #36
canardesign commentedDrupal Version
9.3.13
Domain module version
8.x-1.0-beta6
Expected Behavior
Navigate to https://mydomain.com/node/xxx to view or edit node when this node domain source field is filled
Actual Behavior
I got an error :
InvalidArgumentException: Source path http://mydomain.com/node/1219/edit has to start with a slash. in Drupal\path_alias\AliasManager->getAliasByPath() (line 185 of core\modules\path_alias\src\AliasManager.php).
Steps to reproduce
Note that no error occurs if node domain source field is null.
Applied https://www.drupal.org/files/issues/2022-02-20/3043779-31.patch with no luck.
Comment #39
acbramley commentedNot sure if we still need an issue summary update, the steps are fairly clear.
Here's one approach with a test only patch. The test fails still because of another issue with the fix but it gets us closer...
Comment #40
acbramley commentedUpdated IS, removed irrelevant tags.
Comment #41
acbramley commentedComment #42
acbramley commentedFix for
Warning: Undefined array key 1 template_preprocess_html()Comment #46
acbramley commentedDerp, should be a 404.
Comment #47
dpiThis is about the RequestPath condition.
Comment #49
douggreen commentedThe problem is more pervasive than this. If you visit /index.php5 (as mentioned in #30), something takes everything after "index.php" as the path alias, and you end up in PathAlias.php with the path part set to "5" which throws an error, and #3215098: AliasManager->getAliasByPath('//') PHP Warning does not fix that.
I don't understand why the test passes but it doesn't work in my browser.
In my browser (or curl)
I kicked the test bot to test it here, and this test passes (ignore the unrelated test failures). So I ran it locally and it also passes:
Comment #50
douggreen commentedSorry, I've isolated my particular problem to another module, so I'm restoring this to "needs review." Since this is a different (but similar problem) I'm not actually commenting on this patch.
Comment #52
jmaguniaThis issue is reproducible in Drupal 10.1 also.
Comment #53
priya.chat commentedI have tried a patch for this issue in Drupal 10.1, this may resolved the mentioned problem. kindly review.
Comment #54
acbramley commented@priya.chat did you miss the previous patches? There's already ongoing work for this issue, with tests etc (see #46)
If that doesn't work for you, would you mind explaining what your solution does differently?
Comment #55
priya.chat commentedHi @acbramley, I have tried previous patched for Drupal 10.1 , but didin't worked for me so I have given a try to first check if the path is valid for which we are validating the "/" value then apply the other checks. Thanks.
Comment #56
smustgrave commented@priya.chat can you provide steps for how it's failing for you?
Can't drop test coverage though.
Comment #57
priya.chat commentedHi @smustgrave , I have applied patch on #33 and tried to access /index.php5 or /index.php.php on Drupal 10.1.x , getting error below
InvalidArgumentException: Source path .php has to start with a slash. in Drupal\path_alias\AliasManager->getAliasByPath() (line 185 of /core/modules/path_alias/src/AliasManager.php).
Kindly suggest, if I am following any wrong step to reproduce this issue.
Comment #59
j_s commentedIn my particular case, a visitor went to mysite.com/index.php) which causes a white screen error. #46 didn't work for me but #56 resolved the issue.
Comment #60
georob commentedRerolled #56 for 10.3. Applies cleanly and addresses the issue as described by making the change in path auto module for requiring a slash.
Comment #61
georob commentedReading the thread again, I've moved the initial test from #39 into the patch from #56 rerolled in #60 into this patch, #61.
Comment #62
j_s commentedPatch in #61 worked well for me on 10.3. Thanks!
Comment #63
jmaguniaEdit:
The last patch couldn't be applied to Drupal 10.3.9.Here is a reroll.Comment #64
byrond commentedWhen updating to Drupal 11.1.3 while this patch is installed, clearing cache for the first time (the first of our post-deployment steps), the following error happens. Removing the patch allows cache to be cleared,
and it can be added back. I think a check for an empty or unsetwhitelistwill fix this. If so, I'll update the patch.Comment #65
byrond commented$whitelistwas changed to$pathPrefixesin Drupal 11.1.0https://git.drupalcode.org/project/drupal/-/commit/27948b069b1be0be6062b...
Here is an updated patch for Drupal 11.1+.
Comment #66
acbramley commentedThis needs to be rolled onto an MR.
Comment #69
swirtI am running into this being flagged by Invicti/Netsparker scan because they try to hit nonsensical pages like
And Invicti objects to getting a 500 response instead of a more appropriate 404. I agree with desoi, acbramley and alexpott who suggested this should be a 404. Sites with a 500 error look broken and it should not be this easy to make a Drupal site look broken.
alexpott indicated there was a possible problem with 404-ing in this case. I wonder if instead of trying to handle this at the php level and replacing the thrown exception with a 404, if it would be cleaner to have a well crafted rule in .htaccess that handles the non slash characters after `index.php`
Comment #71
swirtI created a new branch and PR ^^ for an .htaccess approach to the problem. It is simpler, and since most sites customize their .htaccess anyway, this would allow them to alter it without really needing to patch core.
Comment #72
swirtWhile the Tugboat is available, this url should return fine
https://mr11806-gs7qqwaidh3locbz5vsd5vt5golwwmyn.tugboatqa.com/index.php
And this one should result in 404
https://mr11806-gs7qqwaidh3locbz5vsd5vt5golwwmyn.tugboatqa.com/index.phpboo
Comment #73
j_s commentedIt could be useful to potentially have both the php and htaccess fixes.
Comment #74
fagoI also ran into this, with #3530291: Warning logged: Source path aut has to start with a slash.
In this case it could be a module using the API wrong, what triggers the exception.
Comment #75
nicholassOn Drupal 10.5 this also occurs if someone just adds an extra / to the homepage, for example https://www.example.gov// which the htaccess route (3043779-htaccess-no-php-danglers) doesn't cover that situation.
And the other patch (3043779-source-path-has-11.x) results in a new error
because pathPrefixes wouldn't exist in 10.5 https://git.drupalcode.org/search?search=pathPrefixes&nav_source=navbar&...
Comment #76
nicholassWhy can't we just do something simpler like this?
That seems to fix things that I tested from the comments above
Comment #78
hanan alasariI have this issue also, i have attached a patch for Drupal 10.4.7. Just for test purposes.
Comment #79
hanan alasariComment #80
dieppon commentedI have updated the previous patch for Drupal 10.5
Comment #82
acbramley commentedI can't reproduce #75 and I'm not sure I agree with #76 that the changes to AliasManager are simpler. This specific bug report is coming from the RequestPath condition plugin.
I've opened an MR with my preferred solution (from back in #46)
I'm going to close the MR for htaccess because while that may fix things for sites on Apache, it won't do anything for sites running on other technologies e.g Nginx. Also hiding patches.
Comment #84
nicholass@acbramley You said #75 you can't reproduce, but here is a link to try https://www.justice.vic.gov.au// its easy way to spot drupal sites now
Comment #85
anmol singh commentedI was trying to reproduce this issue in PHP Test using below code, error is visible on ui. but my test is not failing. ideally it should show error while running tests. if I don't apply any solution.
Comment #86
acbramley commented@anmol singh we have test coverage in the MR see https://git.drupalcode.org/project/drupal/-/merge_requests/13580/diffs#d...
Comment #87
anmol singh commented1- @acbramley it's not about this MR (https://git.drupalcode.org/project/drupal/-/merge_requests/13580/diffs#d...) I am applying patch https://www.drupal.org/project/drupal/issues/3043779#comment-16221793 which is fixing my Problem. for this I am writing my own PHP Tests which is not failing.
2- This MR(https://git.drupalcode.org/project/drupal/-/merge_requests/13580/diffs#d...) is no need for me because here your issue is fixed in
RequestPath.phpbut i am getting error on
AliasManager.phpfor this you have this MR(https://git.drupalcode.org/project/drupal/-/merge_requests/11348/diffs) but there is no PHP Test.Comment #88
jannakha commentedlooks like this index.php is being abused (from my access log from some soviet hackers):
/index.php/node/
/index.php/node/add/../../web.config
/index.php/node/1}}\"}}'}}1%25>\"%25>'%25><%25={{={@{%23{${dfb}}%25>/
/index.php/node/add/../../package.json
/index.php/node/dfb{{98991*97996}}xca/
/index.php/node/add/%2e%2e%2f%2e%2e%2fGemfile
/index.php/node/add/%2e%2e%2f%2e%2e%2fweb.config
Comment #89
anmol singh commentedHi @acbramley
when I am using this MR (https://git.drupalcode.org/project/drupal/-/merge_requests/11348/diffs) it is fixing index.php77 issue but i am still seeing
Warning: Undefined array key 1 template_preprocess_html().why this warning is not addressed in this MR as well. I think that should be fixed in this as well(https://git.drupalcode.org/project/drupal/-/merge_requests/11348/diffs).IMP!
I've updated symfony/http-foundation from v6.4.26 to v6.4.29 and now everything is working fine. but what fixed in symfony/http-foundation.
Now i think we can close this issue as fixed in symfony/http-foundation.
Comment #90
tlo405 commentedI was seeing this same problem when hitting a URL like
/index.php3on my site... but today I've updatedsymfony/http-foundationfrom v6.4.26 to v6.4.29 and now everything is working correctly.Wondering if anyone else is experiencing something similar?
Comment #91
tobiasbSo perhaps the bug is fixed via
symfony/http-foundationupdate (#3557393: Update Symfony to 7.3.7 / 6.4.29), which adds the leading/already?Comment #93
acbramley commented@anmol singh my MR is https://git.drupalcode.org/project/drupal/-/merge_requests/13580/diffs, I've hidden the other one now.
Comment #94
anmol singh commented@acbramley I think this issue should be closed as mentioned above in comment #90 its already fixed by upgrading
symfony/http-foundation from v6.4.26 to v6.4.29Comment #95
smustgrave commentedCore now uses
"symfony/http-foundation": "^7.4"so can we confirm if this is still a bug?Comment #96
acbramley commentedI'm unable to reproduce it on a client site on 11.3, not sure how the library bump fixed it but I don't even hit a debugger in the RequestPath condition plugin anymore on index.php with some random characters after it.
Comment #98
smustgrave commentedSince there's been no follow up and last few comments mention not being able to reproduce this going to close out.