Repository navigation
fix(egress-gateway): close resource URI respellings that dodge a uri rule - #229
Conversation
## 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.
|
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 DetailsChecked and held
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.
|
Assessment: Approve At 6a01d8c, the earlier blocking finding is fixed. A DetailsChecked and held at 6a01d8c
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.
|
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 DetailsChecked and held at 9c3fc70
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.
|
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 DetailsChecked and held at e3561c3
Deriving the refusal from an invariant rather than from a list of reported spellings is what caught the after-the-colon and backslash cases. |
|
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 DetailsChecked and held at f952ca5
Pinning the opaque branch with its own cases, instead of trusting the refusal to cover it, closes the regression path I was worried about. |
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.
|
Assessment: Approve At 4140ec7, the opaque-hier-part and missing-authority refusals close my no- DetailsChecked and held at 4140ec7
Replacing |
…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.
|
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
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.
|
Assessment: Comment d2d2a25 states the Checked and held at d2d2a25
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.
|
Assessment: Comment d64afc3 limits the suffix pattern to Checked and held at d64afc3
Testing the paths the pattern must not reach, alongside the ones it must, is what makes the new prose checkable. |
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.
|
Assessment: Comment a228290 closes the encoded-slash gap at its narrowest point: only Checked and held at a228290
Rewriting the three tests that pinned the old reading, instead of loosening them, kept the behaviour for |
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.
|
Assessment: Approve 572623d refuses userinfo under Checked and held at 572623d
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
left a comment
There was a problem hiding this comment.
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?
Description
This policy guards a file, and before this change the agent read it anyway:
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
forbidstoppedmatching, 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 atab 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.
localhostcarrying an invisible code point is a host every referenceparser resolves to
localhost, so each one opens the guarded file. The box has no IDNA, so itsnormalized 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 Rusturlcrate:…/.env#,…/.env#x,…/.env?…/.env— refused by the rule…/.env?x,…/.env?a=1\where the server reads a path separator//or/file:path, which two of three resolvers decode into a separator..%2Ftraverses@http/httpsthat carries contentThe 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, andRFC 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:
xn--xn--formhttp/httpsthat compresses its zeros, or maps an IPv4 addressfile:every loopback spelling now folds, because the local authority is parsed rather than compared as textThe 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://::. Thatauthority 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/httpsURI carrying userinfo is refused. RFC 9110 §4.2.4 deprecates it: a sender maynot 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, whileall three parsers read it as host
notesand path/page. An empty one was worse again, because aparser drops it and the box did not.
file:keeps its userinfo, because RFC 9110 does not governthat 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/httpsthat is live. Aparser reads a port as a number, so a leading zero and a bare
:both drop, and an empty userinfoand 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 truefor
file:and false for thehttp/httpstwin. The correction had landed on the port row andnot on the userinfo row beside it.
docs/design/mcp.mdnow states both at the right scope.No
uripattern names one origin and only that origin while those spellings are unfolded. Thepage used to tell an operator to name the host with a
likepattern instead of matching a fullurithat carries a port. Measured, that does not hold: a pattern keeping the path separatormatches none of the port spellings, because the standard form puts the port before the
/, and theonly 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 localpath. None of the three parsers implements a remote
file:URI. Node and the Rusturlcrate openan empty host or
localhostand refuse every other host outright,[::1]included. Python'surl2pathnameignores the host, so any host opens the same local file. So against a server built onurlsplit, aforbidnaming afile:path is dodged by any host the box keeps, not only by arespelling of a local one. The page states that at its real width now, and gives a
forbidthepattern
uri like "file://*/home/op/.env"with the catch named:*crosses a/, so it is asuffix match that also refuses a deeper path ending in the same characters. That is the safe
direction in a
forbidand a widening in apermit, 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 assertionsthis 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/, nolikepatterncan write an authority-agnostic
permiton afile:path at all. Refusing a non-local authorityremoves the need for the pattern instead of documenting its catch.
An encoded slash in a
file:path is refused, and thehttp/httpstwin keeps it. This rowstarted the PR as a documented residual and is now closed under
file:. The code comment called aresolver that decodes a reserved delimiter a hypothetical; measured, two of three do it. Python's
url2pathnameand the Rusturlcrate both turn%2Finto a separator, so/home/op%2F.envreaches the guarded file and
..%2Fetctraverses. Node refuses the URI. No file name holds a/, sothe segment names no file and the URI has no canonical form here — the same shape as the
file:query refusal. An
http/httpspath keeps the escape, because the origin server receives it.%5Cis 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
uriequal to a URI carryinga fragment can no longer match, and the server returns the whole document. A
file:literalcarrying 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 linerange, say — and one that uses an opaque
file:URI. Neither is evidenced: nothing in thisrepository 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 aresolver 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
uriliteral written against the old standard form may nolonger 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 underhttp/https, and afile:userinfo is not folded; anunbracketed, 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 isclosed under
file:— refused outright — and deliberately open underhttp/https, where theorigin 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
uriliteral that can never match — one that is not a fixed point ofthis 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-gatewaypublic list.There is a precedent on the same file.
crates/egress-gateway/AGENTS.mdalready records this shapefor hosts: "
normalize_hostandis_bindable_hostare the one host spelling, exported forpolicy::spelling, which refuses a host literal no bound host can equal." The same file says a45th name needs a named external caller, and
policy::spellingis that caller.Related Issues
None.
Type of Change
Bug fix
Testing
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --all-featureson this branch: 242 passed inegress-gatewayacross 7 binaries, 540passed with 7 ignored in
policyacross 31, and 1046 passed with 6 ignored inboxacross 49.The
boxsuite needsEXPERIMENTAL_LINUX_SUPPORT=TRUEon this x86_64 Linux host. Oneskipping:line, in
box: a live library reload needs a usable containment backend. The gateway builds with--all-featuresand with--no-default-features.cargo fmt --all --checkis clean, and clippyprints 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
mainwas merged in: itrewrote the gateway's MITM layer and removed test targets with it, and added to
policy.uri.rs::an_authority_outside_rfc_3986_is_refuseduri.rs::every_authority_the_grammar_spells_still_canonicalizesIPvFutureliteral, a userinfo, and a port.uri.rs::the_authority_refusal_follows_the_grammar_in_both_directionsuri.rs::the_emitted_authority_is_itself_rfc_3986uri.rs::a_host_holding_an_escape_of_a_reserved_or_non_ascii_octet_is_refuseduri.rs::the_host_emits_no_percent_escapeuri.rs::an_http_uri_carrying_userinfo_is_refusedfile:keeps two, and a%40in a path is not an@.uri.rs::an_encoded_slash_in_a_file_path_is_refusedfile:spellings refuse across all three hier-part forms, including the traversal; thehttp/httpstwin keeps the escape, and%5C,%252F, and an unreserved escape all still ride.uri.rs::a_file_uri_that_carries_a_query_is_refuseduri.rs::no_generated_file_uri_with_a_query_gets_a_canonical_formfile:spelling carrying a query gets a standard form, with thehttpstwin of each as an over-folding control.uri.rs::a_fragment_or_an_empty_query_names_no_second_resourceuri.rs::an_opaque_hier_part_is_refused_because_a_parser_supplies_the_delimitersuri.rs::an_http_uri_with_no_authority_is_refused_and_file_keeps_its_local_onefile:/xstill completes.uri.rs::a_resource_uri_a_url_parser_reads_differently_is_refused\at each count of leading\— while a custom scheme and a scheme-less string stay verbatim.uri.rs::canonicalize_resource_uri_is_idempotentadmission.rs::an_appended_delimiter_cannot_dodge_an_exact_uri_forbidhttpquery still rides through.admission.rs::a_host_spelling_outside_the_uri_grammar_cannot_dodge_an_exact_uri_forbidadmission.rs::a_uri_like_pattern_cannot_name_one_origin_and_only_that_originadmission.rs::a_file_forbid_pattern_is_a_suffix_match_across_every_authorityfile: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 Rusturlcrate, then grouped by the resource each parsersays 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
urlcrate, and in Python, which ignores the host entirely. I confirmedthat 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_directionsuses the function under test as itsown 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 ], withhostasIP-literal / IPv4address / reg-name— and not a character list onepass happened to enumerate. That matters in both directions: a registered name legitimately holds
_,~, and every sub-delim, and256.1.1.1is a valid name rather than an invalid address, so ahand-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_3986is the pin for that half.Mutation testing, in both directions
Each was applied alone, observed to fail, and restored.
uri.rstests, and the decision-path testuri.rstest, and the decision-path testuri.rstestsfile:, whose parsers reject more anywayuri.rstests, and the decision-path testthe_grammar_check_reads_the_whole_authorityuri.rstests, and the decision-path testuri.rstests, and the decision-path testuri.rstests, and the decision-path testfile:toouri.rstests, and the decision-path testuri.rstests, and the decision-path testuri.rstestsfile:pathuri.rstests%in the host, before the unreserved decodeuri.rstests, and the decision-path testuri.rstestsuri.rstests, and the decision-path testuri.rstests, including the idempotency propertyfile:query refusalfile:-queryuri.rstests, and the decision-path testuri.rstestsuri.rstestshttp/httpsquery toouri.rstests, and the decision-path testfile:query away instead of refusingfile:-queryuri.rstests\from the refused set\under every schemehttpURI with no authorityfile:tooTwo 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 prefixcould 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-containmentandtest-integrefuse 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, andtest-integcannot launch aworkload at all, with or without
EXPERIMENTAL_LINUX_SUPPORT=TRUE. So the MCP doors have noend-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 oncewhile 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.mdgains the authority grammar, the four host forms that stayunfolded, the re-scoped port and userinfo residual, and what a
likepattern does and does notmatch.
docs/user/mcp-policy.mdgains a troubleshooting row for each refusal an operator can meet.No committed policy under
examples/, and no other page or skill, holds acontext.input.uriliteral.
The local
file:authority is parsed, not compared. Review found a claim this branch alreadymade that the code did not hold:
the_finding_bypass_classes_canonicalize_to_one_identitysaysevery equivalent spelling of "this machine" collapses, naming loopback IP literals, while the
comparison was text against two spellings. Node resolves
file://[::0001]/home/op/.envto the localfile, 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 theempty 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 therequest 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.
mainmoved under this branch and conflicted in the MCP troubleshootingtable, 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
docs/design/mcp.mdanddocs/user/mcp-policy.mdBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.