Skip to content

fix(mcp): preserve empty HTTP resource queries - #299

Merged
kevin-orellana merged 2 commits into
mainfrom
feature/mcp-preserve-empty-http-query
Nov 10, 2026
Merged

kevin-orellana merged 2 commits into
mainfrom
feature/mcp-preserve-empty-http-query

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Strands Box removes a final ? from an HTTP or HTTPS resource address. For example, https://example.com/report? becomes https://example.com/report. The two addresses can return different content. This changes the address that policy checks and that the Model Context Protocol (MCP) server receives. Box's HTTP gateway also removes an empty query when the resource server fetches that address.

Solution. Preserve an empty HTTP or HTTPS query through both operations: the MCP resource read and the server's later fetch through the gateway. Policy and the MCP server receive the same resource address. The destination HTTP server (web origin) receives the corresponding path and query, called the request target.

Trade-off. Exact resource rules distinguish addresses with and without ?. Each operation still requires its applicable policy checks. Empty queries on file: addresses remain removed, preserving the repair in #229.

Description

An address ending in ? has an empty query. An address without ? has no query. RFC 3986 section 6.2.3 says these forms cannot be assumed equivalent.

For an application requesting https://example.com/report? through an MCP server that fetches the same address:

Stage Before this change With this change
Resource address checked by MCP policy https://example.com/report https://example.com/report?
Resource address sent to the MCP server, if permitted https://example.com/report https://example.com/report?
Request target sent to the web origin, if permitted /report /report?

Figure 1: Box preserves an empty query through the resource-read message and the later HTTP fetch. Each operation requires a separate policy permit. The MCP labels abbreviate the full resource address to its path and query.

Before and after comparison for an application requesting https://example.com/report?. Before the change, Box removes the empty query before the MCP policy decision, and the resource server receives https://example.com/report. The web origin receives the request target /report. With the complete fix, MCP policy checks the address ending in /report?, the resource server receives that address, and the HTTP gateway forwards /report? to the web origin. The gateway applies a separate HTTP policy decision. Denied requests are not forwarded.

Download the editable draw.io source.

Gateway correction

The gateway now remembers whether the original request had an empty query before splitting its path and query. Both plain HTTP and intercepted HTTPS retain that distinction when constructing the forwarded request. This uses private state; public request types and policy attributes are unchanged.

A configured credential can modify query parameters before the gateway forwards a request. These edits retain their existing behavior. Adding a query parameter produces the usual ?name=value; removing the last parameter from an originally nonempty query removes its delimiter. A rewritten path that already contains a query does not receive another ?.

This addresses Abhishek's review. With a broad server permit and an exact forbid for https://example.com/report, that address is denied before server delivery. A permitted https://example.com/report? reaches the origin as /report?. The inverse forbid is also tested.

Related Issues

Follow-up to #229 and its empty-query review comment.

Type of Change

Bug fix

Testing

Local validation covers the final source tree, including the merge of main at 4268891.

Check Result
Admission and origin forwarding Four integration tests pass. They cover the exact forbid and its inverse over HTTP and intercepted HTTPS, using the production policy adapter.
Regression sensitivity Restoring the old gateway behavior fails both affected origin-target assertions and the gateway helper test. Restoring the old MCP behavior fails all four admission tests and all three URI tests. The corrected source passes again.
Gateway suite All 262 tests pass with all features enabled.
Formatting, lint, builds, and API documentation Formatting, workspace Clippy, strict gateway Clippy, gateway and policy builds with all features and without default features, and gateway documentation with warnings treated as errors pass.
Workspace suite One existing startup test timed out after eight seconds. The same binary then passed three exact reruns and all 18 tests in that target, without changing its timeout. No other test target failed. The cause of the timing failure is unconfirmed.
Deterministic containment suite GREEN: 131 cases pass, 10 declared macOS cases are skipped on Linux, and all 141 expected records are present. The runner reports coverage_gate=full.

Local Box tests used a private mount view because the unchanged mount parser rejects this host's Docker network-namespace handle. Tests ran as the original unprivileged user with no effective capabilities. The host mount table remained unchanged.

The first containment attempt exhausted disk space while creating fixtures. The successful rerun used copies of the same binaries with debug symbols removed. All loaded code and data sections and entry points were verified unchanged.

Coverage limits: the workspace run skipped an unavailable credential-daemon check and a Linux check that cannot independently deny reading an executable grant. Existing ignored tests remain ignored. The example build passed, but no scripted examples are present; the manual SDK tutorial was not run. GitHub checks for the updated commit are tracked separately below.

Updated commit: f56ffe3. GitHub checks passed, including Linux ARM64 and macOS unit tests and deterministic containment. The automated re-review completed on this commit with no new findings. Its assessment is "Approve," but its formal GitHub review is COMMENTED; human approval remains pending. Hosted results are separate from the local pass counts above.

The diagram passed structural checks and visual inspection.

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
  • 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

The resource URI normalizer removes an empty HTTP or HTTPS query. That can
change the address selected by resources/read from /report? to /report.
A server can return different content for those addresses.

## Solution

Preserve empty HTTP and HTTPS queries in the canonical policy input and
forwarded resource frame. Keep the file URI delimiter handling from #229.
Correct the resource-address explanation in docs/design/mcp.md.
Exact URI literals distinguish the two forms; patterns can cover both.

## Tests

an_empty_http_query_is_preserved and
an_empty_http_query_reaches_the_decision_and_forwarded_frame fail against
unchanged production code and pass with this fix. They check normalized
values, both request classifiers, and forwarded frames.
file_delimiters_fold_without_merging_http_queries retains file controls
and checks HTTP query identity. Restoring the old filter makes it fail.

On Amazon Linux 2023 ARM64, just check passed with 4,886 tests passed and
17 ignored. Workspace Clippy used the repository's vendored-code lint
allowances. All 244 gateway tests passed, as did both feature builds,
strict gateway Clippy, formatting, and the gateway documentation build.

The deterministic suite passed 131 cases with nine declared macOS-only
skips and no failures or errors. The example command built binaries;
no scripted examples remain. No live MCP server, manual SDK tutorial,
or macOS run was performed locally.

The prose checker reports 15 existing em-dash lines identical to the base.
Independent documentation review found no new prose issue.
Comment thread crates/egress-gateway/src/mcp/uri.rs Resolved
Comment thread crates/egress-gateway/src/mcp/uri.rs Resolved
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Comment

The change works for MCP servers that resolve the URI themselves. Policy input, the forwarded frame, and the canonical form stay consistent with each other. But the gateway's HTTP egress still folds an empty query, so the identity this PR keeps separate gets merged again when an in-box server fetches the resource (see the inline comment).

Checked and held
  • file: empty queries still fold, including FILE:///x? and file:///x?#. A non-empty file: query (file:///x??) is still refused.
  • The canonical form is a fixed point for https://h?, https://h:443/a?, https://h/a/..?, http://h/%7e? and https://h/a??.
  • HTTP and stdio classification and canonicalize_frame_uri agree. A ? inside a fragment (#?section) is still dropped.
  • No frozen surface changed: no pub use, policy attribute name, or record shape. The change adds no allow path, so policy stays the only authorizer.
  • The full strands-box-egress-gateway suite passes at 03e9680 with --all-features.

The regression coverage across both classification paths and the forwarded frame is thorough.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 4, 2026 09:00
@abhisheksp

Copy link
Copy Markdown
Contributor

The empty-query handling has now changed twice: the launch version kept https://h/a?, #229 dropped it, and this PR keeps it again. The file: part of #229 stays intact, which is good.

The HTTP part reopens the issue #229 closed. With permit server == "notes" and forbid uri == "https://notes/report", a read of https://notes/report? misses the forbid. When an in-box server fetches it through the gateway, reconstruct_target sends /report, so the origin gets the forbidden request.

Can the MCP layer and the gateway agree on what an empty query means before this merges? One option is to keep the fold from #229. The other is to merge this together with a gateway change that keeps the ?, plus an admission test for forbid == X against X?.

AI-assisted comment

Preserve an explicitly empty query through plain HTTP and intercepted HTTPS
without changing public request types. Add policy-to-origin regression tests
for exact URI forbids and retain complete MCP frames.

Merge main and resolve the MCP normalization documentation conflict.
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at f56ffe3)

The MCP layer and the gateway now agree: an empty HTTP/HTTPS query is kept as its own identity at every stage. That covers policy input, the forwarded frame, and the origin request target. This answers both the earlier gateway finding and @abhisheksp's request for an admission test of forbid == X against X?. I have no new findings.

Checked and held
  • Forwarding: the delimiter is kept for TLS origin-form /report?, for plain absolute-form http://h/report?, http://h? and …?#f, and for /report??. /report stays /report.
  • Credential edits on /report?:
    • strip gives /report?
    • add gives /report?key=value
    • a header edit gives /report?
    • a rewrite gets no second ?
    • stripping the last parameter from /report?key=x still gives /report, as before.
  • Signing: SigV4 over Target::url() builds the same canonical query as the forwarded /report?, so the signature stays valid.
  • Frozen surface: Target and the other public types are unchanged; the new state is a private bool. Policy is still the only authorizer, and http:request still judges the path without the query.
  • file:: the fix(egress-gateway): close resource URI respellings that dodge a uri rule #229 fold and the refusal of file: queries are intact.
  • Tests run locally at f56ffe3: the gateway suite with --all-features passes, and mcp_resource_query_e2e (4 tests, egress-adapter) passes. CI's --workspace --all-features run includes the e2e target.

The end-to-end test builds the fetch target from the frame the MCP server actually received, which is the right thing to anchor on.

@kevin-orellana

kevin-orellana commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

Addressed in f56ffe3. This PR now includes the gateway correction: a permitted read of https://notes/report? reaches the origin as /report?, preserving the address that policy checked.

Four integration tests cover forbidding /report while allowing /report?, and the inverse, over HTTP and HTTPS. All four passed on Linux ARM64 and macOS. The file: protection from #229 remains unchanged.

Could you take another look?

AI-assisted comment

@priyasingh2111

Copy link
Copy Markdown
Contributor

With this PR, forbid uri == "https://notes/report" does not block https://notes/report? (the version ending in ?).

Does forbid uri == "https://notes/report" block https://notes/report??
Current main (after #229) Yes. The trailing ? is removed before policy checks the URI, so the forbid matches.
With PR #299 No. The ? is kept, so the URIs differ and the read is allowed.

The PR's own tests confirm this. The read of X? is allowed, and the origin receives GET /report?.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

You’re right that the rule no longer blocks /report?. The URL standard says we cannot assume /report and /report? mean the same thing. A server can treat them differently.

That’s why this PR keeps the ? both when Box checks permission and when it sends the request. If the intent is to block both addresses, the rule needs to cover both explicitly. I think we should keep this behavior.

AI-assisted comment

@kevin-orellana
kevin-orellana merged commit 4bc0973 into main Nov 10, 2026
27 of 28 checks passed
@kevin-orellana
kevin-orellana deleted the feature/mcp-preserve-empty-http-query branch November 10, 2026 22:43
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.

4 participants