Skip to content

fix: require CR before LF ending an HTTP/0.9 request line (stricter default) - #878

Merged
ShogunPanda merged 2 commits into
nodejs:mainfrom
MegaManSec:2
Nov 25, 2026
Merged

ShogunPanda merged 2 commits into
nodejs:mainfrom
MegaManSec:2

Conversation

@MegaManSec

@MegaManSec MegaManSec commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Behavior change: strict mode now rejects GET /\n\n (previously accepted as HTTP/0.9) with CR_EXPECTED. Set OPTIONAL_CR_BEFORE_LF (llhttp_set_lenient_optional_cr_before_lf) to keep the old behavior.

A request line terminated by a lone LF is accepted unconditionally, because the bare-LF exit from URL parsing shares the toHTTP09 adaptor with the CRLF exit. The equivalent response-line case is already gated on OPTIONAL_CR_BEFORE_LF in res_status, so the two sides disagree:

GET /\n\n                 -> accepted, v=0/9
HTTP/1.1 200 OK\n...       -> error 25, "Missing expected CR after response line"

This adds a separate toHTTP09BareLF exit node and routes it through checkIfAllowLFWithoutCR, so a bare LF after the URL errors with CR_EXPECTED in strict mode and is still accepted when LENIENT_FLAGS.OPTIONAL_CR_BEFORE_LF is set.

Tests in test/request/sample.md cover both modes, mirroring the existing No carriage ret / No carriage ret (lenient) pair in test/response/sample.md.

The bare-LF exit from URL parsing shared `toHTTP09` with the CRLF exit, so a
request line ending in a lone LF was always accepted. Route it through a
separate `toHTTP09BareLF` node gated on `OPTIONAL_CR_BEFORE_LF`, matching how
`res_status` already handles the response line.
@ShogunPanda

ShogunPanda commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Thanks! The change looks correct: in strict mode GET /\n\n now fails with CR_EXPECTED, while OPTIONAL_CR_BEFORE_LF still accepts it as HTTP/0.9.

Being strict by default is the intended behavior, so this is good as is. Please just mention it in the PR description / changelog, so the change in strictness is visible when we bump llhttp in Node.

@MegaManSec MegaManSec changed the title fix: require CR before LF terminating an HTTP/0.9 request line fix: require CR before LF ending an HTTP/0.9 request line (stricter default) Nov 24, 2026
@MegaManSec

Copy link
Copy Markdown
Contributor Author

Done: title now flags the stricter default (release notes use it), and the description opens with the behavior change and the lenient flag.

@ShogunPanda

Copy link
Copy Markdown
Contributor

Thanks! Couple of months ago I forgot to approve CI run. Do you mind making an empty commit so I can verify CI and we can land for good?

@MegaManSec

MegaManSec commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Done

@ShogunPanda
ShogunPanda merged commit 5aa5ac1 into nodejs:main Nov 25, 2026
7 checks passed
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