Skip to content

Send an outbound call on as the caller wrote it - #520

Merged
mariojgt merged 1 commit into
mainfrom
egress-keep-callers-request
Nov 26, 2026
Merged

mariojgt merged 1 commit into
mainfrom
egress-keep-callers-request

Conversation

@mariojgt

Copy link
Copy Markdown
Contributor

With the outbound guard on, some fetch calls that carry a body failed with TypeError: Cannot construct a Request with a Request object that has already been used. GET requests were not affected, so an app could look healthy while its writes failed.

What was wrong

The guard builds a Request from the caller's arguments to read the destination. Building one from a caller's own Request takes that Request's body.

  • When the caller handles redirects itself (redirect: 'manual' or 'error'), the guard then sent the caller's original Request, which no longer had a body to send. This fails on every such call, in plain Node as well as under a framework.
  • When the guard follows redirects, it sent its own Request, already cloned, in place of the caller's arguments. A framework that patches fetch and rebuilds what it is handed was given something other than what the app wrote.

What changed

  • A caller that handles redirects itself has its destination read straight off the arguments, and the call goes on untouched.
  • A call whose body can be read again (a string, bytes, form fields, a blob, or no body) goes out with the caller's own input and init, including its signal. The guard keeps a copy of the body and reads it only if a 307 or 308 arrives.
  • A body that can be read once (a stream, or a caller's Request while the guard follows redirects) travels as before.

Every hop is still screened, and a redirect to a disallowed address is still refused.

Checked

  • New tests in tests/protect/egress-callers-own-request.test.ts; five of the eight fail without the change.
  • A Next.js 16.4.6 app on Node 22.23.2 with the guard installed over the framework's fetch: GET, POST and PUT with string, bytes and Request bodies, with a timeout signal, with the framework's caching options, and through a 307. All pass.
  • npm test passes except tests/field-test-cli-log.test.ts, which fails on my machine on a temp-path difference and does not involve this code. capabilities:check and typecheck pass.
  • Not checked: I could not make a body-carrying call hang, which was also reported, with either the old or the new code.

🤖 Generated with Claude Code

A caller's Request with a body was left unusable when the caller handled
redirects itself, and a body given in init was handed on inside a Request
the guard had built and cloned.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderbuds

coderbuds Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🎯 Elite quality (98%) — Fixes body-consumption failures in the egress guard by sending the caller's own arguments, with regression tests for each path.

📦 Medium

🤖 Written by Claude Code — going by its own attribution. Unknown whether a person read it; agents can report that with the report-ai-usage-tool tool.

🟢 Low risk — 78 lines of code, and nothing that needs a person.

✅ Reviewed — approved by @daniloradovic.

🩺 Coderbuds triage found nothing that should stop this merge, but worth a look: Adds lazy body capture for oversized bodies with no test in src/protect/egress.js, with no test in this change. It only counts on Minimal or Low risk changes of up to 50 lines of code, so this one needs a person's approval or your own AI review.

See how your team is trending →

@mariojgt

Copy link
Copy Markdown
Contributor Author

/review

@mariojgt
mariojgt merged commit ddd89b7 into main Nov 26, 2026
28 checks passed
@mariojgt
mariojgt deleted the egress-keep-callers-request branch November 26, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants