From 8e5b32aef3d3d7a4ccbf2ff7d047df1d4aef7f6a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 13 Mar 2025 11:43:22 +0100 Subject: [PATCH] Url: Always compare host and port to identify external urls (cherry picked from commit 2b08d88edff8381f513ad7138b2204953e1c406c) --- library/Icinga/Web/Url.php | 5 ++--- test/php/library/Icinga/Web/UrlTest.php | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index f4fcba381..7b9af3644 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -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(); } diff --git a/test/php/library/Icinga/Web/UrlTest.php b/test/php/library/Icinga/Web/UrlTest.php index cbe8b6bf8..6a6088f2f 100644 --- a/test/php/library/Icinga/Web/UrlTest.php +++ b/test/php/library/Icinga/Web/UrlTest.php @@ -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');