diff options
author | Georg Ehrke <developer@georgehrke.com> | 2019-07-02 18:11:05 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2019-07-02 20:04:54 +0200 |
commit | 089a421ecec1c5c51b9811ff24ec0035d4e604c1 (patch) | |
tree | 0ab93f5446ba446aacb8ea09019a465c2153e1f9 /apps/dav/lib/BackgroundJob | |
parent | 23bcb715ebedb60c538511d5f307a39f56a71a34 (diff) | |
download | nextcloud-server-089a421ecec1c5c51b9811ff24ec0035d4e604c1.tar.gz nextcloud-server-089a421ecec1c5c51b9811ff24ec0035d4e604c1.zip |
RefreshWebcalJob: replace ugly Regex with standard php utils
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/lib/BackgroundJob')
-rw-r--r-- | apps/dav/lib/BackgroundJob/RefreshWebcalJob.php | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php index 871734aab55..e99cd7038f6 100644 --- a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php +++ b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php @@ -225,14 +225,25 @@ class RefreshWebcalJob extends Job { } if ($allowLocalAccess !== 'yes') { - $host = parse_url($url, PHP_URL_HOST); + $host = strtolower(parse_url($url, PHP_URL_HOST)); // remove brackets from IPv6 addresses if (strpos($host, '[') === 0 && substr($host, -1) === ']') { $host = substr($host, 1, -1); } - if ($host === 'localhost' || substr($host, -6) === '.local' || substr($host, -10) === '.localhost' || - preg_match('/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/', $host)) { + // Disallow localhost and local network + if ($host === 'localhost' || substr($host, -6) === '.local' || substr($host, -10) === '.localhost') { + $this->logger->warning("Subscription $subscriptionId was not refreshed because it violates local access rules"); + return null; + } + + // Disallow hostname only + if (substr_count($host, '.') === 0) { + $this->logger->warning("Subscription $subscriptionId was not refreshed because it violates local access rules"); + return null; + } + + if ((bool)filter_var($host, FILTER_VALIDATE_IP) && !filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { $this->logger->warning("Subscription $subscriptionId was not refreshed because it violates local access rules"); return null; } |