Skip to content

fix(egress-gateway): close resource URI respellings that dodge a uri rule - #229

Merged
kevin-orellana merged 18 commits into
mainfrom
feature/mcp/resource-uri-delimiter-fold
Nov 3, 2026
Merged

kevin-orellana merged 18 commits into
mainfrom
feature/mcp/resource-uri-delimiter-fold

Conversation

@abhisheksp

@abhisheksp abhisheksp commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

This policy guards a file, and before this change the agent read it anyway:

permit (principal, action == Box::Action::"mcp:call", resource)
when { context.input.server == "notes" };

@id("no_env")
forbid (principal, action == Box::Action::"mcp:call", resource)
when { context.input has uri && context.input.uri == "file:///home/op/project/.env" };

Box rewrites a resource URI to one standard form before a rule sees it, so two spellings of one
file get one decision. A rule compares text exactly. Where the rewriting was too generous about
what counts as one spelling, the workload respelled the guarded path, the forbid stopped
matching, the call fell through to the broad permit, and the log recorded an ordinary allow — while
the server's own URL parser resolved the respelling straight back to the file the rule names.

That happened on two axes, and this closes both.

A delimiter the URI leaves out, or holds and should not. A trailing # or ?, a space or a
tab anywhere, a \ in the path or the authority, or a hier-part with no // — a parser trims,
removes, or supplies each one, so the box read one resource and the server opened another.

A host that is not a host. The authority was the only component with no grammar check. The path
is parsed, so a path RFC 3986 does not spell is refused. The authority got string surgery only —
lowercase it, decode the unreserved escapes, drop a default port — and nothing judged the result.
Here is the sharp case. localhost carrying an invisible code point is a host every reference
parser resolves to localhost, so each one opens the guarded file. The box has no IDNA, so its
normalized authority never compares equal to localhost, the local-authority fold does not fire,
and the rule reads a URI naming a host nobody can resolve. The rule did not match and the file was
read.

Every row below was measured on the real decision path, and each resolves to the guarded resource
in at least two of Python urlsplit, Node, and the Rust url crate:

what the workload asks for before after
…/.env#, …/.env#x, …/.env? kept as written — no match …/.env — refused by the rule
…/.env?x, …/.env?a=1 kept as written — no match the request is refused
a tab or a space inside or before the scheme read as a custom scheme, untouched the request is refused
a trailing space in the query kept as written — no match the request is refused
a \ where the server reads a path separator kept as written — no match the request is refused
a hier-part that omits its own // or / kept as written — no match the request is refused
a host carrying an ignorable or non-ASCII character, raw or escaped kept as written — no match the request is refused
a userinfo before the host, which hides which host the URI reaches kept as written — no match the request is refused
an encoded slash in a file: path, which two of three resolvers decode into a separator kept encoded — no match, and ..%2F traverses the request is refused
a host carrying a character no host may hold kept as written — no match the request is refused
an IPv6 literal with no brackets, or a port that is not digits kept as written — no match the request is refused
a second unescaped @ kept as written — no match the request is refused
a query under http/https that carries content unchanged unchanged, deliberately

The rule the rewriting now follows is that its output is the resource the server will open.
Where a respelling folds, it folds: a fragment never reaches the server and an empty query adds
nothing, so both drop under every scheme. Where it cannot fold honestly, the request is refused,
and each refusal comes from a grammar rather than from the spelling that was reported — RFC 8089
for a file: query, RFC 9110 for a missing authority, RFC 3986 §3.2 for the authority itself, and
RFC 3986 §3.3 for the path, which was already checked.

Refusing is how the authority axis closes without implementing IDNA, and keeping the two apart is
deliberate: refusing a host that is not a host is a different change from folding every equivalent
spelling of a host that is one. The second is not here.

What this does not fix, and what it costs

The host is checked, not folded. Every spelling the grammar allows is still kept as the
workload wrote it, so two spellings of one host still reach a rule as two strings. Three classes
survive, each measured in all three parsers:

unfolded one origin, two strings
a Unicode host against the same name written as xn-- the Unicode spelling is refused rather than folded, so a rule must name the xn-- form
an IPv4 literal in any form but dotted-quad five spellings of one address
an IPv6 literal under http/https that compresses its zeros, or maps an IPv4 address two spellings of one address. Under file: every loopback spelling now folds, because the local authority is parsed rather than compared as text

The blocker on folding a port is now gone, and the fold is still not here. An earlier revision
of this description said folding a port needs host validation in the same change, because the port
fix alone made the rewriting non-idempotent on an invalid authority such as file://::. That
authority is now refused, and any port reaching the normalizer has passed a grammar that allows
only digits. So the fold is unblocked — it is left out because refusing a host that is not a host is
a different change from folding every equivalent spelling of a host that is one, and folding a port
changes which URIs a rule matches. Whoever takes it needs four things: drop an empty port, strip
leading zeros before the default-port drop, refuse a port above 65535 (which this change still
admits verbatim while Node refuses it), and drop an empty userinfo.

An http/https URI carrying userinfo is refused. RFC 9110 §4.2.4 deprecates it: a sender may
not generate one, and a recipient of a URI from an untrusted source is asked to treat its
presence as an error, "because it is likely being used to obscure the authority". The workload is
that untrusted source, and the obscuring was the measured defect — the canonical form spells the
userinfo before the host, so no rule written against a host reached https://user@notes/page, while
all three parsers read it as host notes and path /page. An empty one was worse again, because a
parser drops it and the box did not. file: keeps its userinfo, because RFC 9110 does not govern
that scheme, and stays the smaller residual. Two earlier revisions of this description got the scope
of this wrong in both directions before the RFC settled it.

A port spelling is unfolded, and under http/https that is live. A
parser reads a port as a number, so a leading zero and a bare : both drop, and an empty userinfo
and an empty password drop with them. All three parsers accept every such spelling and reach the
same origin; the box keeps what the workload wrote. An earlier revision of this description
scoped that residual to file:, on the grounds that both parsers reject it outright. That is true
for file: and false for the http/https twin.
The correction had landed on the port row and
not on the userinfo row beside it. docs/design/mcp.md now states both at the right scope.

No uri pattern names one origin and only that origin while those spellings are unfolded. The
page used to tell an operator to name the host with a like pattern instead of matching a full
uri that carries a port. Measured, that does not hold: a pattern keeping the path separator
matches none of the port spellings, because the standard form puts the port before the /, and the
only pattern that does match them also matches every host sharing that prefix. Neither reaches an
empty userinfo. The page now states what each pattern does and does not match, with a test beside
it — it was the one behaviour claim on that page with none, and the one an operator acts on.

Under file: the authority is not load-bearing, and on one resolver any host reaches the local
path.
None of the three parsers implements a remote file: URI. Node and the Rust url crate open
an empty host or localhost and refuse every other host outright, [::1] included. Python's
url2pathname ignores the host, so any host opens the same local file. So against a server built on
urlsplit, a forbid naming a file: path is dodged by any host the box keeps, not only by a
respelling of a local one. The page states that at its real width now, and gives a forbid the
pattern uri like "file://*/home/op/.env" with the catch named: * crosses a /, so it is a
suffix match that also refuses a deeper path ending in the same characters. That is the safe
direction in a forbid and a widening in a permit, so the page says not to use the shape in one.
A test pins the real reach — eleven authority spellings, three deeper paths it also refuses, and
three it does not reach.

This is the one thing I am asking you to decide on the code. Refusing a non-local file:
authority outright would close it, and it costs no URI any measured resolver opens as a remote
resource, because none of them opens one. But it refuses a shape RFC 8089 conforms to, which every
other refusal on this branch does not — the rest reject spellings with no conforming reading. That
makes it a product call about whether Box supports a remote file: URI, and it flips two assertions
this branch currently pins. Say the word and it is a short change.

The case for it got stronger while this was in review: because * crosses a /, no like pattern
can write an authority-agnostic permit on a file: path at all. Refusing a non-local authority
removes the need for the pattern instead of documenting its catch.

An encoded slash in a file: path is refused, and the http/https twin keeps it. This row
started the PR as a documented residual and is now closed under file:. The code comment called a
resolver that decodes a reserved delimiter a hypothetical; measured, two of three do it. Python's
url2pathname and the Rust url crate both turn %2F into a separator, so /home/op%2F.env
reaches the guarded file and ..%2Fetc traverses. Node refuses the URI. No file name holds a /, so
the segment names no file and the URI has no canonical form here — the same shape as the file:
query refusal. An http/https path keeps the escape, because the origin server receives it. %5C
is not refused with it: all three decode it to a literal backslash, which a POSIX name may hold, so
it names a file of its own and both ends agree on which.

A rule that names a fragment now fails open, and nothing warns. A uri equal to a URI carrying
a fragment can no longer match, and the server returns the whole document. A file: literal
carrying a query is dead text the same way. See the decision below, which would close this.

Two shapes stop working. An MCP server that accepts a query on a file: URI — to pick a line
range, say — and one that uses an opaque file: URI. Neither is evidenced: nothing in this
repository uses one and I know of no server that does, so the cost is unquantified rather than
demonstrated. A Windows-style file://localhost\C:\… is refused by the backslash gate, which a
resolver would have accepted. An operator meets a refusal at the door rather than a quiet change of
behaviour, so a setup depending on one of these fails on the first call instead of being
reinterpreted. Say if you would rather have a fold for any of them.

What an operator reads changes. A uri literal written against the old standard form may no
longer match, because more URIs are refused. Both MCP doors read the one rewriting function,
through two entry points, and the server is sent the standard form, so the decision and the call
cannot read different resources.

The sibling cases named alongside the reported one. The report that started this names four
more for this canonicalizer — an encoded slash, a userinfo, an IPv6 literal, and a port. Each of
the four has its non-conforming half closed here, and three have their folding half left open: a second
@ and any userinfo at all are refused under http/https, and a file: userinfo is not folded; an
unbracketed, unclosed, bad-hex, or zone-identified IPv6 literal is refused while zero-compression
and IPv4-mapped forms are not folded; a port that is not digits is refused while a leading zero and
a bare : are not folded, though the blocker on folding those is now gone. The encoded-slash row is
closed under file: — refused outright — and deliberately open under http/https, where the
origin server receives the escape. Whoever resolves that report should
read it as three halves closed and four folds outstanding.

The one decision that is not mine

The loader could refuse a uri literal that can never match — one that is not a fixed point of
this rewriting function, or that the function refuses outright. That turns the fragment case above
from a silent fail-open into a load error.

It needs your agreement, because it means the loader calling this function, which adds a 45th name
to the frozen egress-gateway public list.

There is a precedent on the same file. crates/egress-gateway/AGENTS.md already records this shape
for hosts: "normalize_host and is_bindable_host are the one host spelling, exported for
policy::spelling, which refuses a host literal no bound host can equal."
The same file says a
45th name needs a named external caller, and policy::spelling is that caller.

Related Issues

None.

Type of Change

Bug fix

Testing

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

cargo test --all-features on this branch: 242 passed in egress-gateway across 7 binaries, 540
passed with 7 ignored in policy across 31, and 1046 passed with 6 ignored in box across 49.
The box suite needs EXPERIMENTAL_LINUX_SUPPORT=TRUE on this x86_64 Linux host. One skipping:
line, in box: a live library reload needs a usable containment backend. The gateway builds with
--all-features and with --no-default-features. cargo fmt --all --check is clean, and clippy
prints no warning owned by either crate I touched; the warnings it prints are in the vendored
crates/shell.

Counts moved against an earlier revision of this description because main was merged in: it
rewrote the gateway's MITM layer and removed test targets with it, and added to policy.

Test What it pins
uri.rs::an_authority_outside_rfc_3986_is_refused 38 spellings refuse, one per production the spelling breaks rather than one per character someone listed.
uri.rs::every_authority_the_grammar_spells_still_canonicalizes The over-rejection control: 42 spellings the grammar allows still canonicalize, across every production — sub-delims, an escape, an IPv4 or IPv6 literal, an IPvFuture literal, a userinfo, and a port.
uri.rs::the_authority_refusal_follows_the_grammar_in_both_directions Every generated spelling in the authority position, both ways: the grammar decides and nothing else does. Over 1,000 in each direction.
uri.rs::the_emitted_authority_is_itself_rfc_3986 The authority the box emits conforms too, so the standard form is its own fixed point on this axis.
uri.rs::a_host_holding_an_escape_of_a_reserved_or_non_ascii_octet_is_refused Thirteen escaped spellings refuse, and five that must keep folding still fold — an escape of an unreserved octet, a userinfo escape, and an IPv6 literal.
uri.rs::the_host_emits_no_percent_escape Over 1,000 canonical forms, none with an escape in the host, and the path still emits uppercase hex.
uri.rs::an_http_uri_carrying_userinfo_is_refused Twelve spellings refuse — empty, password-only, escaped, port-qualified, and over an IPv6 literal. file: keeps two, and a %40 in a path is not an @.
uri.rs::an_encoded_slash_in_a_file_path_is_refused Ten file: spellings refuse across all three hier-part forms, including the traversal; the http/https twin keeps the escape, and %5C, %252F, and an unreserved escape all still ride.
uri.rs::a_file_uri_that_carries_a_query_is_refused Eleven spellings refuse, across all three hier-part forms.
uri.rs::no_generated_file_uri_with_a_query_gets_a_canonical_form No generated file: spelling carrying a query gets a standard form, with the https twin of each as an over-folding control.
uri.rs::a_fragment_or_an_empty_query_names_no_second_resource Eight spellings of one guarded file give one standard form.
uri.rs::an_opaque_hier_part_is_refused_because_a_parser_supplies_the_delimiters Seven opaque spellings refuse.
uri.rs::an_http_uri_with_no_authority_is_refused_and_file_keeps_its_local_one Eight authority-less spellings refuse, and file:/x still completes.
uri.rs::a_resource_uri_a_url_parser_reads_differently_is_refused Twenty-one spellings refuse — the scheme position, the two that put the character after the colon, three in the query, and eight using \ at each count of leading \ — while a custom scheme and a scheme-less string stay verbatim.
uri.rs::canonicalize_resource_uri_is_idempotent The standard form is its own fixed point over the widened alphabet.
admission.rs::an_appended_delimiter_cannot_dodge_an_exact_uri_forbid The real decision path for the delimiter axis: nineteen spellings refused, a sibling file the rule does not name still reads, and an http query still rides through.
admission.rs::a_host_spelling_outside_the_uri_grammar_cannot_dodge_an_exact_uri_forbid The real decision path for the authority axis: the 16 raw spellings and 5 escaped ones refused, and eight conforming authorities the rules do not name still read.
admission.rs::a_uri_like_pattern_cannot_name_one_origin_and_only_that_origin Each half of the pattern claim the page makes, including the hosts the wider pattern reaches, and five userinfo spellings that reach neither pattern.
admission.rs::a_file_forbid_pattern_is_a_suffix_match_across_every_authority The file: pattern the page recommends: eleven authority spellings (six local, five not), the three deeper paths its * also reaches, and three paths it does not.

What was measured, and how

A battery of 243 resource-URI spellings was run through the box's standard form and, side by side,
through Node, Python urlsplit, and the Rust url crate, then grouped by the resource each parser
says the spelling names. On the authority axis, 36 of those spellings carried an authority RFC 3986
forbids and the box emitted every one of them. Sixteen of the 36 are the live ones: both reference
parsers resolved a host OTHER than the one the box emitted, so a rule read one resource and the
server opened another. Sixteen more are spellings both parsers reject outright, where refusing
costs nothing. The remaining four are hosts both parsers pass through unchanged, so refusing them
closes no measured respelling — it refuses a host that is not a host.

After the change: 36 refused, 0 newly accepted, 0 spellings refused whose authority conforms, and 0
accepted whose authority does not.

Review then found that the grammar allows an escape in a host, so the check reached the raw spelling
of an ignorable code point and not the escaped one — and the escaped one still opens the guarded
file in Node and the Rust url crate, and in Python, which ignores the host entirely. I confirmed
that against all three parsers before fixing it. An escaped sub-delim is the one class both parsers
accept, and they decode it while the box kept it encoded, so it was two strings for one host too.
Every escape left after the unreserved decode is now refused, which also makes the host emit no
escape at all — so the escape-hex-case correction an earlier commit on this branch made to the host
is reverted, because there is nothing left to case.

What the property test does and does not prove

the_authority_refusal_follows_the_grammar_in_both_directions uses the function under test as its
own oracle, so it pins the wiring — the check is reached for every authority and no earlier
refusal preempts it — and not conformance to §3.2. The conformance work is done by the two
hand-written lists, 38 refused and 42 accepted, and a mutation that refuses a sub-delim fails the
accepted one. Adversarial review closed the remaining axis independently: it wrote an RFC 3986 ABNF
oracle from the grammar and asserted both directions over roughly 245,000 authorities across three
schemes, with zero counterexamples in either direction, and separately re-checked that a
conforming authority normalizes to a conforming one over the same set.

The grammar, and why it is read rather than restated

The check parses the authority in the authority position of a reference, using the same RFC 3986
parser this module already uses for the path. So the rule is §3.2 itself — [ userinfo "@" ] host [ ":" port ], with host as IP-literal / IPv4address / reg-name — and not a character list one
pass happened to enumerate. That matters in both directions: a registered name legitimately holds
_, ~, and every sub-delim, and 256.1.1.1 is a valid name rather than an invalid address, so a
hand-written check would have refused hosts that must keep loading. It also reads the authority as
authored rather than as emitted, because a conforming authority normalizes to a conforming one —
the_emitted_authority_is_itself_rfc_3986 is the pin for that half.

Mutation testing, in both directions

Each was applied alone, observed to fail, and restored.

Mutation Direction What failed
Remove the authority grammar check under three uri.rs tests, and the decision-path test
Enumerate the characters one pass found, instead of the grammar under one uri.rs test, and the decision-path test
Judge the authority the function emits, not the one it was handed under two uri.rs tests
Skip the check for file:, whose parsers reject more anyway under three uri.rs tests, and the decision-path test
Drop the whole-string guard on the parsed authority under the_grammar_check_reads_the_whole_authority
Remove the host escape refusal under two uri.rs tests, and the decision-path test
Remove the encoded-slash refusal under four uri.rs tests, and the decision-path test
Remove the userinfo refusal under three uri.rs tests, and the decision-path test
Refuse a userinfo under file: too over three uri.rs tests, and the decision-path test
Refuse only an EMPTY userinfo under three uri.rs tests, and the decision-path test
Refuse an encoded slash under every scheme over five uri.rs tests
Refuse an encoded backslash with it over the encoded-slash test
Refuse every reserved escape in a file: path over two uri.rs tests
Refuse any % in the host, before the unreserved decode over seven uri.rs tests, and the decision-path test
Apply the escape refusal to the userinfo as well as the host over two uri.rs tests
Refuse a sub-delim in the authority over the over-rejection control
Refuse any port over five uri.rs tests, and the decision-path test
Refuse an empty userinfo over the over-rejection control, and the decision-path test
Refuse a numeric registered name that is not a valid IPv4 address over four uri.rs tests, including the idempotency property
Remove the file: query refusal under both file:-query uri.rs tests, and the decision-path test
Keep the fragment under three uri.rs tests
Keep the empty query under two uri.rs tests
Refuse an http/https query too over four uri.rs tests, and the decision-path test
Fold a file: query away instead of refusing over both file:-query uri.rs tests
Remove the space / control-character refusal under the scheme test, and the decision-path test
Compare the scheme before and after parser preparation only under the scheme test, and the decision-path test
Refuse a space / control character under every scheme over the refusal test
Drop \ from the refused set under the refusal test, and the decision-path test
Refuse \ under every scheme over the refusal test
Keep the opaque branch verbatim under the opaque test, and the decision-path test
Allow an http URI with no authority under the authority test
Require an authority for file: too over six tests, including the idempotency property

Two are worth calling out. "Enumerate the characters one pass found" is the shape a reviewer
would reasonably propose instead of a grammar, and running it as a mutation is how I checked that
the test pins §3.2 rather than the list of characters that happened to be measured: it leaves a
bad port, a malformed IPv6 literal, and a zone identifier accepted. "Compare the scheme before
and after parser preparation only"
was the narrower fix suggested in review on the delimiter
axis, and it leaves open the two spellings that put the character after the colon and does not
reach the query position at all.

Idempotence

The standard form must be its own fixed point, or a second pass over a forwarded URI would change
it. Re-run after this change over a wider alphabet and more prefixes than the in-repo property
test: 6,438,315 inputs, 870,275 accepted, 0 non-fixed-points, and 0 emitted authorities
outside §3.2
. The same sweep on the code before this change: 2,508,672 accepted, 0
non-fixed-points, and emitted authorities outside §3.2 at every prefix. The drop of 1,638,397 in
what is accepted is the set whose authority the grammar forbids, plus the escaped-host,
encoded-slash, and userinfo classes.

The in-repo property test gains @, [, ], _, and | in its alphabet. Without them no prefix
could produce an authority the grammar refuses, so it could not see this class at all — the same
reason it gained #, ?, :, a tab, a space, and \ on the delimiter axis.

Not run

strands-box-containment and test-integ refuse on this x86_64 Linux host and are not green:
the trampoline reports that Linux containment supports aarch64. That is 6 failures across three
targets in containment, in a crate this change does not touch, and test-integ cannot launch a
workload at all, with or without EXPERIMENTAL_LINUX_SUPPORT=TRUE. So the MCP doors have no
end-to-end run here. The wiring is covered by the two decision-path tests above, and I read both
call sites to confirm each forwards the frame it judged.

One policy test, an_observer_with_a_file_target_costs_at_most_half_a_decision_more, failed once
while the machine was compiling in parallel — a p50 ratio of 1.63 against a limit of 1.5. It
measures 1.01 on a quiet machine and passed in the run reported above. It is in a crate this change
does not touch.

Documentation. docs/design/mcp.md gains the authority grammar, the four host forms that stay
unfolded, the re-scoped port and userinfo residual, and what a like pattern does and does not
match. docs/user/mcp-policy.md gains a troubleshooting row for each refusal an operator can meet.
No committed policy under examples/, and no other page or skill, holds a context.input.uri
literal.

The local file: authority is parsed, not compared. Review found a claim this branch already
made that the code did not hold: the_finding_bypass_classes_canonicalize_to_one_identity says
every equivalent spelling of "this machine" collapses, naming loopback IP literals, while the
comparison was text against two spellings. Node resolves file://[::0001]/home/op/.env to the local
file, and the box emitted it unfolded, so it matched no rule. The literal is now parsed and a
loopback or IPv4-mapped-loopback address folds.

One false sentence in this description, corrected. An earlier revision said the canonical form
uppercases the hex of every escape that stays. A query rides through verbatim and so does a
userinfo, so it holds for the path alone.

One dead branch deleted. The authority match held an arm no URI could reach — reaching it with
no authority implies the scheme is file:, because the refusal above takes the absent and the
empty cases for every other scheme — and its comment told the next editor the opposite of the rule.
Review suggested unreachable!(); the branch is deleted instead, because that function is on the
request path in the box's trusted process and the value reaching it is workload-authored, so a
panic there is a worse outcome than the string it replaces. The 6,438,315-input sweep gives
identical numbers before and after.

Merged, not rebased. main moved under this branch and conflicted in the MCP troubleshooting
table, where both sides add a row. Both rows are kept. The branch has heads a reviewer has already
read, so the history is not rewritten.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly — docs/design/mcp.md and docs/user/mcp-policy.md
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

A uri-keyed `forbid` stopped protecting a resource as soon as the workload appended one
byte. The canonical form of an MCP resource URI kept a trailing `#` or `?`, and kept any
fragment, so `file:///x#` was a different string from `file:///x`. A rule compares text
exactly, so an exact or an end-anchored `forbid` on the bare URI matched neither
respelling. The call then rode the coarse `mcp:call` permit and the box recorded an
ordinary permit, while a server that parses its URIs separates the fragment before it
dereferences the resource (RFC 3986 section 3.5) and reads the same file the rule names.
Both MCP doors share the one rule, so both behaved the same way. The branch for an opaque
hier-part was worse: it returned the authored string before it read either delimiter, so
`file:etc#` was a second spelling too.

The repository already decided this rule for the other address the gateway canonicalizes.
[The plain path reports its transport
truthfully](docs/design/decisions.md#the-plain-path-binds-its-own-destination-and-reports-its-transport)
states that the HTTP parser drops a URL fragment, because a fragment is client-only and
must never reach an origin server. The resource URI was the one address the box did not
hold to it.

## Solution

`canonicalize_resource_uri` folds two RFC 3986 equivalences for a `file`, `http`, or
`https` URI. A fragment is removed, because section 3.5 separates it before dereference,
so it names no resource of its own. An empty query is no query, so a bare `?` is removed
with it; a query that carries content is kept verbatim, because a literal or a credential
can live there.

The fold also reaches the opaque hier-part, which returned before either delimiter was
read. That branch now re-emits the scheme and the hier-part instead of the authored
string, so the scheme lowercases there as it does on every other branch.

Both doors read the one function, and both forward the frame the decision used
(`exchange.rs` before it parses the client frame, and `l7.rs` for the body it relays), so
a server cannot dereference a fragment the policy never saw.

`docs/design/mcp.md` gains the canonical form, which the page never stated. It is the page
for what reaches a rule as `context.input.uri`, and `docs/design/egress.md` already states
the form of every other string a rule compares.

A non-empty query is still kept for a `file:` URI, where RFC 8089 gives a query no
meaning, and percent-escape hex case inside a query is still not folded. Both leave one
resource with two spellings, and both are stated in the pull request rather than fixed
here.

## Tests

`cargo test -p strands-box-egress-gateway --all-features` passes 277 tests;
`-p strands-box-policy` passes 464 with 7 ignored; `-p strands-box` passes 1005 with 6
ignored. `cargo build` for the gateway with `--all-features` and with
`--no-default-features` both pass. `cargo fmt --all --check` is clean, `RUSTDOCFLAGS="-D
warnings" cargo doc` is clean on the gateway, and clippy prints no warning in
`crates/egress-gateway` or `crates/box`.

Four new tests, and each one was observed to fail with the defect it names restored, then
pass with it removed:

- `uri.rs::a_fragment_or_an_empty_query_names_no_second_resource` pins that eight
  spellings of one guarded file give one canonical string, that a non-empty query
  survives, and that an authority with no path still gains its `/`.
- `uri.rs::an_opaque_hier_part_folds_its_fragment_and_empty_query` pins the branch that
  returned the authored string, and the scheme lowercasing it gained.
- `uri.rs::the_forwarded_frame_loses_the_fragment_the_decision_dropped` pins that the
  forwarded frame carries the identity the decision used.
- `admission.rs::an_appended_delimiter_cannot_dodge_an_exact_uri_forbid` pins the
  production stdio decision path: an exact uri `forbid` refuses five spellings, and a
  sibling the rule does not name still reads.

`uri.rs::query_and_fragment_are_preserved` asserted the defect, so it is gone. Its
non-regression half survives as `a_non_empty_query_is_preserved`.

`generated_spellings` gains `#`, `?`, and `:`, and
`canonicalize_resource_uri_is_idempotent` gains the `file:` and `FILE:` prefixes. The
property test could not see this change before: it passed with all three defects restored,
because its alphabet held neither delimiter and no prefix reached the opaque branch.

No committed policy under `examples/` and no page or skill holds a `context.input.uri`
literal, so nothing committed is falsified.

Not run: `scripts/test-all.sh` and the deterministic containment suite. Both are red on
this host at `origin/main` without this change, because Linux containment needs aarch64
and this host is x86_64, so the box cannot launch a workload here. That leaves the MCP
doors without end-to-end coverage on this host; the wiring is covered by the unit pins and
by the broker decision-path test above.
Comment thread crates/egress-gateway/src/mcp/uri.rs Resolved
Comment thread docs/design/mcp.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

Dropping the fragment and the empty query is correct, and both doors forward the form they judged. But the same bypass is still open one character away, through a non-empty query on file:, while the new doc says it is closed (see inline).

Details Checked and held
  • Both MCP doors forward the canonical frame they decided on (exchange.rs:599 stdio, l7.rs:325 http). "Validate once, then act on the identity you approved" holds.
  • The fragment is split before the query, so .env#?a=1 → .env and .env?a#b → .env?a. This matches RFC 3986 §3.5.
  • The opaque branch is stable on file:, file:#x, file:?, and FILE:etc#x. The extended property test passes.
  • No pub use name was added, so the egress-gateway façade freeze holds.
  • Custom schemes are still untouched. This is pre-existing and stated in the PR and the docs.
  • I ran cargo test -p egress-gateway --all-features mcp::: 40 pass. A scratch admission test confirmed the ?x case.

The defect-restoration table in the description makes each test's claim easy to trust.

## Problem

A uri-keyed `forbid` still stopped protecting a file when the workload put one more character
after the `?`. The previous commit removed an *empty* query, so a bare `?` named no second
resource. It kept a query that carried content, for every scheme. For a `file:` URI that left the
dodge open. RFC 8089 section 2 spells `file-URI = file-scheme ":" file-hier-part` and gives a file
URI no query at all, so a resolver opens the hier-part and ignores what comes after the `?`.

Measured on the stdio decision path, with the exact `forbid` from this change's own worked
example: the bare URI was refused, and the same URI with a one-character query was admitted. The
string the box recorded kept that query, so no end-anchored rule could match it either. Three
resolvers were then checked by hand - a Python `urlparse` path, a Node `fileURLToPath`, and (as
reported) a Rust `Url::to_file_path`. Each one opens the guarded file.

The reason the previous commit gave to keep a query is that a credential can live there. That
holds for `http` and `https`, where the query is part of the request the origin server receives
(RFC 3986 section 3.4). It does not hold for a scheme whose grammar has no query.

## Solution

`canonicalize_resource_uri` now treats a query by scheme. Under `http` or `https` a non-empty
query is part of what the URI names, and it stays verbatim. A `file:` URI that carries a non-empty
query is outside the grammar the function canonicalizes. It therefore has no canonical form, and
the function returns an error. `of` makes that error a refusal through `map_err(refuse)`, which is
the rail an unparsable path already rides. So the request is refused before the box forwards
anything, and no URI that is admitted has its bytes changed.

The rule comes from what the canonical form guarantees - that the canonical string is the identity
the server dereferences - and not from the spelling that was reported. The check sits above the
split of the hier-part, so it reaches the authority form, the no-authority form, and the opaque
form alike. An empty query still folds away first, so a URI inside RFC 8089's grammar never meets
the refusal.

A fold was rejected. To drop a `file:` query also gives one identity, but it changes the bytes a
server receives for a shape that some server can read, and that cannot be shown to be inert. A
refusal reaches only a URI that RFC 8089 does not define, and it tells the operator.

`docs/design/mcp.md` states the rule for each scheme. `docs/user/mcp-policy.md` gains the refusal
an operator reads.

## Tests

`cargo test -p strands-box-egress-gateway --all-features` passes 279 tests, up from 277.
`-p strands-box-policy --all-features` passes 464 with 7 ignored, unchanged.
`-p strands-box --all-features` passes 1005 with 6 ignored and 0 failed, which needs
`EXPERIMENTAL_LINUX_SUPPORT=TRUE` on this x86_64 Linux host. The gateway builds with
`--all-features` and with `--no-default-features`. `cargo fmt --all --check` is clean. Clippy
prints no warning that `crates/egress-gateway` or `crates/box` owns.

Two new tests, and two that change:

- `uri.rs::a_file_uri_that_carries_a_query_is_refused` pins the refusal across eleven spellings
  and all three hier-part forms, and pins that the decision path refuses the frame while the
  frame rewrite reports no rewrite.
- `uri.rs::no_generated_file_uri_with_a_query_gets_a_canonical_form` runs the generated alphabet
  and asserts that no `file:` spelling carrying a query gets a canonical form. It carries its own
  over-folding control: the `https` twin of each spelling must keep its query.
- `admission.rs::an_appended_delimiter_cannot_dodge_an_exact_uri_forbid` gains five spellings that
  put content after the `?`, and an over-folding control that an `http` query still rides through.
- `uri.rs::a_non_empty_query_is_preserved` and
  `uri.rs::an_opaque_hier_part_folds_its_fragment_and_empty_query` asserted a kept `file:` query.
  Each now asserts the same property under `http`, where it is still true.

Five mutations were run, in both directions, each observed to fail and then restored:

| Mutation | Direction | Tests that failed |
|---|---|---|
| Remove the `file:` query refusal | under-fold | the two new `uri.rs` tests, and the decision-path test |
| Keep the fragment | under-fold | three `uri.rs` tests |
| Keep the empty query | under-fold | two `uri.rs` tests |
| Refuse an `http`/`https` query too | over-fold | four `uri.rs` tests, and the decision-path test |
| Fold a `file:` query away instead of refusing it | over-fold | the two new `uri.rs` tests |

Not run: the `strands-box-containment` suite and `scripts/test-all.sh`. The containment suite is
red at `main` without this change, because the trampoline refuses with `Linux containment supports
ARM64 (aarch64), not x86_64`. That is 6 failures across three test targets, and this change
touches no file in that crate. The earlier claim that the `strands-box` suite needs aarch64 was
wrong: that suite needs the experimental opt-in above, and it is green with it.
Comment thread crates/egress-gateway/src/mcp/uri.rs Resolved
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Approve

At 6a01d8c, the earlier blocking finding is fixed. A file: URI with a non-empty query is now refused for every form of the part after file: (with a host, path-only, and opaque), and the docs now describe the actual behaviour. One older bypass of the same kind is left, at the scheme check (inline, non-blocking).

Details Checked and held at 6a01d8c
  • These are all refused: .env?x, .env?a=1, .env?a=1#, file://localhost/…?x, FILE:///…?x, and file:etc?x. I ran them through canonicalize_resource_uri, and the new admission spellings pass.
  • Conforming file: URIs never reach the refusal: .env? and .env#?x fold to .env. The fragment is split off first, as RFC 3986 §3.5 says.
  • https://h/p?a=1 keeps its query, so http/https URIs are not folded too far.
  • The remote door is consistent: of() refuses before canonicalize_mcp_frame (whose .ok()? gives None) could forward the raw frame.
  • Tab, NUL, space, and \ in the path are refused by the existing RFC 3986 path check.
  • Declining the loader export is the right call under the pub use freeze in egress-gateway/AGENTS.md. The PR description now gives the normalize_host/policy::spelling precedent for the maintainer.

The two-direction mutation table makes each new test's claim easy to trust.

…ol character

Addresses review feedback on the scheme position of a resource URI, and widens the fix to the
query position, which the reported shape did not cover.

## Problem

A URL parser trims leading and trailing C0 controls and spaces, and removes every tab, CR, and LF,
before it reads the scheme. The box read the authored bytes. So one URI named two schemes: the box
read a tab inside `file` as part of a custom scheme and took the never-touch branch, and the server
read `file:` and opened the path. Measured on the stdio decision path at 6a01d8c, with the same
exact `forbid` as the test beside it, eight spellings were admitted unchanged and each one resolves
to the guarded file in both a Python `urlsplit` path and a Node `fileURLToPath`.

Two of the eight carry the characters *after* the colon, so the authored scheme already reads as
`file` and a check that compares the scheme before and after preparation does not see them. The
query position is a third case: the box kept a trailing space on a query that a parser drops, so
the canonical form was not the resource an origin server resolves. That one showed up as a
non-idempotent canonical form once the generated alphabet could reach it.

The same characters in the *path* were already refused, because RFC 3986 rejects them there. Only
the scheme and the query positions let them through.

## Solution

A URI under `file`, `http`, or `https` is refused when it holds any C0 control or space, anywhere.
RFC 3986 allows neither in any component, so a conforming URI never meets the refusal, and the rule
needs no list of positions. The scheme is read from the prepared form, because that is the scheme
the server acts on, which is what reaches a tab inside the scheme itself.

A narrower rule was rejected: to compare the scheme before and after preparation leaves the two
spellings that put the character after the colon, and leaves the query position untouched.

A custom scheme keeps its never-touch contract. The box claims no identity for one, so there is no
identity for these characters to split.

`docs/design/mcp.md` states the refusal, and `docs/user/mcp-policy.md` gains the row an operator
reads.

## Tests

`cargo test -p strands-box-egress-gateway --all-features` passes 280, up from 279.
`-p strands-box-policy --all-features` passes 464 with 7 ignored, unchanged.
`-p strands-box --all-features` passes 1005 with 6 ignored and 0 failed, under
`EXPERIMENTAL_LINUX_SUPPORT=TRUE`. Both gateway builds pass, `cargo fmt --all --check` is clean, and
clippy prints no warning owned by `crates/egress-gateway` or `crates/box`.

- `uri.rs::a_resource_uri_whose_scheme_a_url_parser_rewrites_is_refused` pins thirteen spellings:
  the scheme position, the two that put the character after the colon, and three in the query. It
  also pins that a custom scheme, a scheme-less string, and `/a:b` stay verbatim, and that the
  decision path refuses the frame while the frame rewrite reports no rewrite.
- `admission.rs::an_appended_delimiter_cannot_dodge_an_exact_uri_forbid` gains five of the
  spellings on the real decision path.
- `generated_spellings` gains a tab and a space, so the property test can reach this class.
  `canonicalize_resource_uri_is_idempotent` is what caught the query position: before this change
  it reported `http://h/? ` as a canonical form that is not its own fixed point.

Three mutations, each applied alone, observed to fail, and restored:

| Mutation | Direction | Tests that failed |
|---|---|---|
| Remove the refusal | under-fold | the new `uri.rs` test, and the decision-path test |
| Compare the scheme before and after preparation only | under-fold | the new `uri.rs` test, and the decision-path test |
| Refuse these characters under every scheme | over-fold | the new `uri.rs` test |

The second mutation is the narrower rule named above. It fails on the spellings that put the
character after the colon, which is why the wider rule is the one that ships.

Not run: the `strands-box-containment` suite and `scripts/test-all.sh`. The containment suite is red
at `main` without this change, because the trampoline refuses with `Linux containment supports ARM64
(aarch64), not x86_64`. This change touches no file in that crate.
Extends the previous commit's rule to the third character a URL parser reads differently. Found
while checking the same class for what the reported shape did not cover.

## Problem

A URL parser reads a `\` as a path separator under `file`, `http`, and `https`, and the box read it
as one more character of a name. The path position was already refused, because RFC 3986 rejects a
`\` there, but the authority and the opaque hier-part were not. So two spellings named the guarded
file and the box admitted each one unchanged:

- an authority that uses `\` for every separator
- an opaque hier-part that opens with repeated `\`

Measured against two WHATWG parsers, the first resolves to the path a rule names in Node's
`fileURLToPath` and in the Rust `url` crate, which is the engine behind the `Url::to_file_path` the
review cited. So an MCP server written in TypeScript or Rust opens the file the rule refuses.

## Solution

The refusal from the previous commit gains `\`. A URI under one of the three schemes is refused when
it holds any C0 control, any space, or any `\`. The reason is one reason: RFC 3986 allows none of
them in any component, and a URL parser gives each one a meaning the box does not. So a conforming
URI never meets the refusal, and the rule still needs no list of positions.

A custom scheme keeps its never-touch contract, because a `\` is only a separator for a special
scheme, and the box claims no identity for a custom one.

`docs/design/mcp.md` and `docs/user/mcp-policy.md` state the wider refusal.

## Tests

`cargo test -p strands-box-egress-gateway --all-features` passes 280, unchanged in count because
the spellings join the test the previous commit added, now renamed
`a_resource_uri_a_url_parser_reads_differently_is_refused` for the wider rule.
`-p strands-box-policy --all-features` passes 464 with 7 ignored.
`-p strands-box --all-features` passes 1005 with 6 ignored and 0 failed, under
`EXPERIMENTAL_LINUX_SUPPORT=TRUE`. Both gateway builds pass, `cargo fmt --all --check` is clean, and
clippy prints no warning owned by `crates/egress-gateway` or `crates/box`. The six it prints are in
the vendored `crates/shell`.

- `uri.rs::a_resource_uri_a_url_parser_reads_differently_is_refused` gains five `\` spellings across
  the authority, the opaque hier-part, and the path.
- `admission.rs::an_appended_delimiter_cannot_dodge_an_exact_uri_forbid` gains two of them on the
  real decision path.
- `generated_spellings` gains a `\`, so the property test reaches this class.

Two mutations, each applied alone, observed to fail, and restored:

| Mutation | Direction | Tests that failed |
|---|---|---|
| Drop `\` from the refused set | under-fold | the refusal test, and the decision-path test |
| Refuse `\` under every scheme | over-fold | the refusal test, on its custom-scheme controls |

Not run: the `strands-box-containment` suite and `scripts/test-all.sh`. The containment suite is red
at `main` without this change, because the trampoline refuses with `Linux containment supports ARM64
(aarch64), not x86_64`. This change touches no file in that crate.
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Request Changes

At 9c3fc70, the whitespace and control-character refusal is correct and wider than what I suggested. The backslash fix from the thread (e3561c3) is not on the branch, so file://localhost\home\op\.env and the opaque file:\\… spellings still get past an exact uri forbid (see the thread reply). Pushing that commit should be the only thing left.

Details Checked and held at 9c3fc70
  • Leading and trailing C0 controls and spaces, a tab inside the scheme, a tab after the colon, NUL before an uppercase FILE:, and a trailing space on an http query are all refused through whatwg_prepared → scheme_of.
  • Custom schemes keep their never-touch contract: notes:///x is left verbatim.
  • Non-ASCII whitespace (\u{a0}) and DEL in the path are still refused by the RFC 3986 path check.
  • Adding tab and space to the generated alphabet let the idempotence property test reach this class. That is how the author found the query-position case.

Deriving the rule from "RFC 3986 allows none of these anywhere", rather than from a list of positions, is what made the after-the-colon and query cases fall out.

…ue branch

Review feedback named two opaque-hier-part spellings that the refusal already covers but no test
spelled. Each count of leading ` now has its own case, so the opaque branch cannot regress while
the authority cases keep passing. No change to canonicalize_resource_uri.

`cargo test -p strands-box-egress-gateway --all-features` passes 280 with 0 failed, clippy prints
no warning the crate owns, and `cargo fmt --all --check` is clean.
Comment thread crates/egress-gateway/src/mcp/uri.rs Resolved
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Approve

At e3561c3, the whitespace, control-character, and backslash refusal closes my earlier scheme-position finding, and it also covers positions I hadn't named. One older case in the same class is left: a file:/http(s): URI with no //authority (inline, non-blocking).

Details Checked and held at e3561c3
  • These are all refused: " file:", "\tfile:", "fi\tle:", "file:\t///", "\0FILE:", and http://h/a?b=1 .
  • The backslash forms are refused: file://localhost\home\op\.env, file://localhost\home/op/.env, file:\\localhost\…, and file:\\\home\op\.env. Node reads each one as /home/op/.env, and 9c3fc70 had admitted all four.
  • Custom schemes stay verbatim ( notes:///x), as the PR intends.
  • U+00A0 and DEL in the path are refused by the existing RFC 3986 path check.
  • The query refusal from 6a01d8c is unchanged.

Deriving the refusal from an invariant rather than from a list of reported spellings is what caught the after-the-colon and backslash cases.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Approve

This replaces my 00:47 Request Changes. That review read a stale checkout (9c3fc70). The author is right that e3561c3 was already on the branch, and I re-ran the backslash spellings at f952ca5: all of them are refused. f952ca5 is test-only and pins each count of leading \ on the opaque branch. One older case in the same class is left, a file:/http(s): URI with no //authority (inline, non-blocking).

Details Checked and held at f952ca5
  • Backslashes are refused in the authority and the opaque hier-part: file://localhost\home\op\.env, file:\\localhost\…, file:\\\home\op\.env, and file:\home\op\.env.
  • Spaces and C0 controls are refused in the scheme, after the colon, and in the query: " file:", "fi\tle:", "file:\t///", and http://h/a?b=1 .
  • Custom schemes stay verbatim ( notes:///x).
  • file:/home/op/.env folds to the guarded identity and is denied.
  • The query refusal from 6a01d8c is unchanged.

Pinning the opaque branch with its own cases, instead of trusting the refusal to cover it, closes the regression path I was worried about.

Comment thread crates/egress-gateway/src/mcp/uri.rs Resolved
Closes the last shape in the class the previous three commits worked through: a hier-part that a
URL parser completes for the workload.

## Problem

A URL parser treats `file`, `http`, and `https` as special schemes and supplies any delimiter the
URI omits. The box kept such a URI verbatim, so the two ends read different resources. Measured on
the decision path with an exact `uri` forbid, each of these was admitted unchanged, and Node and the
Rust `url` crate both resolve each one to the guarded resource:

- an opaque `file:` hier-part, with or without a leading `./`, which a parser reads as the absolute
  path form
- an opaque `http`/`https` hier-part, which a parser reads as the authority form
- an `http`/`https` URI with one slash or three, which a parser folds to the authority form

The comment on the no-authority branch claimed that keeping the path-only form was safer than
inventing an authority. That was wrong in a way that mattered: a parser reads the first path segment
as the host, so `http:/etc/passwd` becomes the host `etc` and the path `/passwd`.
`a_path_only_http_uri_keeps_its_path_only_form` pinned that belief.

## Solution

The hier-part must spell its own shape, which both grammars state. RFC 8089 section 2 has
`local-path = path-absolute`, so a `file:` URI needs an absolute path and an opaque hier-part is
refused. RFC 9110 section 4.2.1 requires `"//" authority` and forbids an empty host, so an `http` or
`https` URI with no authority, or an empty one, is refused as well.

`file:/x` is still completed by the box rather than refused, because RFC 8089 makes an absent
authority the local one, so the box is not guessing there.

This is the same reasoning as the `file:` query refusal: a URI outside the grammar has no canonical
form, so the box refuses it rather than let a parser decide. A conforming URI meets neither refusal.

`docs/design/mcp.md` and `docs/user/mcp-policy.md` state both refusals.

## Tests

`cargo test -p strands-box-egress-gateway --all-features` passes 280 with 0 failed.
`-p strands-box-policy --all-features` passes 464 with 7 ignored.
`-p strands-box --all-features` passes 1005 with 6 ignored and 0 failed, under
`EXPERIMENTAL_LINUX_SUPPORT=TRUE`. Both gateway builds pass, `cargo fmt --all --check` is clean, and
clippy prints no warning owned by `crates/egress-gateway` or `crates/box`; the six it prints are in
the vendored `crates/shell`.

- `uri.rs::an_opaque_hier_part_is_refused_because_a_parser_supplies_the_delimiters` replaces
  `an_opaque_hier_part_folds_its_fragment_and_empty_query`, whose premise is gone: the branch it
  pinned no longer folds anything, because it refuses.
- `uri.rs::an_http_uri_with_no_authority_is_refused_and_file_keeps_its_local_one` replaces
  `a_path_only_http_uri_keeps_its_path_only_form`, which pinned the wrong belief above. It keeps
  that test's true half, the `file:` local authority, and adds the empty-authority spellings.
- `admission.rs::an_appended_delimiter_cannot_dodge_an_exact_uri_forbid` gains two of the spellings
  on the real decision path.

Three mutations, each applied alone, observed to fail, and restored:

| Mutation | Direction | Tests that failed |
|---|---|---|
| Keep the opaque branch verbatim | under-fold | the opaque test, and the decision-path test |
| Allow an `http` URI with no authority | under-fold | the authority test |
| Require an authority for `file:` too | over-fold | six tests, including the idempotency property |

Not run: the `strands-box-containment` suite and `scripts/test-all.sh`. The containment suite is red
at `main` without this change, because the trampoline refuses with `Linux containment supports ARM64
(aarch64), not x86_64`. This change touches no file in that crate.
@abhisheksp abhisheksp changed the title fix(egress-gateway): fold a resource URI's fragment and empty query fix(egress-gateway): close resource URI respellings that dodge a uri rule Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Approve

At 4140ec7, the opaque-hier-part and missing-authority refusals close my no-// finding. Neither refusal catches a URI that conforms to RFC 8089 or RFC 9110. One older case in the same delimiter class is left in the http(s) authority (empty userinfo or empty port), plus a stale comment (both inline, non-blocking). My Approve summaries at 00:55 and 01:01 are duplicates. This one supersedes both.

Details Checked and held at 4140ec7
  • These are refused: file:home/op/.env, FILE:home/op/.env, https:notes/page, https:///notes/page, and the bare file:. Node turns the last one into file:///, so refusing it fails closed.
  • file:/home/op/.env still folds to file:///… and is denied. https://NOTES:443/page and https://notes/page? still fold to the guarded identity.
  • file://@localhost/… stays verbatim, but Node refuses it as an invalid URL, so a server cannot open the guarded file through it.
  • https://./notes/page canonicalizes to https:///notes/page. That form is not its own fixed point, but Node keeps the host ., so no guarded resource is reached.

Replacing a_path_only_http_uri_keeps_its_path_only_form rather than editing it removes the test that encoded the wrong belief.

…uthority

Adversarial review found a claim this branch already makes that the code does not
hold. `the_finding_bypass_classes_canonicalize_to_one_identity` says every
equivalent spelling of "this machine" collapses, naming loopback IP literals, and
`is_local_file_authority` compared the bracketed literal as text against `::1`
and `0:0:0:0:0:0:0:1`. One address has many spellings. Measured in Node:
`file://[::0001]/home/op/.env` resolves to `file://[::1]/home/op/.env`, which is
the local file a rule names, while the box emitted the authority unfolded and so
matched no rule on `file:///home/op/.env`. `[0::1]` and an IPv4-mapped loopback
literal did the same.

Parse the literal with `Ipv6Addr` and fold a loopback address, or an IPv4-mapped
address whose IPv4 half is loopback. A text comparison cannot carry this, because
the spellings of one address are unbounded.

Review also found two false statements in the prose this branch added, both on
pages an operator reads.

The canonical form does not uppercase the hex of every escape that stays. A query
rides through verbatim and so does a userinfo, so the claim holds for the path
alone, and the same page already said so about a query fifty lines later. An
operator who followed the sentence would write `?a=%2E` for a rule that never
matches.

The userinfo residual was scoped to an empty userinfo. Any userinfo puts the host
out of a pattern's reach, because the canonical form spells the userinfo first:
all three parsers read `https://user@notes/page` as host `notes` and path
`/page`, so it fetches the page a rule names while matching no rule written
against the host. The empty one is the sharper half, because a parser drops it and
the box does not, so the two ends read two strings; a non-empty one both ends
agree on, and it still walks past the rule. The remedy the page recommends, the
longest host prefix, reaches neither.

## Tests

| Test | What it pins |
|---|---|
| `uri.rs::the_finding_bypass_classes_canonicalize_to_one_identity` | Five more loopback literal spellings fold to `file:///etc/passwd` — zero-compressed, expanded, and IPv4-mapped in both hex cases. |
| `uri.rs::canonicalize_resource_uri_collapses_every_local_authority_spelling` | The same five, plus four controls that must NOT collapse: a non-loopback literal, a documentation address, an IPv4-mapped non-loopback literal, and an `IPvFuture` literal. |
| `admission.rs::a_uri_like_pattern_cannot_name_one_origin_and_only_that_origin` | Five userinfo spellings, empty and not, reach neither pattern on the real decision path. Was one. |

### Mutation testing, in both directions

| Mutation | Direction | What failed |
|---|---|---|
| Compare the IPv6 literal as text, as before | under | two `uri.rs` tests |
| Fold every IPv6 literal to the local authority | over | one `uri.rs` test |
| Drop the IPv4-mapped loopback half | under | two `uri.rs` tests |

`cargo test -p strands-box-egress-gateway --all-features` passes 240 across 7
binaries, and `-p strands-box --all-features` passes 1045 across 49 with 6
ignored. Clippy prints no warning owned by either crate, and `cargo fmt --all
--check` is clean. The 6,438,315-input sweep is unchanged: 1,045,233 accepted, 0
non-fixed-points, 0 emitted authorities outside RFC 3986 §3.2.
Comment thread crates/egress-gateway/src/mcp/uri.rs Resolved
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Comment

4169f26 does what it says: a bracketed loopback literal now folds, and the two prose corrections are accurate. Two non-blocking gaps are inline. Both are spellings the docs now ask the operator to write rules around, which the code could refuse instead. Userinfo is the clearer one, because RFC 9110 §4.2.4 already asks a recipient to refuse it.

Checked and held at 4169f26
  • Ipv6Addr parsing folds [::0001], [0::1], [0:0:0:0:0:0:0:1], and [::ffff:127.0.0.1] in both hex cases. [2001:db8::1], [::ffff:10.0.0.1], and [v1.x] do not fold, and [::1]:99 still does not collapse.
  • An IPvFuture literal fails the Ipv6Addr parse, so it is kept and never folded.
  • "Uppercased in the path" now matches the code: the query and the userinfo are emitted verbatim.
  • The new admission loop pins all five userinfo spellings on the real decision path, against both patterns.
  • 78f26c9's straight-line emission of the authority is unchanged by this commit.

Measuring the userinfo claim beyond the empty case, instead of narrowing the docs to fit the code, is what exposed the gap behind the first inline comment.

Review found that the previous commit's own justification overstated what a
resolver does, and that the page left an operator uninformed about a wider
residual than the one it named.

Measured in all three parsers. None implements a remote `file:` URI. Node's
`fileURLToPath` and the Rust `url` crate's `to_file_path` open an empty host or
`localhost` and refuse every other host outright, `[::1]` included. Python's
`url2pathname` reads the path and ignores the host, so `file://notes/...`,
`file://[::2]/...`, and `file://127.1/...` each open the same local file. So
against a server built on `urlsplit`, a `forbid` naming a `file:` path is dodged
by ANY host the box keeps, not only by a respelling of a local one. The page
scoped that residual to a port or a userinfo spelling, which is narrower than the
truth.

The previous commit said Node resolves a zero-compressed loopback literal to the
local file. Node folds the href to `[::1]` and then refuses to open it. The fold
is still correct, because it is a narrowing: folding to the empty authority makes
a path-anchored rule match more spellings and never fewer. The page now says that
rather than claiming a resolver opens it.

State the residual at its real width, and give the operator a pattern that holds:
anchor a `file:` rule on the path and allow any authority.

Refusing a non-local `file:` authority outright would close it, and costs no URI
any measured resolver opens as a remote resource. That refuses a shape RFC 8089
conforms, so it is the user's call and not an agent's, and it is not in this
commit.

## Tests

`admission.rs::a_file_pattern_that_allows_any_authority_reaches_every_host_spelling`
pins the recommended pattern on the real decision path: eleven authority
spellings reach the rule, six local and five not, and a sibling path the rule does
not name still reads. Without it the page would recommend a pattern with no test
beside it, which is the defect this branch already corrected once.

`cargo test -p strands-box --all-features` passes 1046 across 49 binaries with 6
ignored, and `-p strands-box-egress-gateway --all-features` passes 240 across 7.
Clippy prints no warning owned by either crate, and `cargo fmt --all --check` is
clean. No code changed, so the idempotence sweep is unmoved.
Comment thread docs/design/mcp.md Resolved
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Comment

d2d2a25 states the file: residual at its measured width and corrects the earlier claim that Node opens a folded loopback literal. One non-blocking gap is inline: the recommended pattern reaches more paths than the page and its test claim. The userinfo comment on normalize_authority (refusing it per RFC 9110 §4.2.4) is still open; this commit does not touch it.

Checked and held at d2d2a25
  • No change to crates/egress-gateway, so the loopback fold and the authority emission I reviewed at 4169f26 are unchanged.
  • All eleven authority spellings in the new test, six local and five not, reach forbid_env_any_authority on the real decision path.
  • The new prose matches what I measured: Node's fileURLToPath refuses every host except an empty one and localhost, [::1] included, and Python's url2pathname ignores the host.
  • "Narrowing" holds for a path-anchored rule: folding to the empty authority adds spellings a rule reaches and removes none that a rule on the folded form would match.
  • The port and query-hex residual paragraph still describes the code once its file: clause is removed.

Pinning the recommended pattern with a test on the real decision path is what made its actual reach measurable.

…es a slash

Review found that the pattern the previous commit recommends reaches more paths
than the page and its test claim. In this policy language `*` matches a `/`, so
`uri like "file://*/home/op/.env"` is a SUFFIX match: measured on the real
decision path, it also refuses `file:///srv/backup/home/op/.env` and
`file:///tmp/x/home/op/.env`. The page gave the advice generally, and the test
checked only a sibling name, so neither showed the real reach.

In a `forbid` the over-reach is the safe direction and the pattern still covers
what it was recommended for. In a `permit` it widens:
`uri like "file://*/srv/public/readme"` also permits
`file:///home/op/srv/public/readme`. No `like` pattern can say "any authority,
exactly this path", because nothing stops `*` at the first `/`.

Scope the recommendation to a `forbid`, call it a suffix match, and state that a
`permit` on a `file:` path has to name the authority it expects.

This is the concrete case for refusing a non-local `file:` authority in the
canonicalizer, which would remove the need for the pattern at all. That refuses a
shape RFC 8089 conforms to, so it stays the user's call and is not here.

## Tests

`admission.rs::a_file_forbid_pattern_is_a_suffix_match_across_every_authority`
replaces `a_file_pattern_that_allows_any_authority_reaches_every_host_spelling`,
whose name and closing comment both claimed the pattern names one path. It pins
eleven authority spellings, three deeper paths that the suffix match also
refuses, and three paths it does not reach.

`cargo test -p strands-box --all-features` passes 1046 across 49 binaries with 6
ignored, and `-p strands-box-egress-gateway --all-features` passes 240 across 7.
Clippy prints no warning owned by either crate, and `cargo fmt --all --check` is
clean. No code outside tests changed.
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Comment

d64afc3 limits the suffix pattern to forbid and tests its reach in both directions, which settles my last inline comment. One non-blocking gap is inline: against the Python resolver this paragraph targets, an encoded slash gets past the recommended forbid. The userinfo comment on normalize_authority (refuse per RFC 9110 §4.2.4) is still open.

Checked and held at d64afc3
  • * crosses /. The test now pins three deeper paths as refused and three non-suffix paths as read, which matches what I measured last round.
  • "A permit names the authority it expects … refused by the absence of a permit" holds when that permit is the gate. An exact file:///srv/public/readme does not match file://notes/srv/public/readme.
  • A query cannot get past the suffix forbid: a file: URI with a non-empty query is refused (uri.rs line 67), even though Node and Python would open the path and ignore the query.
  • %2E, %65, and the other unreserved escapes in a file: path decode before matching, so file:///home/op/%2Eenv reaches the rule.
  • No non-test code changed since d2d2a25.

Testing the paths the pattern must not reach, alongside the ones it must, is what makes the new prose checkable.

Comment thread docs/design/mcp.md Resolved
Review found that an encoded slash reached the guarded file past both an exact
`uri` forbid and the suffix pattern the previous commit recommends, and that
neither page named the residual — only a code comment did.

The comment treated a resolver that decodes a reserved delimiter as hypothetical.
Measured, two of the three do it. Python's `url2pathname` and the Rust `url`
crate both turn `%2F` into a separator, so `file:///home/op%2F.env` opens
`/home/op/.env` and `file:///tmp/%2e%2e%2Fetc/passwd` traverses to
`/tmp/../etc/passwd`. Node refuses the URI with `ERR_INVALID_FILE_URL_PATH`.
Review said Node and the Rust crate both reject it; the Rust crate does not, so
the residual was wider than reported.

No POSIX or Windows file name holds a `/`, so a segment spelling one with `%2F`
names no file, and the escape has no canonical form under `file:`. Refuse it, the
same way a `file:` query is already refused, and for the same reason: the URI is
outside the grammar this function canonicalizes. That also takes the `..%2F`
traversal the code comment left to the leaf box's filesystem bound.

The refusal is scheme-split, like the query. An `http`/`https` path keeps the
escape, because the origin server receives it and a segment there may spell one,
which is also what the egress request-path canonicalization does. And `%5C` is
NOT refused with it: all three resolvers decode it to a literal backslash, which
a POSIX name may hold, so it names a file of its own and both ends agree on
which. Refusing it would be an over-fold.

## Tests

Three tests asserted the old premise for `file:` and are rewritten rather than
edited, because each pinned a reading that is gone: the `%2F` assertion moves to
the `http`/`https` twin, where it is still true, and gains the `file:` refusal
beside it. `reserved_octets_stay_encoded` becomes
`reserved_octets_stay_encoded_under_http_and_are_refused_under_file`.

| Test | What it pins |
|---|---|
| `uri.rs::an_encoded_slash_in_a_file_path_is_refused` | Ten `file:` spellings refuse across all three hier-part forms, including the traversal. The `http`/`https` twin keeps the escape, `%5C` and other reserved escapes still ride, `%252F` holds no encoded slash, and an unreserved escape still folds. |
| `admission.rs::a_file_forbid_pattern_is_a_suffix_match_across_every_authority` | Four encoded-slash spellings no longer reach the file on the real decision path, so the recommended pattern does not have to carry them. |

### Mutation testing, in both directions

| Mutation | Direction | What failed |
|---|---|---|
| Remove the encoded-slash refusal | under | four `uri.rs` tests, and the decision-path test |
| Refuse an encoded slash under every scheme | over | five `uri.rs` tests |
| Refuse an encoded backslash with it | over | `an_encoded_slash_in_a_file_path_is_refused` |
| Refuse every reserved escape in a file path | over | two `uri.rs` tests |

`cargo test -p strands-box-egress-gateway --all-features` passes 241 across 7
binaries, and `-p strands-box --all-features` passes 1046 across 49 with 6
ignored. Clippy prints no warning owned by either crate, and `cargo fmt --all
--check` is clean. The sweep over 6,438,315 inputs accepts 1,045,160 with 0
non-fixed-points, down 73 from the previous commit, which is the encoded-slash
class.
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Comment

a228290 closes the encoded-slash gap at its narrowest point: only file: paths are refused, http/https keep the escape, and the mutations in both directions are tested. I found no new defect at this head. The only thing still open is the userinfo comment on normalize_authority (refuse per RFC 9110 §4.2.4), which this commit does not touch.

Checked and held at a228290
  • Hex case and the uppercase scheme: the check runs on the canonical path after hex is uppercased, so %2f and FILE: are caught. Both are in the test.
  • Escape built during normalization: an escape that only appears after normalization, such as %%32F, is still caught, because the check runs after unreserved decoding.
  • Double encoding: %252F is not refused. That is correct, because a single decode gives the literal text %2F, not a separator.
  • Traversal: ..%2F and %2e%2e%2F are refused rather than left to the leaf box's filesystem bound.
  • Authority and fragment: a %2F in the authority was already refused, and one in the fragment is dropped before the check.
  • Request side only: canonicalize_resource_uri has one caller, the request path in mcp/mod.rs, so a refusal cannot drop a server's resources/list reply.
  • No legitimate file lost: an input that worked before, file:///a%2Fb, now refuses, but no POSIX file name holds a /, so no real file becomes unreachable. %5C, %3F, and %23 still pass and are tested.
  • Correction to my earlier comment: your measurement that the Rust url crate decodes %2F widens the case I made. The design page and the user-facing error table both state it now.

Rewriting the three tests that pinned the old reading, instead of loosening them, kept the behaviour for http/https and for file: pinned separately.

The review bot's assessment named this gap five times and never filed the
comment, so the substance was unaddressed. It cites RFC 9110 §4.2.4, which I read
rather than took on trust. The section deprecates the userinfo under these two
schemes: a sender "MUST NOT generate the userinfo subcomponent (and its "@"
delimiter)", and "before making use of an "http" or "https" URI reference
received from an untrusted source, a recipient SHOULD parse for userinfo and
treat its presence as an error; it is likely being used to obscure the authority
for the sake of phishing attacks".

Both halves fit. The workload is the untrusted source, and the box is the
recipient. The obscuring is the defect measured on this branch: the canonical
form spells the userinfo before the host, so no rule written against a host
reached a URI carrying one, while Node, Python `urlsplit`, and the Rust `url`
crate all read `https://user@notes/page` as host `notes` and path `/page`. An
empty userinfo was worse again, because a parser drops it and this function did
not, so the two ends read two strings.

Refuse it. That closes both halves at once, so no `uri` pattern has to reach a
userinfo and the page no longer has to explain that none can.

Scoped to `http`/`https`, because RFC 9110 governs those schemes. A `file:` URI
keeps its userinfo and stays the smaller documented residual: Node and the Rust
`url` crate reject such a URI outright, and Python ignores the userinfo and the
host alike.

## Tests

Four tests asserted a userinfo riding through and are rewritten, because the
premise is gone rather than wrong. Each `http` userinfo assertion moves to the
`file:` twin, where it is still true, or becomes a refusal.

| Test | What it pins |
|---|---|
| `uri.rs::an_http_uri_carrying_userinfo_is_refused` | Twelve spellings refuse — empty, password-only, escaped, port-qualified, and over an IPv6 literal. `file:` keeps two, an authority with no userinfo is untouched, and a `%40` in a path is not an `@`. |
| `uri.rs::every_authority_the_grammar_spells_still_canonicalizes` | The §3.2 userinfo control moves to `file:`, so the grammar check is still pinned to accept all five spellings. |
| `admission.rs::a_uri_like_pattern_cannot_name_one_origin_and_only_that_origin` | Five userinfo spellings are refused on the real decision path rather than reaching no pattern. |

### Mutation testing, in both directions

| Mutation | Direction | What failed |
|---|---|---|
| Remove the userinfo refusal | under | three `uri.rs` tests, and the decision-path test |
| Refuse a userinfo under `file:` too | over | three `uri.rs` tests, and the decision-path test |
| Refuse only an EMPTY userinfo | under | three `uri.rs` tests, and the decision-path test |

`cargo test -p strands-box-egress-gateway --all-features` passes 242 across 7
binaries, and `-p strands-box --all-features` passes 1046 across 49 with 6
ignored. Clippy prints no warning owned by either crate, and `cargo fmt --all
--check` is clean. The sweep over 6,438,315 inputs accepts 870,275 with 0
non-fixed-points and 0 emitted authorities outside RFC 3986 §3.2 — down 174,885,
which is the userinfo class the generated alphabet reaches through its `@` piece.
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Approve

572623d refuses userinfo under http/https per RFC 9110 §4.2.4, which closes the last open item. You're right that the userinfo point only ever appeared in my summaries and never as a filed comment. I found no new defect at this head, and nothing from earlier reviews is still open.

Checked and held at 572623d
  • Only these three schemes reach it: normalize_authority is called only for schemes that scheme_of returns, which are file, http, and https. So scheme != "file" means exactly http/https, and the error text is accurate.
  • Every spelling that reaches the @ split is refused: that covers empty, :-only, escaped, port-qualified, IPv6, and uppercase-scheme spellings. An @ after /, ?, or # is not part of the authority and is untouched. %40 in the host was already refused as a reserved escape, and %40 in the path rides through as tested.
  • The file: userinfo residual holds as documented: Node rejects file://user@localhost/…, file://@localhost/…, and file://localhost:/… with ERR_INVALID_URL. Python opens /home/op/.env for any userinfo and host.
  • The recommended file: forbid covers it on the real decision path: I probed file://user@localhost/home/op/.env, file://@evil/home/op/.env, and file://u:[email protected]/home/op/.env. All three were denied by forbid_env_any_authority.
  • The design page now matches the code: the userinfo-reach paragraph and the "neither pattern reaches any userinfo" caveat are gone. The port-spelling gap stays documented as a residual you have to write around.

Across this PR, each fix kept its scheme split and was mutation-tested in both directions, which leaves the reach of every refusal checkable.

@kevin-orellana kevin-orellana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Box changes /report? to /report, but a server can return different content for those addresses. This can make a resource read return different content than requested. Would it make sense to preserve the empty query for HTTP and HTTPS addresses?

@kevin-orellana
kevin-orellana merged commit 3977e0a into main Nov 3, 2026
22 checks passed
@kevin-orellana
kevin-orellana deleted the feature/mcp/resource-uri-delimiter-fold branch November 3, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants