* * @author 2022 Christoph Wurst * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace OC\Security; use OC\Net\HostnameClassifier; use OC\Net\IpAddressClassifier; use OCP\IConfig; use OCP\Security\IRemoteHostValidator; use Psr\Log\LoggerInterface; use function strtolower; use function substr; use function urldecode; /** * @internal */ final class RemoteHostValidator implements IRemoteHostValidator { public function __construct( private IConfig $config, private HostnameClassifier $hostnameClassifier, private IpAddressClassifier $ipAddressClassifier, private LoggerInterface $logger, ) { } public function isValid(string $host): bool { if ($this->config->getSystemValueBool('allow_local_remote_servers', false)) { return true; } $host = idn_to_utf8(strtolower(urldecode($host))); if ($host === false) { return false; } // Remove brackets from IPv6 addresses if (str_starts_with($host, '[') && str_ends_with($host, ']')) { $host = substr($host, 1, -1); } if ($this->hostnameClassifier->isLocalHostname($host) || $this->ipAddressClassifier->isLocalAddress($host)) { $this->logger->warning("Host $host was not connected to because it violates local access rules"); return false; } return true; } } Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: 2d16c6190b8cea7a328bf8ca687e24cbcfbc42a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

declare(strict_types=1);

/**
 * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
 *
 * @author Joas Schilling <coding@schilljs.com>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
namespace OCP\Http\Client;

/**
 * @since 19.0.0
 */
class LocalServerException extends \RuntimeException {
}