Skip to content

Commit 0bfd904

Browse files
[6.x] Harden URL::isExternalToApplication() (#14287)
Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent 2750f0d commit 0bfd904

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/Facades/Endpoint/URL.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function isExternalToApplication(?string $url): bool
274274
->filter(fn ($siteUrl) => $urlDomain === $siteUrl)
275275
->isEmpty();
276276

277-
$isExternalToCurrentRequestDomain = ! Str::startsWith($url, self::getDomainFromAbsolute(url()->to('/')));
277+
$isExternalToCurrentRequestDomain = $urlDomain !== self::getDomainFromAbsolute(url()->to('/'));
278278

279279
return self::$externalAppUrlsCache[$url] = $isExternalToSites && $isExternalToCurrentRequestDomain;
280280
}
@@ -386,7 +386,7 @@ private function getAbsoluteSiteUrls(): Collection
386386
*/
387387
private function getDomainFromAbsolute(string $url): string
388388
{
389-
return preg_replace('/(https*:\/\/[^\/]+)(.*)/', '$1', $url);
389+
return parse_url($url, PHP_URL_HOST) ?? $url;
390390
}
391391

392392
/**

tests/Facades/Concerns/ProvidesExternalUrls.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ public static function externalUrlProvider()
6767
['http://subdomain.this-site.com.au/some-slug', true],
6868
['http://subdomain.this-site.com.au/some-slug?foo', true],
6969
['http://subdomain.this-site.com.au/some-slug#anchor', true],
70+
71+
// Credential injection
72+
['http://this-site.com@evil.com', true],
73+
['http://this-site.com@evil.com/', true],
74+
['http://this-site.com@evil.com/path', true],
75+
['http://this-site.com@evil.com/path?query', true],
76+
['http://this-site.com:password@evil.com', true],
77+
['http://user:pass@evil.com', true],
78+
['http://absolute-url-resolved-from-request.com@evil.com', true],
79+
['http://absolute-url-resolved-from-request.com@evil.com/path', true],
80+
['http://subdomain.this-site.com@evil.com', true],
81+
['http://subdomain.this-site.com@evil.com/path', true],
82+
['http://this-site.com:8000@evil.com', true],
83+
['http://this-site.com:8000@evil.com/path', true],
84+
['http://this-site.com:8000@webhook.site/token', true],
7085
];
7186
}
7287
}

0 commit comments

Comments
 (0)