Skip to content

refactor(security): ask ipaddress for single-address egress checks - #3540

Merged
dan-petty merged 2 commits into
mainfrom
refactor/2184-use-ipaddress-for-egress-checks
Nov 4, 2026
Merged

dan-petty merged 2 commits into
mainfrom
refactor/2184-use-ipaddress-for-egress-checks

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The single-address egress check tells a public address from a non-public one. It used a block list that copied the private module pydantic_ai._ssrf. That module has no API promise, so the copy could drift with each upgrade.

The check now asks Python's ipaddress (is_global, is_multicast) about each address and about each IPv4 address that it embeds. The code keeps only the rules that ipaddress lacks, each with an RFC comment: NAT64, IPv4-compatible, ISATAP and the whole block 192.0.0.0/24. The Teredo client comes from IPv6Address.teredo. CONST_PRIVATE_NETWORKS stays for the overlap test of a range. A table test over the IANA registries holds each block to is_global.

No answer of is_non_public_ip changes.

Closes #2184
Change: openspec/changes/archive/2026-11-04-2184-the-egress-checks-take-their-non/

The single-address egress check took its blocks from a hand-kept list that copied the private
module pydantic_ai._ssrf. It now asks ipaddress (is_global, is_multicast) and keeps only the rules
that ipaddress lacks: NAT64, IPv4-compatible, ISATAP and the block 192.0.0.0/24. A table test
pins the answers over the IANA special-purpose registries.
@dan-petty dan-petty added type/refactor Type refactor: a new structure, same behavior scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault labels Nov 4, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results (local, before push):

  • New table test tests/core/test_non_public_ip_table.py: 106 passed. It passed on the base before any edit of src/. With the NAT64 loop removed, 4 NAT64 rows failed.
  • tests/core/test_validation.py, tests/http, tests/security, tests/sandbox: 2004 passed, 1 skipped.
  • devops ci run once: all checks passed except security, where bandit B104 flagged the literal "0.0.0.0" in the new test. I replaced it with "0.0.0.1" (same block). Bandit on the changed files is clean now.
  • Not a fix PR, so no fail-to-pass run.

@dan-petty
dan-petty marked this pull request as ready for review November 4, 2026 23:13
@dan-petty
dan-petty merged commit 4485be2 into main Nov 4, 2026
23 checks passed
@dan-petty
dan-petty deleted the refactor/2184-use-ipaddress-for-egress-checks branch November 4, 2026 23:15
dan-petty-release Bot added a commit that referenced this pull request Nov 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.56.5](v0.56.4...v0.56.5)
(2026-11-04)


### Code Refactoring

* **security:** ask ipaddress for single-address egress checks
([#3540](#3540))
([4485be2](4485be2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/refactor Type refactor: a new structure, same behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(security): the egress checks take their non-public address rules from a maintained source, not a hand-kept copy of pydantic-ai's private blocks

1 participant