}
protected function preventLocalAddress(string $uri, array $options): void {
- if ($this->isLocalAddressAllowed($options)) {
- return;
- }
-
$host = parse_url($uri, PHP_URL_HOST);
if ($host === false || $host === null) {
throw new LocalServerException('Could not detect any host');
}
+
+ if ($this->isLocalAddressAllowed($options)) {
+ return;
+ }
+
if (!$this->remoteHostValidator->isValid($host)) {
throw new LocalServerException('Host "' . $host . '" violates local access rules');
}
], self::invokePrivate($this->client, 'getProxyUri'));
}
+ public function testPreventLocalAddressThrowOnInvalidUri(): void {
+ $this->expectException(LocalServerException::class);
+ $this->expectExceptionMessage('Could not detect any host');
+
+ self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]);
+ }
+
public function dataPreventLocalAddress():array {
return [
['https://localhost/foo.bar'],
['https://10.0.0.1'],
['https://another-host.local'],
['https://service.localhost'],
- ['!@#$', true], // test invalid url
['https://normal.host.com'],
['https://com.one-.nextcloud-one.com'],
];