Skip to content

Duplicate slashes are removed from path parameters. #11049

@Treora

Description

@Treora

When processing the requested path, Nextcloud cleans up subsequent slashes paths, such that e.g. /apps//test will become /apps/test. While usually not an issue, it becomes problematic when you want to keep those double slashes, most commonly when expecting a url as a parameter in apps for redirection, proxying, or archiving.

Reproduce

For example, an app could try to use the following URL syntax:

/apps/redirectme/to/https://example.org

And therefore define a route like this:

[
  'name' => 'page#redirect',
  'url' => '/to/{target}',
  'requirements' => array('target' => '.+')
]

Expected behaviour

Parameter $target will be https://example.org.

Actual behaviour

Parameter $target is https:/example.org (note the single slash).

Even when using a function such as IRequest->getRawPathInfo(), you will obtain the 'cleaned'/corrupted value.

Cause

This one line seems to be the culprit:

$requestUri = preg_replace('%/{2,}%', '/', $requestUri);

Workaround

You can work around this by reading the parameter manually; somewhat hacky, but something like this seems to work: (cleaner solutions welcome!)

$path = $_SERVER['REQUEST_URI'];
$routePath = 'apps/redirectme/to/'; // (presumably nobody has this string in their web root)
$target = substr($path, strpos($path, $routePath) + strlen($routePath));

Prior discussion

This issue has been traced by and discussed with @nickvergessen and @LukasReschke. The thought thus far was that there was no particularly strong reason for the implemented behaviour, but that changing this behaviour might be problematic due to existing apps that may rely on it.

Reporting the issue nevertheless to have it documented, and perhaps the thoughts on this may change, or it may be worth providing an extra method somewhere to get the parameters without the slash-cleaning step.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions