aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Security/Normalizer
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2019-01-03 10:03:46 +0100
committerThomas Citharel <tcit@tcit.fr>2019-01-03 10:03:46 +0100
commitc9b588774bf57b0d0f9742b2ca32f2185c4317f1 (patch)
treea4ce602632f3bbb37a3a2ff38054110dd5238486 /lib/private/Security/Normalizer
parent4d8f2c241886d6aebb938d6e6867e1779520b930 (diff)
downloadnextcloud-server-c9b588774bf57b0d0f9742b2ca32f2185c4317f1.tar.gz
nextcloud-server-c9b588774bf57b0d0f9742b2ca32f2185c4317f1.zip
Allow bracket IPv6 address format inside IPAdress Normalizer
When run with php's build-in server (for instance on localhost:8080), IP provided through $this->server['REMOTE_ADDR'] is [::1], which is not an acceptable format for \inet_pton. This removes the brackets if there's any. Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'lib/private/Security/Normalizer')
-rw-r--r--lib/private/Security/Normalizer/IpAddress.php3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/private/Security/Normalizer/IpAddress.php b/lib/private/Security/Normalizer/IpAddress.php
index 84c87054c76..4edf83eca5e 100644
--- a/lib/private/Security/Normalizer/IpAddress.php
+++ b/lib/private/Security/Normalizer/IpAddress.php
@@ -68,6 +68,9 @@ class IpAddress {
* @return string
*/
private function getIPv6Subnet(string $ip, int $maskBits = 48): string {
+ if ($ip[0] === '[' && $ip[-1] === ']') { // If IP is with brackets, for example [::1]
+ $ip = substr($ip, 1, strlen($ip) - 2);
+ }
$binary = \inet_pton($ip);
for ($i = 128; $i > $maskBits; $i -= 8) {
$j = \intdiv($i, 8) - 1;