InvalidArgumentException: Source path has to start with a slash - thrown when requesting double slash path

Created on 16 August 2021, over 3 years ago
Updated 24 April 2025, about 7 hours ago

The RequestPath condition plugin throws this exception when https://www.example.com// is requested. i.e. with a double slash instead of a single one. The error happens in this code block:

    $path = $this->currentPath->getPath($request);
    // Do not trim a trailing slash if that is the complete path.
    $path = $path === '/' ? $path : rtrim($path, '/');
    $path_alias = mb_strtolower($this->aliasManager->getAliasByPath($path));

If the requested path is "//", then the rtrim gets applied, resulting in an empty string.

Proposing the solution to remove double slashes generally in the path before any further evaluation, as a double slash can always only be by mistake. Going to provide an MR shortly.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component

system.module

Created by

πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Merge request !31603228298-10.1.x β†’ (Open) created by rpayanm
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    This InvalidArgumentException is also being triggered by bot traffic on all our sites using the Lazy module because it uses this RequestPath condition plugin. It's being triggered by visiting the path /index.php.suspected, so not just paths with double slashes. That's why I want to propose to also just catch any InvalidArgumentExceptions thrown in the getAliasByPath() method.

Production build 0.71.5 2024