Skip to content

fix(network): address Copilot review (allow-list typing + private-range hoisting) - #4

Merged
ajram23 merged 1 commit into
mainfrom
fix/address-copilot-review
Jun 3, 2026
Merged

fix(network): address Copilot review (allow-list typing + private-range hoisting)#4
ajram23 merged 1 commit into
mainfrom
fix/address-copilot-review

Conversation

@ajram23

@ajram23 ajram23 commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Addresses the 4 Copilot review comments on the network wiring (upstream PR dbreunig#7 / our fork's ported allow-list code). All 4 are in the TS→Python port of Vercel's allow-list.ts — behavior was faithful, Python typing/idiom was not.

Fixes

Copilot comment Fix
types.py allowed_url_prefixes typed list[str | AllowedUrl] but dict entries are accepted widen to list[str | AllowedUrl | dict[str, Any]]
_validate_allow_list(entries: list[str | AllowedUrl]) same gap same widen
_is_private_ipv4 rebuilds 14 IPv4Network objects every call hoist to module const _PRIVATE_IPV4_NETWORKS
_is_private_ipv6 same (incl. 2002::/16) hoist to _PRIVATE_IPV6_NETWORKS + _SIXTOFOUR_NETWORK

Plus a related typing cleanup the type-checker flagged in the same family: firewall_headers' local transforms annotated Sequence[...] (covariant) instead of list[...] (invariant), clearing the reportAssignmentType between the dict and AllowedUrl.transform branches.

Verification

  • pytest tests/test_commands/ tests/test_network.py2297 passed, 1 skipped; all private-range tests pass.
  • ruff clean on changed lines; pyright reportAssignmentType cleared.
  • No behavior change — pure typing accuracy + import-time precompute.

Deliberately scoped out (separate, grounded follow-up)

Importing AbstractResolver properly (to clear the aiohttp.abc.AbstractResolver access warning) surfaces a genuine deeper issue: _PinnedResolver.resolve doesn't conform to aiohttp's typed List[ResolveResult] return, plus a pre-existing tuple-type mismatch in _resolve_host. That's security-sensitive DNS-rebinding code and needs aiohttp's resolver contract grounded — not a drive-by here. Left as-is. Also out of scope: 6 pre-existing UP035/UP045 ruff style lints in types.py (unrelated; CI doesn't run ruff).

Four items from the Copilot review of the network/allow-list code (a port of
Vercel's TS just-bash), all in the ported allow-list/private-range surface:

- Widen `NetworkConfig.allowed_url_prefixes` and `_validate_allow_list` from
  `list[str | AllowedUrl]` to `list[str | AllowedUrl | dict[str, Any]]`. The
  runtime already accepts dict-shaped entries (`_entry_url`, `_validate_allow_list`,
  `firewall_headers` all branch on `isinstance(entry, dict)`); the annotation
  just didn't model the third shape carried over from the TS object literals.
- Hoist the private-range CIDR tables out of `_is_private_ipv4`/`_is_private_ipv6`
  into module-level constants (`_PRIVATE_IPV4_NETWORKS`, `_PRIVATE_IPV6_NETWORKS`,
  `_SIXTOFOUR_NETWORK`). They were rebuilt on every call — and this is the hot
  path for `deny_private_ranges=True` (hostname + each resolved address).
- Annotate `firewall_headers`' local `transforms` as `Sequence[...]` (covariant)
  instead of `list[...]` (invariant), clearing the assignment-type mismatch
  between the dict and `AllowedUrl.transform` branches.

Behavior unchanged; 2297 tests pass (incl. all private-range tests).

NOT included (deliberately scoped out): the DNS-resolver typing cluster
(`_PinnedResolver.resolve` not conforming to aiohttp's `List[ResolveResult]`,
the `_resolve_host` tuple type, `aiohttp.abc.AbstractResolver` access). Giving
pyright the real base type surfaces a genuine interface-conformance question on
security-sensitive rebinding-protection code that deserves its own grounded change.
@ajram23
ajram23 merged commit f9d558f into main Jun 3, 2026
3 checks passed
@ajram23

ajram23 commented Jun 3, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai can you please review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant