Skip to content

fix(batch): add missing early return in nodeHttpBatchRpcResponse on non-POST#195

Merged
teamchong merged 1 commit into
cloudflare:mainfrom
aleister1102:fix/node-batch-405-early-return
Jul 4, 2026
Merged

fix(batch): add missing early return in nodeHttpBatchRpcResponse on non-POST#195
teamchong merged 1 commit into
cloudflare:mainfrom
aleister1102:fix/node-batch-405-early-return

Conversation

@aleister1102

Copy link
Copy Markdown
Contributor

Summary

nodeHttpBatchRpcResponse wrote a 405 status for non-POST requests via response.writeHead(405, ...) but was missing response.end() and return. Execution fell through into the full RPC pipeline unconditionally, then crashed with ERR_HTTP_HEADERS_SENT when the function later tried to write the 200 response — leaving the TCP connection open until timeout.

The Fetch API counterpart (newHttpBatchRpcResponse) was unaffected; it already returned a 405 Response immediately.

Changes

  • src/batch.ts: add response.end() and return after the 405 writeHead call in nodeHttpBatchRpcResponse

Test plan

  • Verify a non-POST request to a nodeHttpBatchRpcResponse endpoint now receives a 405 with a closed connection and no RPC handlers are invoked
  • Verify a valid POST request continues to work normally

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@aleister1102

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jun 11, 2026
@aleister1102

aleister1102 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi @teamchong @kentonv, could you take a look when you get a chance? This is the fix for the missing early return discussed in the HackerOne report. The change is minimal - two lines in src/batch.ts. Thanks!

@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/capnweb@195

commit: 3b3b24c

@teamchong

Copy link
Copy Markdown
Collaborator

verified the fix locally. on main a GET to this endpoint never gets a response, the socket just stays open until timeout, and there's an unhandled ERR_HTTP_HEADERS_SENT rejection later when the pipeline runs anyway.

with your branch it returns the 405 immediately. So the change is correct.

two things to add before this can merge (snippets below are just a starting point, adjust as you see fit):

a changeset (the release automation needs it):

.changeset/non-post-early-return.md

---
"capnweb": patch
---

Fix nodeHttpBatchRpcResponse leaving the connection open and crashing with
ERR_HTTP_HEADERS_SENT on non-POST requests. It now returns 405 immediately.

and a regression test, since this path had no coverage. In __tests__/index.test.ts, inside the existing describe("HTTP requests") block:

  it("rejects non-POST requests with 405", async () => {
    let response = await fetch(`http://${inject("testServerHost")}`, { method: "GET" });
    expect(response.status).toBe(405);
    await response.text();
  });

this hangs on main and passes with your fix, so it actually catches the regression.

Thanks!

@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3b3b24c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
capnweb Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@aleister1102 aleister1102 force-pushed the fix/node-batch-405-early-return branch from 4883dd7 to f684df8 Compare June 11, 2026 16:50
@aleister1102

aleister1102 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Done - thanks for verifying the fix locally, @teamchong.

Added both items:
• Changeset: .changeset/non-post-early-return.md
• Regression test: rejects non-POST requests with 405 in the existing describe ("HTTP requests") block

Confirmed locally that the new test passes on this branch. Should be ready for another look.

@kentonv

kentonv commented Jul 3, 2026

Copy link
Copy Markdown
Member

Hmm looks good to me but the new test seems to be failing.

…sponse

Without response.end() and return, non-POST requests fell through into the
RPC pipeline and crashed with ERR_HTTP_HEADERS_SENT. Forward options.headers
on the 405 path so cross-origin browser clients receive CORS headers.

Co-authored-by: Cursor <cursoragent@cursor.com>
@aleister1102 aleister1102 force-pushed the fix/node-batch-405-early-return branch from f684df8 to 3b3b24c Compare July 4, 2026 13:38
@aleister1102 aleister1102 requested a review from kentonv July 4, 2026 13:40
@teamchong teamchong merged commit 78744ca into cloudflare:main Jul 4, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 4, 2026
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.

3 participants