Conversation
network_rule_matches runs every rule through urlsplit before fnmatchcase, and the two disagree on three characters. urlsplit reads '?' as a query, '#' as a fragment and '[...]' as an IPv6 literal, so the rule api?.example.com quietly becomes the host "api", [a-z]*.com becomes "a-z" (or raises inside the matcher, which returns False), and https:// on its own becomes the host "https". None of it raised: an egress allowlist with a typo narrowed to a different destination, or to nothing, silently. check_network_rule runs from the policy validator over every allow and block rule. '?' and '#' are refused outright, a rule whose urlsplit raises or yields no host is refused with the parser's own message, and brackets are accepted only around an IPv6 address. Rules that already matched correctly -- bare hosts, *.example.com, origins with schemes and ports, [::1]:8080 -- validate as before. Task-level rules reach the same check through with_task_network_policy's model_validate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refuse a network-policy rule at config time when
network_rule_matcheswould read it as something other than the glob it looks like.The matcher runs every rule through
urlsplitand thenfnmatchcase. Those two disagree on three characters:urlsplittreats?as the start of a query,#as a fragment, and[...]as an IPv6 literal, and it does so beforefnmatchever sees the rule. So onmain:urlsplitleaves as the hostapi?.example.comapiapi, neverapi1.example.com[a-z]*.coma-z(3.10) /ValueError(3.11+)a-z, or nothinga#b.comaahttps://httpshttpsNone of that raises. An egress allowlist with a typo in it narrows to a different destination, or to nothing, silently — and this is the policy the Docker proxy and the Prime/Modal providers enforce, so it is the wrong place to be quiet.
Change
check_network_ruleruns fromvalidate_network_policyover every allow and block rule (*exempt):?and#are refused outright, a rule whoseurlsplitraises or yields no host is refused with the parser's own message, and a bracketed rule is accepted only if the bracket holds an IPv6 address. Every rule that matched correctly before still validates: bare hosts,*.example.com, origins with schemes and ports,[::1]:8080.with_task_network_policygoes throughmodel_validate, so task-level rules get the same check.Validation
No new tests, per AGENTS.md. Temporary script against this branch:
uv run ruff checkanduv run ruff format --checkare clean on the touched file. The fullpytest tests/run does not collect on this machine (an unrelatedanthropic.types.betaimport in the environment here), andpre-commit's uv hook rejects the lockfile formatting under this uv version, so those two were not run locally.Note
Reject malformed network rules in
NetworkPolicyConfigvalidationruntime.check_network_ruleto validate each rule before the matcher processes it. Accepts the unrestricted*rule; rejects?and#delimiters, rules without a host, invalid ports, and bracketed hosts that are not valid IPv6 literals.NetworkPolicyConfig.validate_network_policynow runs every entry in the normalized allow and block lists throughcheck_network_rule, raising a rule-specificValueErroron failure.allowandblockentries in runtime.py for these patterns.Macroscope summarized 58de16f.