Skip to content

fix: prevent upstream body-presence rejection on proxied XRPC requests#146

Draft
webpro wants to merge 2 commits intoascorbic:mainfrom
webpro:fix/xrpc-proxy-body-headers
Draft

fix: prevent upstream body-presence rejection on proxied XRPC requests#146
webpro wants to merge 2 commits intoascorbic:mainfrom
webpro:fix/xrpc-proxy-body-headers

Conversation

@webpro
Copy link
Copy Markdown

@webpro webpro commented Mar 26, 2026

Summary

Fixes intermittent "A request body was provided when none was expected" errors when using the PDS on Cloudflare Workers. This affects both desktop (bsky.app) and mobile clients.

Root cause: Cloudflare Workers subrequests to CF-proxied origins (like api.bsky.app) intermittently inject transfer-encoding: chunked on the wire, even for GET requests with no body and clean headers. The upstream XRPC server (@atproto/xrpc-server) detects this header and rejects the request (bluesky-social/atproto#3267).

This is not controllable via the Headers object passed to fetch() — CF's internal routing adds it after the Worker's fetch() call. Confirmed by sending a completely empty new Headers() GET from a Worker to api.bsky.app and still receiving the 400.

Changes to handleXrpcProxy:

  • Header allowlist instead of blocklist — only forward accept, accept-encoding, accept-language, atproto-accept-labelers, if-none-match, if-modified-since, user-agent (+ content-type/content-length for POST). This prevents CF-internal headers (cf-*, transfer-encoding, te, x-forwarded-*, etc.) from leaking into subrequests.
  • Explicit Request constructor for GET/HEADfetch(new Request(url, { method, headers })) produces a cleaner wire format than fetch(url, { method, headers }) in the CF Workers runtime.
  • Retry (up to 3x) on the specific body-presence error — since the CF behavior is intermittent, a retry is a reliable safety net. In practice, the first or second attempt succeeds.

Test plan

  • Deployed to production PDS on Cloudflare Workers (pds.webpro.blue)
  • Verified GET queries (feed, notifications, profile, etc.) no longer fail with the body-presence error
  • Verified POST requests with bodies (createRecord, etc.) still work correctly
  • Confirmed iOS app and desktop browser (Firefox) both work

Cloudflare Workers subrequests to CF-proxied origins (like api.bsky.app)
intermittently inject transfer-encoding: chunked, causing the upstream
XRPC server to reject GET requests with 'A request body was provided
when none was expected' (bluesky-social/atproto#3267).

Changes:
- Switch from header blocklist to allowlist, preventing CF-internal
  headers (transfer-encoding, cf-*, etc.) from leaking into subrequests
- Use explicit Request constructor for GET/HEAD to produce a cleaner
  wire format
- Retry up to 3x on the specific body-presence 400 error as a safety
  net for CF intermittent behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@webpro
Copy link
Copy Markdown
Author

webpro commented Mar 26, 2026

The error kept popping up, a refresh usually resolved it, hence the retries. This PR does not solve the underlying issue, but it does remedy it for me fairly cleanly.

bsky

@ascorbic
Copy link
Copy Markdown
Owner

I wonder if this flag could help. I'm unsure if it applies to proxied requests or just worker-to-worker

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 29, 2026

Open in StackBlitz

npm i https://pkg.pr.new/create-pds@146
npm i https://pkg.pr.new/@getcirrus/oauth-provider@146
npm i https://pkg.pr.new/@getcirrus/pds@146

commit: ea425bc

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