Skip to content

Commit 50ef62e

Browse files
committed
fix: parse relative zone record names safely
1 parent 513ce9f commit 50ef62e

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎o2switch_cli/core/dns_service.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ def _record_name(cls, item: dict[str, object], root_domain: str) -> str:
8383
raw_name = item.get("dname") or item.get("name") or item.get("domain")
8484
if raw_name in (None, ""):
8585
raw_name = cls._decode_b64_text(item.get("dname_b64")) or root_domain
86-
return canonical_record_name(str(raw_name), root_domain)
86+
token = str(raw_name).strip()
87+
zone_name = normalize_hostname(root_domain)
88+
if not token or token == "@":
89+
return zone_name
90+
if token.endswith("."):
91+
return canonical_record_name(token, zone_name)
92+
return f"{token.lower().rstrip('.')}.{zone_name}"
8793

8894
@staticmethod
8995
def _require_serial(operation: str, root_domain: str, serial: int | None) -> int:

‎tests/test_dns_service.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,25 @@ def test_find_records_decodes_base64_zone_entries() -> None:
267267
assert matches[0].value == "203.0.113.25"
268268

269269

270+
def test_find_records_treats_non_trailing_dot_names_as_relative_zone_tokens() -> None:
271+
_, service = build_service(
272+
[
273+
{
274+
"dname_b64": b64("name.ginutech.com"),
275+
"record_type": "A",
276+
"data_b64": [b64("203.0.113.25")],
277+
"ttl": 300,
278+
"line_index": 9,
279+
}
280+
],
281+
serial=None,
282+
)
283+
assert service.find_records("name.ginutech.com") == []
284+
malformed = service.find_records("name.ginutech.com.ginutech.com")
285+
assert len(malformed) == 1
286+
assert malformed[0].name == "name.ginutech.com.ginutech.com"
287+
288+
270289
def test_delete_rejects_ambiguous_records_without_force() -> None:
271290
_, service = build_service(
272291
[

0 commit comments

Comments
 (0)