Improve local domain detection

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2022-06-23 11:45:16 +02:00
parent eb677bf048
commit d23c7d245c
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A

View file

@ -66,8 +66,10 @@ class LocalAddressChecker {
$host = substr($host, 1, -1);
}
// Disallow localhost and local network
if ($host === 'localhost' || substr($host, -6) === '.local' || substr($host, -10) === '.localhost') {
// Disallow local network top-level domains from RFC 6762
$localTopLevelDomains = ['local','localhost','intranet','internal','private','corp','home','lan'];
$topLevelDomain = substr((strrchr($host, '.') ?: ''), 1);
if (in_array($topLevelDomain, $localTopLevelDomains)) {
$this->logger->warning("Host $host was not connected to because it violates local access rules");
throw new LocalServerException('Host violates local access rules');
}