From d70cd5add23b66a5009c492727002c19db431b95 Mon Sep 17 00:00:00 2001 From: Robin Kluth Date: Mon, 19 Feb 2024 11:18:37 +0100 Subject: [PATCH 1/4] Log Host/IP in `LocalServerException` for `Host violates local access rules` Signed-off-by: Robin Kluth --- lib/private/Http/Client/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php index 3bf43e6c07ec6..26a0a63378b94 100644 --- a/lib/private/Http/Client/Client.php +++ b/lib/private/Http/Client/Client.php @@ -192,7 +192,7 @@ protected function preventLocalAddress(string $uri, array $options): void { throw new LocalServerException('Could not detect any host'); } if (!$this->remoteHostValidator->isValid($host)) { - throw new LocalServerException('Host violates local access rules'); + throw new LocalServerException('Host "'.$host.'" violates local access rules'); } } From 25c0021137a2e80dc83a13e814ed4869ecb62782 Mon Sep 17 00:00:00 2001 From: Robin Kluth Date: Mon, 19 Feb 2024 11:19:58 +0100 Subject: [PATCH 2/4] Log Host/IP in `LocalServerException` for `Host violates local access rules` Signed-off-by: Robin Kluth --- lib/private/Http/Client/DnsPinMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Http/Client/DnsPinMiddleware.php b/lib/private/Http/Client/DnsPinMiddleware.php index aecccc6ce9772..80454010a29a4 100644 --- a/lib/private/Http/Client/DnsPinMiddleware.php +++ b/lib/private/Http/Client/DnsPinMiddleware.php @@ -147,7 +147,7 @@ public function addDnsPinning() { foreach ($targetIps as $ip) { if ($this->ipAddressClassifier->isLocalAddress($ip)) { // TODO: continue with all non-local IPs? - throw new LocalServerException('Host violates local access rules'); + throw new LocalServerException('Host "'.$ip.'" violates local access rules'); } $curlResolves["$hostName:$port"][] = $ip; } From 414f8f1f2d9f04dfee2b94e5570b490f58f6e030 Mon Sep 17 00:00:00 2001 From: Robin Kluth Date: Mon, 19 Feb 2024 14:26:42 +0100 Subject: [PATCH 3/4] Include `hostName:$port` for Host access violation message as well Signed-off-by: Robin Kluth --- lib/private/Http/Client/DnsPinMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Http/Client/DnsPinMiddleware.php b/lib/private/Http/Client/DnsPinMiddleware.php index 80454010a29a4..518281e4af01b 100644 --- a/lib/private/Http/Client/DnsPinMiddleware.php +++ b/lib/private/Http/Client/DnsPinMiddleware.php @@ -147,7 +147,7 @@ public function addDnsPinning() { foreach ($targetIps as $ip) { if ($this->ipAddressClassifier->isLocalAddress($ip)) { // TODO: continue with all non-local IPs? - throw new LocalServerException('Host "'.$ip.'" violates local access rules'); + throw new LocalServerException('Host "'.$ip.'" ('.$hostName.':'.$port.') violates local access rules'); } $curlResolves["$hostName:$port"][] = $ip; } From 51739ad1ac658a6215851cd9eac37a30c4f85955 Mon Sep 17 00:00:00 2001 From: Robin Kluth Date: Fri, 23 Feb 2024 20:05:50 +0100 Subject: [PATCH 4/4] Adjust tests to match new expected exception Signed-off-by: Robin Kluth --- tests/lib/Http/Client/DnsPinMiddlewareTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/lib/Http/Client/DnsPinMiddlewareTest.php b/tests/lib/Http/Client/DnsPinMiddlewareTest.php index 2fa868e6963d4..54071f37b1a82 100644 --- a/tests/lib/Http/Client/DnsPinMiddlewareTest.php +++ b/tests/lib/Http/Client/DnsPinMiddlewareTest.php @@ -287,7 +287,7 @@ static function (RequestInterface $request, array $options) { public function testRejectIPv4() { $this->expectException(LocalServerException::class); - $this->expectExceptionMessage('Host violates local access rules'); + $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ static function (RequestInterface $request, array $options) { @@ -334,7 +334,7 @@ static function (RequestInterface $request, array $options) { public function testRejectIPv6() { $this->expectException(LocalServerException::class); - $this->expectExceptionMessage('Host violates local access rules'); + $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ static function (RequestInterface $request, array $options) { @@ -381,7 +381,7 @@ static function (RequestInterface $request, array $options) { public function testRejectCanonicalName() { $this->expectException(LocalServerException::class); - $this->expectExceptionMessage('Host violates local access rules'); + $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ static function (RequestInterface $request, array $options) {