Skip to content

fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes #887

Closed

Description

@dan-petty

Problem

Lines cited at dcafadf.
At 132ecc5, CONST_LOCAL_DOMAIN_SUFFIXES moved to config/constants.py:2546-2552; no other cited line moved.

This issue's earlier design (a list of reserved special-use names plus a new "configured private zones" setting) is replaced by the Public Suffix List (PSL) through tldextract, which is already a direct dependency, and DNS-name comparison through dnspython. The scanner's hostname list is not part of this item; it stays with #431 (see Key questions).

  • Several hand-written local-name tests, each with its own list:
    • CONST_LOCAL_DOMAIN_SUFFIXES (config/constants.py:2512-2518: .local, .localhost, .cluster.local, .internal, .lan), matched with endswith in _is_fqdn_url (commands/k8s/networking.py:255-277, the suffix check at :267-270) and in pricing's _is_local_host (ai/spend/pricing.py:90-101, the check at :93);
    • .endswith(".local") in is_loopback_or_private_host (core/validation.py:157) and validate_url_egress (:216);
    • a ("localhost", "host.docker.internal") tuple in the sandbox local-whitelist check (sandbox/models.py:129-133);
    • host.endswith(f".{domain}") against k8s.domain and cloudflare.domain in pricing (ai/spend/pricing.py:51-60, the check at :58).
  • A lookalike Ingress host is written into config. _select_best_ingress_host (commands/k8s/networking.py:652-661) matches with h.lower().endswith(norm) (:659). For the domain example.com it picks grafana.evilexample.com over grafana.example.com, and configure-urls writes https://grafana.evilexample.com into config (:677-679, :719-727; the domain comes from k8s.domain or cloudflare.domain, :778-780). A preferred domain written EXAMPLE.COM. never matches and falls back to the first host. Both behaviours confirmed by an offline probe.
  • _is_fqdn_url is inconsistent. It treats names under lan and internal as local, but returns True for grafana.corp, grafana.home.arpa, grafana.test, ollama.home and the bare public suffix co.uk (offline probe).
    • Its only caller is _should_update_url (:280-296, the call at :292). That function keeps a configured URL from being replaced by a discovered IP, NodePort or loopback URL, but only when _is_fqdn_url accepts the configured host (pinned by tests/test_k8s_networking.py:255-263).
    • At dcafadf, _should_update_url("https://grafana.corp", "http://192.0.2.4:30080") is False (kept), while _should_update_url("https://node1.example.internal", "http://192.0.2.4:30080") is True (replaced).
  • Pricing misses common local names. _is_local_host counts names under lan as local but grafana.corp, x.test, a single-label name and x.onion as remote (offline probe).
  • An unresolvable name is classed as public. is_loopback_or_private_host("unresolvable.invalid") returns False when DNS fails (core/validation.py:152-176; pinned by tests/test_validation.py:259-260).
  • web_fetch deny-list entries can be no-ops. _in_domains (ai/common_tools.py:321-323) tests hostname.endswith(f".{d}"). blocked_domains=[".evil.com"] blocks neither evil.com nor a.evil.com (offline probe).
  • A naive library swap would get four things wrong (offline probes with dnspython 2.8.0, tldextract 5.3.2 and httpx2 2.13.0):
    • dns.name.from_text(""), "." and "@" all parse to the root name, and so does from_unicode. Every host is under root. Today allowed_domains=[""] or ["."] admits nothing; a naive swap would admit everything.
    • httpx2 and urlparse accept the hosts a..b.evil.com, evil.com.., .evil.com and a 64-character label, and dnspython raises on all of them (EmptyLabel, LabelTooLong). Today blocked_domains=["evil.com"] blocks all four; a helper that returns False on a parse error would let them through.
    • tldextract does not reject those names: a..b.evil.com, .evil.com and the 64-character label all get suffix com and a non-empty top_domain_under_public_suffix. A PSL test alone calls them public. A dns.name step after it raises a raw dns.exception out of validate_url_egress and is_loopback_or_private_host instead of their own error.
    • from_text silently uses IDNA 2003 for non-ASCII input (faß.de becomes fass.de), while httpx2 sends IDNA 2008 (xn--fa-hia.de).
  • The browser capability reads the host by hand. PlaywrightBrowser.navigate (ai/harness/agents.py:391-395) takes netloc.split(":")[0] (:392). With allowed_domains=["example.com"]:
    • http://example.com:x@8.8.8.8/ navigates, though the request goes to 8.8.8.8. A public address is needed here: with the default block_private_addresses=True, a TEST-NET address is already refused by the private-address check.
    • http://EXAMPLE.COM./ is blocked (trailing dot kept).
    • A bracketed IPv6 host is read as [2001, so allowed_domains=["2001:db8::1"] never admits http://[2001:db8::1]/.
    • The tool is a stub today, but this is its egress policy.
  • The scanner's extractor writes under the home directory. tldextract.TLDExtract(suffix_list_urls=(), fallback_to_snapshot=True) (security/reference_extractor.py:64) uses ~/.cache/python-tldextract even with the network off. Measured offline with a temporary HOME: the first run writes the JSON file and its lock, and later runs only rewrite the lock file.
  • No library ships the IANA Special-Use Domain Names registry. The PSL lists arpa and onion as ordinary ICANN suffixes, so tldextract reads grafana.home.arpa, resolver.arpa, names under in-addr.arpa and x.onion as public. Every other registry entry (localhost, local, test, invalid, example, alt), ICANN's private-use internal, and the convention zones (lan, corp, home, svc, cluster.local, single labels) already have no PSL suffix (offline probe). This issue's earlier reserved list (localhost, local, onion, home.arpa, alt, internal) covered only home.arpa under arpa. Under the PSL that leaves resolver.arpa, ipv4only.arpa and the RFC 6761 private reverse zones public.

Acceptance criteria

  • One core module, built on the libraries (proposed src/devops_cli/core/dns_names.py). tldextract and dns.name are imported on first use, not at module import.
    • One shared offline extractor: tldextract.TLDExtract(suffix_list_urls=(), fallback_to_snapshot=True, cache_dir=None). It never fetches the list and writes nothing under the home directory. security/reference_extractor.py:64 uses it too.
    • is_public_dns_name(host), in this order:
      • returns False for an IP literal (ipaddress.ip_address parses it). Callers classify IP literals with ipaddress before calling it, so 8.8.8.8 stays public at core/validation.py:157, where today's name clause sits before the IP check;
      • parses the name with dns.name.from_unicode(host, idna_codec=dns.name.IDNA_2008) and returns False (not public) on any dns.exception.DNSException. Callers that deny non-public hosts therefore refuse a malformed name with their own error and without a DNS lookup. The sandbox local whitelist still resolves such a name when the policy is generated, and pricing counts it as local;
      • lowercases before asking tldextract (it keeps case);
      • returns True only when the name has a registrable part under a PSL suffix (top_domain_under_public_suffix is non-empty, so co.uk or com alone is not a host name);
      • and the parsed name is not at or under arpa (RFC 3172) or onion (RFC 7686). Those two are the only declared names. They are dns.name.Name constants with their RFCs cited, tested with Name.is_subdomain, because no library knows them (see Problem).
    • is_at_or_under(host, domain):
      • parses both sides with dns.name.from_unicode(..., idna_codec=dns.name.IDNA_2008) and compares with is_subdomain, which also handles case and the trailing dot;
      • an IP-literal host matches only an equal ipaddress entry, never by suffix;
      • a domain that parses to the root name raises;
      • a dns.exception.DNSException from either side propagates. Each caller below states what it does with it.
  • Call sites rewired:
  • Domain fields refuse root and a leading dot when loaded. One shared pydantic type, Annotated[str, AfterValidator(...)]. It keeps an IP literal (ipaddress.ip_address) as it is. Otherwise it parses the value with dns.name.from_unicode(..., idna_codec=dns.name.IDNA_2008) and refuses root ("", ., @), a leading dot and anything dnspython rejects, naming the field.
    • List fields, checked per entry, so an empty-string entry is refused:
      • WebSearchTool and WebFetchTool (ai/agents/capabilities.py:194-195, :202-203);
      • WebFetch (:389-390);
      • Researcher.allowed_domains (ai/harness/agents.py:120) and PlaywrightBrowser.allowed_domains (:334).
    • Scalar fields k8s.domain and cloudflare.domain (config/settings.py:314, :350): a blank or whitespace-only value, from the file or the environment, is read as unset (None) before the check. k8s/template.py:42, :46 and :50 already treat a blank value as unset, so a blank value must not fail every command's settings load. Any other value gets the same check.
  • Table test (offline, parametrised). Mock hosts are example.com. Matching at or under a domain needs subdomains, and the local-name rows need other suffixes, so the lookalike, malformed-label, IDN, private-suffix and configured-domain rows below are the stated exception to the repository rule that mock hosts carry no subdomain. No other row uses one.
    • Ingress hosts grafana.evilexample.com and grafana.example.com with domain example.com: grafana.example.com is picked, and also when the domain is written EXAMPLE.COM. (the lookalike subdomain is the point). With a..b.example.com listed first, grafana.example.com is still picked (the malformed subdomain is the point).
    • is_public_dns_name is False for grafana.corp, grafana.home.arpa, grafana.test, ollama.home, co.uk, 1.2.0.192.in-addr.arpa, resolver.arpa, x.onion, localhost, 192.0.2.1 and a..b.example.com, and True for example.com and EXAMPLE.COM. (the suffix or the malformed label is the point of each False row). These rows replace test_is_fqdn_url (tests/test_k8s_networking.py:239-252).
    • _should_update_url keeps the configured URL (returns False) for ("https://grafana.corp", "http://192.0.2.4:30080") and ("https://grafana.home.arpa", "http://localhost:8080"), as today. It also keeps ("https://node1.example.internal", "http://192.0.2.4:30080"), which returns True today. It returns True for ("http://localhost:3000", "http://192.0.2.4:30080"). The private suffixes are the point; http://192.0.2.4:30080 stands for a discovered NodePort URL on an RFC 5737 address.
    • is_loopback_or_private_host(h, resolve_dns=False) is True for grafana.corp, x.alt, unresolvable.invalid and a..b.example.com, and False for 8.8.8.8.
    • validate_url_egress("http://grafana.corp/", allow_private=False) and validate_url_egress("http://a..b.example.com/", allow_private=False) raise SSRFBlockedError, with socket.getaddrinfo patched to fail the test if called. Today the second one tries DNS first.
    • web_fetch with blocked_domains=["example.com"] refuses a..b.example.com, example.com.., .example.com, a 64-character label under example.com and EXAMPLE.COM.. With allowed_domains=["example.com"], a..b.example.com and example.com.. are refused; today the domain check admits both. The malformed names are the point of the row.
    • allowed_domains=["faß.de"] admits https://faß.de/ and https://xn--fa-hia.de/ and refuses https://fass.de/ (IDN handling is the point of the row).
    • allowed_domains=[""], ["."], ["@"] and [".example.com"], and blocked_domains=[".example.com"], are refused when the capability is built. k8s.domain: "." is refused at config load, naming k8s.domain. k8s.domain: "" and k8s.domain: " " load as unset.
    • navigate with allowed_domains=["example.com"] blocks http://example.com:x@8.8.8.8/ and allows http://EXAMPLE.COM./. With block_private_addresses=False, it also blocks http://a..b.example.com/. With block_private_addresses=False and allowed_domains=["2001:db8::1"], it allows http://[2001:db8::1]/.
    • Pricing counts grafana.corp, x.test, a single-label name, x.onion and a..b.example.com as local, without raising, and 8.8.8.8 and example.com as remote. With k8s.domain: example.com, ai.example.com is local and ai.evilexample.com is not (the subdomain under the configured domain is the point).
    • Sandbox: SandboxNetworkConfig(mode="local_whitelist", local_whitelist=["node1.example.internal"]) now builds; today the model validator refuses it. Generating the policy (to_k8s_network_policy(), which resolves the entry through _resolve_local_host) with a mocked socket.getaddrinfo answering 8.8.8.8 raises ValueError. The row must generate the policy; building the model alone no longer refuses the name. A name with no public suffix is the point; a TEST-NET answer would not show it, because the stdlib classes TEST-NET as private.
  • One answer everywhere. One parametrised test runs three checks over the same host names (no IP literals) and they agree: local exactly when not public. The checks are is_public_dns_name, pricing's _is_local_host (with an empty config file, so no configured domain or AI endpoint matches) and is_loopback_or_private_host(..., resolve_dns=False).
  • No writes, no network. With HOME pointed at tmp_path, building the shared extractor and classifying a name leaves tmp_path empty, and no socket is opened.
  • No construct left:
  • Dependency. dnspython[idna]==2.8.0 is a direct dependency in pyproject.toml. fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897, which lands first, declares dnspython==2.8.0; this item adds the idna extra.
    • dnspython enables its IDNA 2008 codec only when that extra's requirement is met. Today idna 3.19 arrives only through other packages (tldextract, httpx2 and email-validator among them).
    • Without idna, from_unicode(..., IDNA_2008) raises NoIDNA2008 on any non-ASCII label, and is_public_dns_name would read every IDN as not public.
    • uv.lock gains no new package.
  • Tests:
    • tests/test_validation.py:259-260 changes as intended: unresolvable.invalid is now non-public;
    • test_is_fqdn_url (tests/test_k8s_networking.py:239-252) is replaced by the is_public_dns_name rows above;
    • these stay green unchanged: tests/test_validation.py:234-258, tests/test_k8s_networking.py:34-47 and :255-276 (as fix(k8s): tunnel sync and url setup still overwrite settings they should keep #794 leaves them), tests/test_ai_spend_pricing.py:269-302, tests/test_common_tools.py:117-149, tests/test_runtime_security_and_ssrf_hardening.py:73-110 and tests/test_harness.py:290-324;
    • tests/test_reference_extractor.py passes unchanged (the scanner keeps its own list);
    • tests stay offline, and each new test takes under 1 s.
  • uv run devops ci passes. A changelog.d fragment names the behaviour changes:
    • names without a public suffix count as local everywhere;
    • public-only egress refuses them, and names dnspython rejects, before any DNS lookup;
    • configure-urls keeps a configured URL whose host is a name when discovery finds only an IP or loopback URL. Names under lan, internal, local and cluster.local, and single-label names, used to be replaced;
    • leading-dot and root domain entries are refused, and a blank k8s.domain or cloudflare.domain reads as unset.

Key questions

  • Configured private zones, as this issue first proposed, or the PSL? Decided (owner, 2026-10-03): the PSL. Fixes use reputable libraries, never curated name lists or suffix tests in source.
    • Names without an ICANN public suffix (lan, corp, internal, home, alt, cluster.local, single labels) are local with no setting. No private zone name goes into config or source, and no migration note is needed.
    • The earlier design needed a new setting, a curated RFC list in source, and an upgrade step telling users to add lan first.
    • Cost: a gTLD newer than the bundled snapshot reads as local (refused by public-only egress before DNS, free in pricing) until the tldextract pin is bumped. The pin is exact (pyproject.toml:30, 5.3.2, released 2026-08-08).
    • At dcafadf, .github/dependabot.yml:25 points pip updates at release/v0.2.14, so no automatic bump reaches current branches today.
  • Does a configured URL on a private zone stay protected from configure-urls? (owner decision) Proposed: yes, and the rule that protects it stops using any public-suffix test.
    • At dcafadf, _should_update_url("https://grafana.corp", "http://192.0.2.4:30080") is False. Rebuilt on is_public_dns_name, _is_fqdn_url would return False for grafana.corp, the call would return True, and configure-urls would overwrite a configured .corp or .home.arpa ingress URL with a NodePort URL. That overwrite class belongs to fix(k8s): tunnel sync and url setup still overwrite settings they should keep #794.
    • Proposed rule: a configured URL whose host is a name is not replaced by a discovered URL whose host is an IP literal or loopback. A host is a name when ipaddress.ip_address does not parse it and fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897's loopback predicate does not match it. Whether it has a public suffix plays no part. _is_fqdn_url then has no caller and is deleted.
    • Side effect: configured names under lan, internal, local and cluster.local, and single-label names, are kept too; today the suffix list lets an IP or NodePort URL replace them. That keeps user settings, the direction fix(k8s): tunnel sync and url setup still overwrite settings they should keep #794 sets ("only unset or local URLs are updated"), and the changelog fragment names it.
    • The case that needs the owner: a hand-configured in-cluster URL of the form http://<service>.<namespace>.svc.cluster.local:<port> cannot be reached from outside the cluster. Today a discovered NodePort or port-forward URL replaces it; under the proposed rule it stays until the user changes it. Treating cluster.local specially would bring back a suffix test, and the cluster domain is configurable anyway.
    • Rejected alternative: keep a PSL test in the rule and name the downgrade of private-zone URLs in the changelog fragment. It overwrites the URLs a private cluster is most likely to configure.
    • fix(k8s): tunnel sync and url setup still overwrite settings they should keep #794 (v0.2.28) rewrites _should_update_url and lands first. If its rule already keeps every configured URL that is not unset, the default or loopback, the _is_fqdn_url call is gone, and this item only deletes the function and adds the table rows.
  • Which special-use names need a test beyond the PSL? Proposed: only arpa (RFC 3172) and onion (RFC 7686), matched with dns.name is_subdomain, never endswith.
    • Matching all of arpa rather than home.arpa covers every PSL-suffixed entry in the IANA registry: home.arpa, resolver.arpa, ipv4only.arpa, service.arpa, eap.arpa, 6tisch.arpa, and the private reverse zones under in-addr.arpa and ip6.arpa.
    • The rest of this issue's earlier list (localhost, local, alt, internal) needs no entry, because none of them has a PSL suffix.
    • These are data no library carries, so the two names stay declared with their RFCs cited.
  • Where does the scanner's hostname list go? Proposed: it moves to fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists #431, which already owns that file and keeps CONST_SPECIAL_USE_TLDS for URL hosts. This item does not touch is_local_or_reserved_domain (security/reference_extractor.py:263-280) or CONST_SPECIAL_USE_TLDS (config/constants.py:1048-1062).
  • Do .corp, .test, .onion and single-label names become free in pricing? Proposed: accept it. This is spend classification, not a security check, and it matches how names under lan are counted today. A name dnspython rejects is counted as local too, so pricing never raises.
  • Refuse or strip a leading dot in domain lists? Proposed: refuse at load, naming the field. A leading dot has no DNS meaning, and today it silently disables the entry.
  • Why from_unicode with IDNA 2008 everywhere, not only for IDN input? Proposed: because httpx2 sends IDNA 2008. from_text would compare faß.de as fass.de, a different host.
  • Is a new dependency needed? Proposed: no new package. dnspython 2.8.0 is already locked (via fastmcp-slim, pydantic[email] and email-validator) and becomes direct, with its idna extra.
    • It is ISC-licensed and pure Python. The last release was 2025-09-07, but the repository is active (commits on 2026-10-03) and not archived.
    • Its IDNA 2008 codec needs idna, which dnspython declares only under the idna extra. idna 3.19 is already locked, so the extra adds no package.
    • tldextract (BSD-3-Clause, commits on 2026-09-29) is already direct.

Strategic alignment

Update 2026-10-08: refinement

Every defect holds; #431, #897 and #898 landed, and #794 lands first. dnspython is already pinned (pyproject.toml:40), so only idna is added. #897's second PR is #1174; whichever lands second drops sandbox/models.py:129-132. Lines: core/validation.py:236, :334; config/constants.py:2775-2781; commands/k8s/networking.py:646-655; ai/common_tools.py:459-469.

Activity

  1. added
    type/bug
    scope/security
    priority/p3-low
    on Oct 1, 2026
  2. changed the title [-]fix(security): one local-name check from the special-use registry and configured private zones[/-] [+]fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes[/+] on Oct 3, 2026
  3. added
    priority/p2-medium
    and removed
    priority/p3-low
    on Oct 3, 2026
  4. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Cross-check from the 2026-10-08 client-library audit (checked at release/v0.2.29, 05e9388).

    PlaywrightBrowser (ai/harness/agents.py:329-479) answers every action with a canned string that a model reads as evidence. For example: "Navigated to {url}. Title: Page Title. Content loaded." (:397), "Console logs: 0 errors." and "Network requests: 200 OK (0 failed)." (:465-479).

    This item does not cover that: it only rewires the stub's host check in navigate (:391-395). #1330 does cover it, with the proposed answer "delete it" (#1330, key question on PlaywrightBrowser). No new issue is filed.

    If #1330 deletes the class, this item's PlaywrightBrowser.navigate call-site change and its navigate table rows go with it. Whichever of the two lands second drops them.

    Key question for the owner: delete the stub browser (#1330's proposal) rather than give it a real backend?

    • Proposed: yes, delete it. A real browser capability would be a feature item with its own egress design.

    Found by the 2026-10-08 client-library audit.

  5. added this to the v0.2.37 milestone on Oct 17, 2026
  6. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Moved to v0.2.37: v0.2.37 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  7. added
    status/in-progress
    on Oct 17, 2026
  8. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1618, merged into release/v0.2.37 as 4ee3e01.

    Summary

    Fixes #887

    Replaces hand-written local-domain suffix lists (CONST_LOCAL_DOMAIN_SUFFIXES, .endswith(".local"), ("localhost", "host.docker.internal")) and substring suffix checks (.endswith(...)) across egress validation, Kubernetes URL auto-configuration, AI spend pricing, web_fetch, PlaywrightBrowser.navigate, and sandbox local whitelisting with a shared offline Public Suffix List (PSL) classifier and IDNA-2008 DNS-label hierarchy comparator in src/devops_cli/core/dns_names.py.

    23 file(s) changed.

    How it was verified

    Check runs at e9b64bb:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-887-psl-local-names-and-dns-label-matching.md:

    No Acceptance Criteria section.

  9. added a commit that references this issue on Oct 20, 2026
  10. removed
    status/in-progress
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/securitytype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions