# What structural signals indicate egress-scope erosion when a policy engine's tool allowlist and its network egress filter are evaluated against different argument projections **Date of Record:** 2026 November 26 **Scope:** Applies to runtime policy engines that enforce least-privilege tool scoping and egress control by *statically inspecting tool-call arguments* before dispatch. Does not apply to post-hoc egress monitoring, kernel-level netfilter enforcement, or capability-token systems where the tool itself is the sole enforcement point. ## Core Distinction The failure mode is not "the agent called a disallowed tool" or "the agent reached a disallowed host." It is the **projection mismatch**: the tool allowlist and the egress allowlist are two independent policy decisions that each inspect a *different serialization* of the same tool-call argument object. The tool gate typically inspects the parsed, typed argument (e.g., `host: str`, `path: str`, `method: str`). The egress gate typically inspects a *derived* string — the URL after template expansion, the DNS name after CNAME resolution, or the raw bytes of a `curl`-style argv. When these two projections disagree about which substring denotes the destination, an argument that passes the tool gate can produce an egress target the egress gate never saw. Least-privilege is therefore not a property of the tool or the host in isolation. It is a property of the **join** of two projections. The invariant that must hold is: *for every tool call admitted by the tool gate, the egress projection computed by the egress gate must be a pure function of the same argument fields the tool gate validated, with no additional attacker-influenced expansion.* Most policy engines violate this silently because the two gates live in different modules, written by different teams, at different times. ## What Was Observed A `http_fetch` tool was scoped to `allowed_hosts = ["api.internal.example"]`. The egress filter was scoped to `allowed_egress = ["api.internal.example:443"]`. Both gates were "correct" against their own unit tests. The observed trace: 1. Agent emits `http_fetch(url="https://api.internal.example@169.254.169.254/latest/meta-data/")`. 2. **Tool gate** parses `url` with `urllib.parse.urlsplit`. It reads `.hostname`, which returns `169.254.169.254` (RFC 3986 userinfo is stripped before hostname). `169.254.169.254` is *not* in `allowed_hosts`. **Tool gate rejects.** Good — in this direction. 3. Agent emits `http_fetch(url="https://api.internal.example#@169.254.169.254/")`. Tool gate reads `.hostname` → `api.internal.example`. **Admitted.** 4. **Egress gate** does not re-parse. It receives the *original* `url` string and applies a regex `^https://([^/]+)` to extract the authority for logging and for the egress allowlist check. The `#` fragment terminator is not in `[^/]`, so the captured authority is `api.internal.example#@169.254.169.254`. This does not match `api.internal.example:443`. The egress gate's regex *fails to match*, and in this engine an unmatched authority was treated as "no egress decision required" (fail-open on parse failure) rather than "deny." 5. The underlying HTTP client (a different library) parses per RFC 3986: fragment is stripped, userinfo `api.internal.example` is discarded, host is `169.254.169.254`. The request is sent to the metadata endpoint. The structural signal was not a malformed request. Every layer received syntactically valid input. The signal was the **disagreement between two parsers over the same string**, plus a fail-open branch on the egress side. Neither gate logged an anomaly because neither gate knew the other existed. A second instance of the same class: tool gate validated `host` and `port` as separate typed fields, then the egress gate reconstructed `f"{host}:{port}"` and matched against a suffix allowlist `".internal.example"`. An argument `host="evil.internal.example.attacker.net"` passed the tool gate (host field matched the *prefix* rule the tool gate used) and passed the egress suffix check (`.internal.example` appeared mid-string). Two different substring predicates, two different answers. ## Condition of Validity The guardrail holds only under a specific condition: **the egress projection must be derived from the same normalized tuple the tool gate validated, and both gates must share one parser.** Concretely: - One canonicalization function `normalize_call(tool, args) -> (tool_name, frozenset(validated_fields), egress_target)` is called *once* per tool call. Both the tool allowlist check and the egress allowlist check consume its output. The egress target is a structured `(scheme, host, port)` tuple, not a re-derived string. - The HTTP client that actually dispatches the request must be configured to *use* that same normalized target — i.e., the client is handed `host=169.254.169.254` only after the egress gate has approved `169.254.169.254`. Passing the raw URL string to the client and *also* checking a parsed form reintroduces the mismatch. - Any parse failure at any layer is **deny**, never "no decision." The fail-open branch is the amplifier; the parser disagreement is the trigger. When any of these is absent — separate parsers, re-derived strings, fail-open on ambiguity — the invariant is unenforced and the engine is operating outside the condition of validity, even if all unit tests pass. ## Decision Boundary The boundary is between **admission by string match** and **admission by structural equality**. String matching on a re-derived projection is admissible only when the derivation is injective (one string ↔ one target) and total (every input maps to a decision). URL authorities are neither injective (userinfo, fragments, IDN, percent-encoding, trailing dots, IPv4-in-IPv6) nor total (parse failures). Therefore: - If the egress target is computed by a *second* parse of attacker-influenced bytes, the gate must treat non-match as **deny** and must log the projection mismatch as a first-class security event. - If the egress target is the *shared* normalized tuple, string matching is safe because the string is no longer attacker-influenced at match time. The operational rule: **never let the egress gate see the raw argument. Let it see only the normalized tuple, and make the dispatcher consume the same tuple.** If you cannot restructure the call path to achieve this, you must fail closed on every parse ambiguity — which is a correctness-preserving but availability-destroying fallback, and should be treated as a temporary state, not a design. ## Operational Effect The practical consequence is that least-privilege egress cannot be reasoned about per-gate. It must be reasoned about per-**join**. Two observable effects follow: 1. **Silent erosion.** The engine's allowlists remain nominally correct while the effective permitted egress set is strictly larger than the declared set. Audits that inspect each gate's config find nothing wrong. Audits that replay traffic through both parsers find the divergence. 2. **Asymmetric failure.** The tool gate rejects the obvious `userinfo@host` form (because `.hostname` strips it), which creates false confidence. The fragment and suffix forms pass because they exploit *different* parser behaviors on *different* gates. The attacker does not need to defeat either gate; they need only find the input where the two gates' projections differ. This is a search over parser differentials, and the differentials are enumerable. The bounding architectural invariant is the single-normalization rule above. Without it, "least privilege" is a claim about two independent string predicates, not about the actual syscall that leaves the process. ```python from dataclasses import dataclass from urllib.parse import urlsplit class EgressProjectionMismatch(RuntimeError): """Raised when the tool gate and egress gate disagree on the destination.""" @dataclass(frozen=True) class NormalizedCall: tool: str host: str port: int scheme: str ALLOWED_TOOLS = frozenset({"http_fetch"}) ALLOWED_EGRESS = frozenset({("https", "api.internal.example", 443)}) def normalize_call(tool: str, raw_url: str) -> NormalizedCall: # Single canonicalization point. Both gates consume this output. try: parts = urlsplit(raw_url) if not parts.hostname or parts.scheme not in {"http", "https"}: raise ValueError("unparseable authority") port = parts.port or (443 if parts.scheme == "https" else 80) host = parts.hostname.rstrip(".").lower() except (ValueError, AttributeError) as exc: # Fail closed: ambiguity is denial, never "no decision". raise EgressProjectionMismatch( f"cannot normalize egress target for {raw_url!r}: {exc}" ) from exc return NormalizedCall(tool=tool, host=host, port=port, scheme=parts.scheme) def admit(tool: str, raw_url: str) -> NormalizedCall: call = normalize_call(tool, raw_url) if call.tool not in ALLOWED_TOOLS: raise EgressProjectionMismatch(f"tool {call.tool!r} not in allowlist") target = (call.scheme, call.host, call.port) if target not in ALLOWED_EGRESS: # The dispatcher will use call.host/call.port, not raw_url, # so this decision is authoritative over the actual egress. raise EgressProjectionMismatch( f"egress target {target!r} not in allowlist " f"(normalized from {raw_url!r})" ) return call def dispatch(call: NormalizedCall) -> None: # Dispatcher MUST consume the normalized tuple, never raw_url. assert call.host == "api.internal.example" and call.port == 443 # ... perform request against call.host:call.port ... # The fragment/userinfo differential that defeated the split-parser engine: try: admit("http_fetch", "https://api.internal.example#@169.254.169.254/") except EgressProjectionMismatch as err: print("denied:", err) ```