aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Http/Client/Client.php
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2022-10-27 14:33:31 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2022-10-31 16:13:28 +0100
commit8aea25b5b92dac105f7e862470ee0dcf0e876615 (patch)
tree3095f0a58eb70e1c21117ce9c3450a1e60e323ba /lib/private/Http/Client/Client.php
parentaa81b87f26552bc3d49de6cf0babfe6a79c21af5 (diff)
downloadnextcloud-server-8aea25b5b92dac105f7e862470ee0dcf0e876615.tar.gz
nextcloud-server-8aea25b5b92dac105f7e862470ee0dcf0e876615.zip
Add remote host validation API
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Http/Client/Client.php')
-rw-r--r--lib/private/Http/Client/Client.php18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php
index d4dba3e5a44..2e370395132 100644
--- a/lib/private/Http/Client/Client.php
+++ b/lib/private/Http/Client/Client.php
@@ -37,8 +37,11 @@ use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\RequestOptions;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IResponse;
+use OCP\Http\Client\LocalServerException;
use OCP\ICertificateManager;
use OCP\IConfig;
+use OCP\Security\IRemoteHostValidator;
+use function parse_url;
/**
* Class Client
@@ -52,19 +55,18 @@ class Client implements IClient {
private $config;
/** @var ICertificateManager */
private $certificateManager;
- /** @var LocalAddressChecker */
- private $localAddressChecker;
+ private IRemoteHostValidator $remoteHostValidator;
public function __construct(
IConfig $config,
ICertificateManager $certificateManager,
GuzzleClient $client,
- LocalAddressChecker $localAddressChecker
+ IRemoteHostValidator $remoteHostValidator
) {
$this->config = $config;
$this->client = $client;
$this->certificateManager = $certificateManager;
- $this->localAddressChecker = $localAddressChecker;
+ $this->remoteHostValidator = $remoteHostValidator;
}
private function buildRequestOptions(array $options): array {
@@ -181,7 +183,13 @@ class Client implements IClient {
return;
}
- $this->localAddressChecker->throwIfLocalAddress($uri);
+ $host = parse_url($uri, PHP_URL_HOST);
+ if ($host === false || $host === null) {
+ throw new LocalServerException('Could not detect any host');
+ }
+ if (!$this->remoteHostValidator->isValid($host)) {
+ throw new LocalServerException('Host violates local access rules');
+ }
}
/**