Skip to content

Commit 5576f05

Browse files
committed
chore: always execute parse_url in preventLocalAddress
This change should make it easier to spot wrong uses of the HTTP client on development setups where allow_local_remote_servers is usually true. Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent da68a29 commit 5576f05

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

lib/private/Http/Client/Client.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,15 @@ private function isLocalAddressAllowed(array $options) : bool {
158158
}
159159

160160
protected function preventLocalAddress(string $uri, array $options): void {
161-
if ($this->isLocalAddressAllowed($options)) {
162-
return;
163-
}
164-
165161
$host = parse_url($uri, PHP_URL_HOST);
166162
if ($host === false || $host === null) {
167163
throw new LocalServerException('Could not detect any host');
168164
}
165+
166+
if ($this->isLocalAddressAllowed($options)) {
167+
return;
168+
}
169+
169170
if (!$this->remoteHostValidator->isValid($host)) {
170171
throw new LocalServerException('Host "' . $host . '" violates local access rules');
171172
}

tests/lib/Http/Client/ClientTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ public function testGetProxyUriProxyHostWithPasswordAndExclude(): void {
130130
], self::invokePrivate($this->client, 'getProxyUri'));
131131
}
132132

133+
public function testPreventLocalAddressThrowOnInvalidUri(): void {
134+
$this->expectException(LocalServerException::class);
135+
$this->expectExceptionMessage('Could not detect any host');
136+
137+
self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]);
138+
}
139+
133140
public function dataPreventLocalAddress():array {
134141
return [
135142
['https://localhost/foo.bar'],
@@ -146,7 +153,6 @@ public function dataPreventLocalAddress():array {
146153
['https://10.0.0.1'],
147154
['https://another-host.local'],
148155
['https://service.localhost'],
149-
['!@#$', true], // test invalid url
150156
['https://normal.host.com'],
151157
['https://com.one-.nextcloud-one.com'],
152158
];

0 commit comments

Comments
 (0)