nette / routing

Nette Routing: two-ways URL conversion
https://doc.nette.org/routing
Other
231 stars 3 forks source link

Bug: Canonical logic accept domain.com///// #6

Closed janbarasek closed 3 years ago

janbarasek commented 4 years ago

Description

In case of domain.com//// internal method match(IRequest $httpRequest): ?array got fake URL with only one slash.

Some example (CustomRouter.php):

public function match(IRequest $httpRequest): ?array
{
    $url = $httpRequest->getUrl();
    dump($url);
    dump($url->getAbsoluteUrl());
    $realUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')
        . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    dump($realUrl);
    die;

In production mode dump looks like this:

Snímek obrazovky 2020-02-12 v 10 05 47

So object UrlScript contains invalid URL and I can open URL https://nette.org, https://nette.org/ and https://nette.org///// too without canonical redirect.

Steps To Reproduce

Open https://nette.org///// for example:

Snímek obrazovky 2020-02-12 v 10 08 39

Thanks.

JanTvrdik commented 4 years ago

There's a built-in path filter in Nette\Http\RequestFactory which replaces sequence of / with a single /. See https://github.com/nette/http/blob/v3.0.3/src/Http/RequestFactory.php#L28

janbarasek commented 4 years ago

Yes, of course, but I think this is a natural duplication that should be redirected.

janbarasek commented 4 years ago

@dg How can I solve this issue? This bug makes a number of duplicate pages and damages SEO.

I think firstly I must fix Url entity which should support sequence of / in case of homepage or ending with it.

Thanks.

dg commented 3 years ago

This is related to nette/http, I know about it and it will be addressed in version 4.0.