]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel/types: reduced validation strictness for DomainName
authorAleš Mrázek <ales.mrazek@nic.cz>
Tue, 29 Jul 2025 06:36:08 +0000 (08:36 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 29 Jul 2025 06:36:08 +0000 (08:36 +0200)
doc/_static/config.schema.json
python/knot_resolver/datamodel/types/types.py
tests/manager/datamodel/types/test_custom_types.py

index 0670f35e3cbbf34e6e731310de97ce981d8bc576..88e11901d818a2a2a999cb15a8cf32294196da20 100644 (file)
                                                 "type": "array",
                                                 "items": {
                                                     "type": "string",
-                                                    "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$"
+                                                    "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$"
                                                 }
                                             },
                                             {
                                                 "type": "string",
-                                                "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$"
+                                                "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$"
                                             }
                                         ]
                                     }
                                 "type": "array",
                                 "items": {
                                     "type": "string",
-                                    "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$"
+                                    "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$"
                                 }
                             },
                             {
                                 "type": "string",
-                                "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$"
+                                "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$"
                             }
                         ],
                         "description": "Subtree(s) to forward."
                                                 "string",
                                                 "null"
                                             ],
-                                            "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$",
+                                            "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$",
                                             "description": "Hostname of the Forward server.",
                                             "default": null
                                         },
                         "properties": {
                             "origin": {
                                 "type": "string",
-                                "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$",
+                                "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$",
                                 "description": "Origin for the imported data. Cache prefilling is only supported for the root zone ('.')."
                             },
                             "url": {
                             ],
                             "items": {
                                 "type": "string",
-                                "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$"
+                                "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$"
                             },
                             "description": "List of domain names representing negative trust-anchors. (RFC 7646)",
                             "default": null
                                         },
                                         {
                                             "type": "string",
-                                            "pattern": "(?=^.{,253}\\.?$)(^(?!\\.)((?!-)\\.?[a-zA-Z0-9-]{,62}[a-zA-Z0-9])+\\.?$)|^\\.$"
+                                            "pattern": "(?=^.{,253}\\.?$)(^(?!-)[^.]{,62}[^.-](\\.(?!-)[^.]{,62}[^.-])*\\.?$)|^\\.$"
                                         }
                                     ]
                                 },
index 946e2b13e35d23a7f91586e82e7500b30f0befb4..fb22169effa61a2e31870eaad61a4c5c39d6df84 100644 (file)
@@ -143,15 +143,18 @@ class DomainName(StrBase):
     """
 
     _punycode: str
+    # fmt: off
     _re = re.compile(
         r"(?=^.{,253}\.?$)"  # max 253 chars
-        r"(^(?!\.)"  # do not start name with dot
-        r"((?!-)"  # do not start label with hyphen
-        r"\.?[a-zA-Z0-9-]{,62}"  # max 63 chars in label
-        r"[a-zA-Z0-9])+"  # do not end label with hyphen
-        r"\.?$)"  # end with or without '.'
+        r"(^"
+            # do not allow hyphen at the start and at the end of label
+            r"(?!-)[^.]{,62}[^.-]"  # max 63 chars in label; except dot
+            r"(\.(?!-)[^.]{,62}[^.-])*"  # start with dot; max 63 chars in label except dot
+            r"\.?"  # end with or without dot
+        r"$)"
         r"|^\.$"  # allow root-zone
     )
+    # fmt: on
 
     def __init__(self, source_value: Any, object_path: str = "/") -> None:
         super().__init__(source_value, object_path)
index 5614fd0a24e6fe1a9f90163926c150a822aa95ea..744e9b132ee198e43c6fb8b811f2abec1dcd8aef 100644 (file)
@@ -153,6 +153,7 @@ def test_escaped_str_invalid(val: Any):
     [
         ".",
         "example.com",
+        "_8443._https.example.com.",
         "this.is.example.com.",
         "test.example.com",
         "test-example.com",
@@ -174,7 +175,9 @@ def test_domain_name_valid(val: str):
     [
         "test.example..com.",
         "-example.com",
+        "-test.example.net",
         "test-.example.net",
+        "test.-example.net",
         ".example.net",
         _rand_domain(64),
         _rand_domain(1, 128),