Skip to content

Commit 9bc9e57

Browse files
skorandac00kiemon5ter
authored andcommitted
Fix ipv6 validation for addresses with brackets
Fix ipv6 validation for addresses that include the brackets, such as [2001:8003:5555:9999:555a:5555:c77:d5c5]. See https://tools.ietf.org/html/rfc4038#section-5.1 regarding the inclusion of brackets in the address. The Shibboleth IdP sends ipv6 addresses that include the brackets.
1 parent ad83f81 commit 9bc9e57

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/saml2/validate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def valid_ipv4(address):
133133
IPV6_PATTERN = re.compile(r"""
134134
^
135135
\s* # Leading whitespace
136+
\[? # See https://tools.ietf.org/html/rfc4038#section-5.1
136137
(?!.*::.*::) # Only a single wildcard allowed
137138
(?:(?!:)|:(?=:)) # Colon iff it would be part of a wildcard
138139
(?: # Repeat 6 times:
@@ -153,6 +154,7 @@ def valid_ipv4(address):
153154
(?:25[0-4]|2[0-4]\d|1\d\d|[1-9]?\d)
154155
){3}
155156
)
157+
\]? # See https://tools.ietf.org/html/rfc4038#section-5.1
156158
\s* # Trailing whitespace
157159
$
158160
""", re.VERBOSE | re.IGNORECASE | re.DOTALL)

tests/test_13_validate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from saml2.validate import valid_any_uri
1414
from saml2.validate import NotValid
1515
from saml2.validate import valid_anytype
16+
from saml2.validate import valid_address
1617

1718
from pytest import raises
1819

@@ -120,3 +121,10 @@ def test_valid_anytype():
120121
assert valid_anytype("P1Y2M3DT10H30M")
121122
assert valid_anytype("urn:oasis:names:tc:SAML:2.0:attrname-format:uri")
122123

124+
def test_valid_address():
125+
assert valid_address("130.239.16.3")
126+
assert valid_address("2001:8003:5555:9999:555a:5555:c77:d5c5")
127+
128+
# See https://tools.ietf.org/html/rfc4038#section-5.1 regarding
129+
# the inclusion of brackets in the ipv6 address below.
130+
assert valid_address("[2001:8003:5555:9999:555a:5555:c77:d5c5]")

0 commit comments

Comments
 (0)