Skip to content

feat(egress): stream responses with credential redaction - #345

Merged
pgrayy merged 5 commits into
mainfrom
feature/egress-stream-replies
Nov 7, 2026
Merged

pgrayy merged 5 commits into
mainfrom
feature/egress-stream-replies

Conversation

@hanaduy

@hanaduy hanaduy commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

The gateway buffers complete responses and rejects bodies above 16 MiB. This delays interactive output until a response finishes and breaks large package downloads.

Stream HTTP responses with backpressure, including credential-bound responses and MCP replies. Credential redaction runs before delivery and retains a credential-sized tail between chunks, so partial matches do not change release boundaries. Small events can wait for more data or clean completion. MCP tools/list keeps bounded capture so schema staging finishes before release.

HTTP and HTTP MCP request outcomes remain pending until the upstream response completes, fails, or reaches its deadline. If downstream delivery ends early, the connection retains the upstream reader and drains it under the existing deadline and connection cap. A workload disconnect cannot advance a temporal prerequisite. Downstream delivery retains its own partial or failed outcome. Existing partial and uncertain outcome semantics remain; a ::response does not prove tool success.

The existing 300-second upstream deadline remains absolute, including when downstream backpressure stalls an incomplete upstream response. Request bodies and tools/list capture retain their 16 MiB limits. Timeout configuration and upload streaming are separate follow-ups.

The Rust interface adds the opaque ResponseRedactor and Vault::response_redactor, and removes the unused EffectAttempt::ResponseRelease.body_bytes field. Consumers constructing that attempt must omit the field. No configuration or stored-record format changes.

Related Issues

Closes #171. Upload limits in #172 remain.

Type of Change

Bug fix; breaking Rust interface change; documentation update.

Testing

  • Latest macOS workspace run: 4,751 passed, 17 ignored, one failed. The failure is the tool-grammar fixture introduced by test(policy): verify ::response events for tool grammar actions #333: macOS rejects its copied /usr/bin/false with a launch-constraint violation. The same test fails on unchanged main (c8856a1), and the copied executable fails outside Box. A separate fixture-only prototype makes all 11 tool-grammar tests pass; that fix is not included here.
  • Builds, formatting, lint, feature variants, rustdoc, and site-manifest checks passed. No warnings in the changed crates. Runtime skips cover unavailable credential-daemon and local Node/Python fixtures, plus non-UTF-8 filenames. The manual SDK tutorial was not run.
  • Deterministic containment: 129 passed and 12 declared Linux-only skips; no failures or coverage-integrity problems.
  • Coverage includes early HTTP/HTTPS delivery, large downloads, bounded cross-chunk redaction, fixed-tail release boundaries, MCP schema staging, absolute deadlines, release denial, and partial-response outcomes.
  • All 26 gateway lifecycle tests pass. Disconnect and release-refusal regressions verify that an open upstream response stays pending. Real-policy coverage checks HTTP and HTTP MCP temporal prerequisites through clean completion, truncation, and deadline expiry, including after disconnect. Independent mutation checks confirm all three affected regressions fail against the pre-fix implementation and pass with this fix.
  • Manual checks on the earlier streaming revision confirmed progressive Claude Code output and cold npm downloads, including 31 MB Next.js and 40 MB workerd packages. Those checks were not repeated for the lifecycle follow-up. Complete corpus cases remain blocked by unrelated policy denials.

Linux validation of the latest commit is left to PR CI; the local cross-check lacks aarch64-linux-gnu-gcc.

Checklist

  • Read the contributing guide and reviewed the implementation.
  • Kept the change focused on response streaming.
  • Added regression coverage and updated affected documentation.
  • Ran integrated checks and an independent review; disclosed the unrelated fixture failure.

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

The gateway reads every response body whole before the workload gets any of
it, and refuses one over 16 MiB (#171). So an npm package
over 16 MiB, a large Git pack, or a long download cannot pass through a box.

Only two steps need the whole body: the leak-back scrub, for a target with a
bound credential, and catalog staging, for a configured MCP server. A
response that neither applies to, and that does not answer a HEAD request,
now streams. The gateway checks its head as before, claims the
ResponseRelease before the first body byte, and hands the body to the
workload as hyper reads it. The upstream is read only as fast as the
workload reads, so memory no longer grows with the body.

- ResponseRelease.body_bytes becomes Option<usize>: the bytes in hand for a
  buffered response, the declared Content-Length for a streamed one, and
  None for a chunked one. The policy adapter and telemetry read nothing from
  it, so no decision changes. The release outcome reports the bytes the
  workload took, and a body that fails partway is reported as Partial.
- The 300 s upstream deadline covers the wait for a streamed response's
  head. After that, each gap between body pieces may last 300 s.
- A credentialed target or an MCP server keeps the buffered path and the
  16 MiB limit. Request bodies stay buffered.

Two behaviours change for a streamed response: a body the upstream cuts
short reaches the workload up to the cut, and a chunked body stays chunked.
Tests for the old behaviour now run against a credentialed target, which is
still buffered.

Prototype for the design in #171. The design is not
reviewed yet.
@github-actions github-actions Bot added Area - Egress/Creds enhancement New feature or request labels Nov 6, 2026
@hanaduy
hanaduy requested a review from zastrowm November 6, 2026 02:38
@hanaduy
hanaduy marked this pull request as ready for review November 6, 2026 03:06
Deliver response bodies progressively with bounded credential redaction.
Keep tools/list capture for schema staging and preserve the absolute upstream
deadline. Remove the unused response-release body length and document the
streaming behavior and remaining limits.

Integrate current main while preserving the existing PR history.

Co-authored-by: Patrick Gray <[email protected]>
@pgrayy pgrayy changed the title feat(egress): stream a response that no credential or MCP server reads feat(egress): stream responses with credential redaction Nov 6, 2026
Comment thread docs/user/policy/actions.md Resolved
@strands-agents strands-agents deleted a comment from github-actions Bot Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Assessment: Approve

I reviewed a45df1f, the changes since 2da671c. ResponseCompletion now keeps the upstream reader until receipt actually ends, which closes the disconnect shortcut. I found nothing new that should block the merge.

Checks that held
  • Clean end: finish() re-polls a reader that has already received the whole body. Incoming returns None, so there is no delay and nothing is recorded twice.
  • Upstream failure, bad trailer, serve deadline: the reader is already Failed, so finish() returns at once with Err. The request outcome was recorded in poll_frame.
  • Workload disconnects, upstream keeps streaming: the upstream is drained until it ends or reaches the reader's deadline. Only then are the request outcome and the release outcome recorded, in that order.
  • Workload disconnects, upstream silent: the serve deadline fires, the reader fails, and the drain returns at once.
  • Release denied, or a refused encoded/collected body: the upstream is drained under the same deadline before the request outcome. The added assertion in response_release_denial_sends_no_upstream_head_or_body covers this.
  • No head (send error): completion stays empty, and the request outcome is recorded on the error path as before.
  • Per-connection scope: serve_connection and intercept_tls each create their own ResponseCompletion. Since Upstream::send consumes self, there is one body per completion.
  • Written rules: the new egress-gateway AGENTS.md rule ("drain within the connection's runtime and slot") matches the code. The README, docs/design/policy.md and actions.md now say "reaches its deadline" instead of "abandoned".
  • Tests: the gateway suite and temporal_egress_mitm_e2e (with --features egress-adapter) pass locally.

The added disconnect rows in the real-policy e2e test guard the precondition case directly.

@strands-agents strands-agents deleted a comment from github-actions Bot Nov 6, 2026
@pgrayy
pgrayy merged commit f44b084 into main Nov 7, 2026
27 checks passed
@pgrayy
pgrayy deleted the feature/egress-stream-replies branch November 7, 2026 00:34
@github-actions github-actions Bot mentioned this pull request Nov 7, 2026
8 tasks done
leo237 pushed a commit to leo237/box that referenced this pull request Nov 10, 2026
… refuse dead/unsafe re-routes

Addresses the human review of the re-routing CR (code only; not every comment).

- redact box-owned backend token in streamed responses. `Vault::response_redactor`
  (the strands-agents#345 streaming scrubber) read only `opaque`, so a backend echoing
  `Authorization` returned the backend token to the workload. It now covers
  `box_owned` as `redact_leaks` does. Pinned by the e2e
  `a_backend_echo_of_its_token_is_redacted`.
- stop double-encoding the SigV4 canonical query. The query arrives already
  percent-encoded, and `canonical_query` re-encoded it (`%3A` -> `%253A`), so an
  encoded query (a GitHub search re-route) signed wrong and AWS answered 403. It
  now decodes each key/value before encoding once. Pinned by
  `canonical_query_encodes_each_parameter_exactly_once`.
- refuse a destination `secret` beside an `http` backend at load. Its strip route
  matched the original destination and tripped the plaintext-credential floor,
  403ing every request. Pinned by
  `a_destination_secret_beside_an_http_backend_is_refused`.
- refuse an encoded path separator (`%2F`, `%5C`) in a re-routed path under a
  backend prefix, which the backend could decode to escape the prefix. Pinned by
  `a_backend_reroute_refuses_an_encoded_separator_in_the_path`.
leo237 pushed a commit to leo237/box that referenced this pull request Nov 11, 2026
… refuse dead/unsafe re-routes

Addresses the human review of the re-routing CR (code only; not every comment).

- redact box-owned backend token in streamed responses. `Vault::response_redactor`
  (the strands-agents#345 streaming scrubber) read only `opaque`, so a backend echoing
  `Authorization` returned the backend token to the workload. It now covers
  `box_owned` as `redact_leaks` does. Pinned by the e2e
  `a_backend_echo_of_its_token_is_redacted`.
- stop double-encoding the SigV4 canonical query. The query arrives already
  percent-encoded, and `canonical_query` re-encoded it (`%3A` -> `%253A`), so an
  encoded query (a GitHub search re-route) signed wrong and AWS answered 403. It
  now decodes each key/value before encoding once. Pinned by
  `canonical_query_encodes_each_parameter_exactly_once`.
- refuse a destination `secret` beside an `http` backend at load. Its strip route
  matched the original destination and tripped the plaintext-credential floor,
  403ing every request. Pinned by
  `a_destination_secret_beside_an_http_backend_is_refused`.
- refuse an encoded path separator (`%2F`, `%5C`) in a re-routed path under a
  backend prefix, which the backend could decode to escape the prefix. Pinned by
  `a_backend_reroute_refuses_an_encoded_separator_in_the_path`.
leo237 pushed a commit to leo237/box that referenced this pull request Nov 11, 2026
… refuse dead/unsafe re-routes

Addresses the human review of the re-routing CR (code only; not every comment).

- redact box-owned backend token in streamed responses. `Vault::response_redactor`
  (the strands-agents#345 streaming scrubber) read only `opaque`, so a backend echoing
  `Authorization` returned the backend token to the workload. It now covers
  `box_owned` as `redact_leaks` does. Pinned by the e2e
  `a_backend_echo_of_its_token_is_redacted`.
- stop double-encoding the SigV4 canonical query. The query arrives already
  percent-encoded, and `canonical_query` re-encoded it (`%3A` -> `%253A`), so an
  encoded query (a GitHub search re-route) signed wrong and AWS answered 403. It
  now decodes each key/value before encoding once. Pinned by
  `canonical_query_encodes_each_parameter_exactly_once`.
- refuse a destination `secret` beside an `http` backend at load. Its strip route
  matched the original destination and tripped the plaintext-credential floor,
  403ing every request. Pinned by
  `a_destination_secret_beside_an_http_backend_is_refused`.
- refuse an encoded path separator (`%2F`, `%5C`) in a re-routed path under a
  backend prefix, which the backend could decode to escape the prefix. Pinned by
  `a_backend_reroute_refuses_an_encoded_separator_in_the_path`.
siwachabhi pushed a commit that referenced this pull request Nov 17, 2026
@siwachabhi siwachabhi mentioned this pull request Nov 17, 2026
4 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Stream egress responses and support downloads larger than 16 MiB

3 participants