Skip to content

doc: document fetch() differences from the Fetch Standard#62236

Open
kovan wants to merge 2 commits intonodejs:mainfrom
kovan:doc/fetch-differences
Open

doc: document fetch() differences from the Fetch Standard#62236
kovan wants to merge 2 commits intonodejs:mainfrom
kovan:doc/fetch-differences

Conversation

@kovan
Copy link
Contributor

@kovan kovan commented Mar 13, 2026

Summary

Add a "Differences from the standard" section to the fetch documentation
in globals.md, covering:

  • No CORS enforcement (server-side, no origin)
  • Fewer forbidden headers (most removed, Host still restricted)
  • Response accepts async iterables (Node.js extension)
  • Response bodies must be consumed to avoid connection leaks
  • Content-Encoding layer limit of 5
  • Manual redirect returns actual response, not opaqueredirect

Based on the differences documented in undici's README
and the original issue description from @mcollina.

Fixes #52163

AI disclosure

This PR was authored with Claude Code. I reviewed and verified all
content against the undici source code and Fetch Standard specification.
The Host header correction (switching from "No forbidden headers" to
"Fewer forbidden headers") was prompted by @bakkot's review and verified
against undici#2322.

Add a 'Differences from the standard' section to the fetch
documentation listing the ways Node.js fetch (via undici) differs
from browser implementations: no CORS enforcement, no forbidden
headers, async iterable support in Response, response body
consumption requirements, Content-Encoding layer limits, and
manual redirect behavior.

Fixes nodejs#52163
@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Mar 13, 2026
not have an origin. All cross-origin requests are allowed by default.
* **No forbidden headers.** The [Fetch Standard][] forbids setting
certain headers (such as `Cookie`, `Host`, and `Origin`) in browser
contexts. Node.js removes these restrictions, allowing full control
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is true? Not for Host anyway. nodejs/undici#2369

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Host is unconditionally deleted by undici before dispatch (httpNetworkOrCacheFetch sets it from the URL). Updated the section to say "Fewer forbidden headers" and note the Host restriction specifically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's accurate but your commit message is wrong. The fix for the referenced CVE was about the host/cookie headers incorrectly carrying through redirects. The change to forbid setting Host on initial requests happened in nodejs/undici#2322 and was unrelated.

Incidentally, if you're using LLMs for any part of this, it's polite to disclose that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks for the correction. The CVE was about headers leaking through cross-origin redirects, not about the initial request restriction. Updated the commit message to reference undici#2322 instead.

Re LLMs: yes, I use Claude Code as part of my workflow. Happy to add a note if there's a preferred format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual thing is to add a line in the PR description describing what parts (of the code and also your comments) were done by the LLM vs you, and whether the correctness of the parts the LLM did is something you've reviewed and are qualified to review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR description with an AI disclosure section.

Host is restricted in Node.js fetch because undici disallows setting
it to align with Cloudflare Workers and Deno behavior (undici#2322).
Change "No forbidden headers" to "Fewer forbidden headers" and note
the Host restriction.
@kovan kovan force-pushed the doc/fetch-differences branch from cce0504 to bc825f9 Compare March 25, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document differences between Node.js fetch() implementations and the standard

4 participants