Repository: web-push-libs/vapid (language: python)

Issue:
Host validation for 'sub' does not allow domains containing hyphen
The host validation introduced in https://github.com/web-push-libs/vapid/commit/871d67da40ca7bd8fff69b1555b517029f707ea4 does not allow domains that contain hyphens to pass through the check, although they should be perfectly valid domains.

Working: test@testingthis.org

Not working: test@testing-this.org

This is also causing the issue described in https://github.com/home-assistant/core/issues/48766.


Discussion / hints:
I believe the PR that introduced this was #92 not #91 

Fix patch:
diff --git a/python/py_vapid/__init__.py b/python/py_vapid/__init__.py
index 892fe0a..9d61e9d 100644
--- a/python/py_vapid/__init__.py
+++ b/python/py_vapid/__init__.py
@@ -352,7 +352,7 @@ def verify(cls, auth):
 
 def _check_sub(sub):
     pattern =(
-        r"^(mailto:.+@((localhost|[%\w]+(\.[%\w]+)+|([0-9a-f]{1,4}):+([0-9a-f]{1,4})?)))|https:\/\/(localhost|\w+\.[\w\.]+|([0-9a-f]{1,4}:+)+([0-9a-f]{1,4})?)$"
+        r"^(mailto:.+@((localhost|[%\w-]+(\.[%\w-]+)+|([0-9a-f]{1,4}):+([0-9a-f]{1,4})?)))|https:\/\/(localhost|[\w-]+\.[\w\.-]+|([0-9a-f]{1,4}:+)+([0-9a-f]{1,4})?)$"
         )
     return re.match(pattern, sub, re.IGNORECASE) is not None
 


Test patch:
diff --git a/python/py_vapid/tests/test_vapid.py b/python/py_vapid/tests/test_vapid.py
index aaf2b05..ec11218 100644
--- a/python/py_vapid/tests/test_vapid.py
+++ b/python/py_vapid/tests/test_vapid.py
@@ -260,7 +260,9 @@ def test_sub(self):
             'mailto:me@1234::',
             'mailto:me@1234::5678',
             'mailto:admin@example.org',
+            'mailto:admin-test-case@example-test-case.test.org',
             'https://localhost',
+            'https://exmample-test-case.test.org',
             'https://8001::',
             'https://8001:1000:0001',
             'https://1.2.3.4'
@@ -277,4 +279,4 @@ def test_sub(self):
         for val in valid:
             assert _check_sub(val) is True
         for val in invalid:
-            assert _check_sub(val) is False
\ No newline at end of file
+            assert _check_sub(val) is False