Repository navigation
Description
What happened
The SSRF and egress checks in core/validation.py read legacy numeric hosts, such as 0177.0.0.1, 127.1 and 2130706433, with a parser that devops-cli wrote itself (_parse_part, _combine_ipv4_parts, _parse_legacy_ipv4). AGENTS.md and #1107 make a hand-rolled address parser a defect. Some of its forms and some classifier branches have no test, and two branches cannot run.
- No test sends an octal form (
0177.0.0.1) or a three-part form (127.0.1). The one-part, two-part and hex forms have tests. - No test checks that
is_private_iptreats a value that does not parse as private, or that_parse_ipdrops an IPv6 zone ID before it classifies the address. _enforce_non_private_ssrfchecks for cloud metadata again, butvalidate_url, its only caller, makes the same check first. So theraisecannot run.parse_numeric_ipcatchesOSErrorandValueErrorfrom_parse_legacy_ipv4, which raises neither._combine_ipv4_partshas areturn Nonefor more than four parts that its only caller already excludes.
What should happen
The legacy forms are read by the parser that the resolver itself uses. socket.getaddrinfo(host, None, flags=socket.AI_NUMERICHOST) parses a numeric host with the C library's own rules and makes no DNS query. The hermetic floor already lets this call through (tests/conftest.py:311-323). ipaddress.ip_address then classifies the result.
socket.inet_aton is not the answer: pyproject.toml:141-145 bans it (TID251, #1107).
Checked on 2026-10-24 with Python 3.14.7 on glibc: getaddrinfo with AI_NUMERICHOST returns 127.0.0.1 for 0177.0.0.1, 127.1, 127.0.1, 2130706433, 0x7f.1 and 0x7f000001, and refuses 08.0.0.1 and 1.2.3.4 x.
Evidence
At b170358:
src/devops_cli/core/validation.py:198-256:_parse_part,_combine_ipv4_parts,_parse_legacy_ipv4andparse_numeric_ip.:140-148and:172-174: the zone-ID drop and the unparsable-is-private default. Lines 144-147 and 174 were not covered in CI at f4d7066.:208(octal) and:224-225(three parts) were not covered.:612-617(_enforce_non_private_ssrf) repeats the check at:685-689(validate_url). Line 614 was not covered.:229and:255-256cannot run.- Callers:
core/validation.py:278,:311,:316,:476;security/reference_extractor.py:101,:103.
Acceptance criteria
- Tests first:
validate_url(..., allow_private=False)andis_loopback_or_private_hostrefusehttp://0177.0.0.1/andhttp://127.0.1/, and the classifier treatsfe80::1%eth0as link-local. Each test fails on a parser that drops the form. - A test shows that
is_private_ipreturnsTruefor a value that does not parse. -
parse_numeric_ipreads legacy forms withsocket.getaddrinfo(..., flags=socket.AI_NUMERICHOST)andipaddress._parse_part,_combine_ipv4_partsand_parse_legacy_ipv4are deleted. If refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's DNS seam has landed, the call goes through it. - The repeated metadata check in
_enforce_non_private_ssrfand the unreachable branches at:229and:255-256are deleted. - The existing tests of the one-part, two-part and hex forms (
tests/test_reference_extractor.py:138-140,tests/test_builtin_tools.py:307) still pass. - No test starts a program or makes a DNS query (docs/TESTING.md).
-
uv run devops cipasses, theconstructsrow included.
Related: #1107 (the rule and the ban), #1314 (the DNS seam), #1381 (the egress-checked clients).
regression of #1107
Proposed design
Problem statement
The SSRF and egress checks in core/validation.py parse legacy numeric IP hosts with a hand-written parser. AGENTS.md and issue #1107 make a hand-rolled address parser a defect. Some parser forms and classifier branches have no test, and two branches cannot run. The fix replaces the parser with socket.getaddrinfo and the AI_NUMERICHOST flag. This call uses the C library's own parsing rules and makes no DNS query.
Acceptance criteria
- Criterion 1: validate_url and is_loopback_or_private_host refuse
http://0177.0.0.1/andhttp://127.0.1/, and the classifier treats fe80::1%eth0 as link-local.
Verification: Each test fails on a parser that drops the form. Run uv run pytest tests/test_reference_extractor.py tests/test_builtin_tools.py. - Criterion 2: is_private_ip returns True for a value that does not parse.
Verification: Run the new test with uv run pytest -k is_private_ip. - Criterion 3: parse_numeric_ip reads legacy forms with socket.getaddrinfo and ipaddress. The functions _parse_part, _combine_ipv4_parts and _parse_legacy_ipv4 are deleted.
Verification: Run uv run pytest tests/test_reference_extractor.py tests/test_builtin_tools.py. Confirm the three functions are absent from src/devops_cli/core/validation.py. - Criterion 4: The repeated metadata check in _enforce_non_private_ssrf and the unreachable branches are deleted.
Verification: Confirm the repeated check and the unreachable return None are absent from src/devops_cli/core/validation.py. - Criterion 5: The existing tests for one-part, two-part and hex forms still pass.
Verification: Run uv run pytest tests/test_reference_extractor.py tests/test_builtin_tools.py -k 'numeric or ip'. - Criterion 6: No test starts a program or makes a DNS query.
Verification: The hermetic floor in tests/conftest.py fails a test that starts a program or makes an external DNS lookup. - Criterion 7: uv run devops ci passes, including the constructs row.
Verification: Run uv run devops ci and confirm all checks pass.
Key questions
- Can socket.getaddrinfo with AI_NUMERICHOST parse all legacy numeric IP forms without a DNS query?: Yes. Verified on Python 3.14.7 on glibc: it returns 127.0.0.1 for 0177.0.0.1, 127.1, 127.0.1, 2130706433, 0x7f.1 and 0x7f000001, and refuses 08.0.0.1 and 1.2.3.4 x. [sources: tests/conftest.py:311-323]
- Is socket.inet_aton available as an alternative parser?: No. pyproject.toml bans it under TID251 (issue feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107). [sources: pyproject.toml:141-145] - Does the hermetic floor allow socket.getaddrinfo with AI_NUMERICHOST in tests?: Yes. The guarded_getaddrinfo in tests/conftest.py lets the call through when the AI_NUMERICHOST flag is set. [sources: tests/conftest.py:311-323]
- Should the getaddrinfo call go through the DNS seam from issue refactor(cli): Unify HTTP and DNS seams with shared fakes #1314?: If refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's DNS seam has landed, the call goes through it. Otherwise, call socket.getaddrinfo directly. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 24, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The candidate proposes a refactor of the security validation logic to use standard library functions instead of a custom parser.This change fixes a security issue by improving how numeric IP addresses are parsed and validated.The change improves security by using the standard library's robust parsing instead of a hand-written parser with known defects.The change requires replacing the custom parser with getaddrinfo calls and updating tests, but does not introduce new functionality.dan-petty commentedon Oct 27, 2026
Status set to Ready at ff47504 (see proposed design in issue body).
devops-cli-service commentedon Nov 1, 2026
Staged: branch
refactor/2152-the-egress-checks-read-legacy-numeric, draft pull request #2971. The pull request plans the item and closes no issue.The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:
These paths of the plan are no file on the default branch, and no group creates them:
tests/test_reference_extractor.py. A person checks that the plan names them right.docs(openspec): plan #2152 replace legacy IPv4 parser (#2971)
docs(openspec): fix plan #2152 premise, paths and tests (#3081)
docs(openspec): fix plan #2184 keep NAT64 and the range list