Url: Always compare host and port to identify external urls

This commit is contained in:
Johannes Meyer 2025-03-13 11:43:22 +01:00
parent 191444ccd9
commit 2b08d88edf
2 changed files with 7 additions and 3 deletions
library/Icinga/Web
test/php/library/Icinga/Web

@ -179,10 +179,9 @@ class Url
}
$urlParts = parse_url($url);
if (isset($urlParts['scheme']) && (
$urlParts['scheme'] !== $request->getScheme()
if ((isset($urlParts['scheme']) && $urlParts['scheme'] !== $request->getScheme())
|| (isset($urlParts['host']) && $urlParts['host'] !== $request->getServer('SERVER_NAME'))
|| (isset($urlParts['port']) && $urlParts['port'] != $request->getServer('SERVER_PORT')))
|| (isset($urlParts['port']) && $urlParts['port'] != $request->getServer('SERVER_PORT'))
) {
$urlObject->setIsExternal();
}

@ -71,6 +71,11 @@ class UrlTest extends BaseTestCase
);
}
public function testWhetherProtocolRelativeUrlsAreDetectedAsBeingExternal()
{
$this->assertTrue(Url::fromPath('//testhost/path/to/my/url.html')->isExternal());
}
public function testWhetherGetAbsoluteUrlReturnsTheGivenUsernameAndPassword()
{
$url = Url::fromPath('http://testusername:testpassword@testsite.com/path/to/my/url.html');