From 22d8707c95983104967465632aa7ece2bdf9e45d Mon Sep 17 00:00:00 2001
From: Eric Garver <eric@garver.life>
Date: Tue, 25 Feb 2020 16:16:04 -0500
Subject: [PATCH 148/154] fix: checkIP6: strip leading/trailing square brackets
This lets users use URL encoded IPv6 addresses, e.g. "[::1234]" as
opposed to "::1234". The brackets are typically only used in a URL or
when combining an address with a port number, e.g. "[::1234]:22".
Fixes: rhbz 1779835
(cherry picked from commit 46065ddfacd28aac46502a931085d27fe3571ebe)
(cherry picked from commit 0fc443471f6a65e708f4dadc07519e27196c26e0)
---
src/firewall/functions.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/firewall/functions.py b/src/firewall/functions.py
index 8793ac3dbf21..375302fd3d30 100644
--- a/src/firewall/functions.py
+++ b/src/firewall/functions.py
@@ -177,6 +177,14 @@ def checkIP(ip):
return False
return True
+def normalizeIP6(ip):
+ """ Normalize the IPv6 address
+
+ This is mostly about converting URL-like IPv6 address to normal ones.
+ e.g. [1234::4321] --> 1234:4321
+ """
+ return ip.strip("[]")
+
def checkIP6(ip):
""" Check IPv6 address.
@@ -185,7 +193,7 @@ def checkIP6(ip):
"""
try:
- socket.inet_pton(socket.AF_INET6, ip)
+ socket.inet_pton(socket.AF_INET6, normalizeIP6(ip))
except socket.error:
return False
return True
--
2.25.2