Skip to content

fix: require CR before LF terminating an HTTP/0.9 request line - #878

Open
MegaManSec wants to merge 1 commit into
nodejs:mainfrom
MegaManSec:2
Open

fix: require CR before LF terminating an HTTP/0.9 request line#878
MegaManSec wants to merge 1 commit into
nodejs:mainfrom
MegaManSec:2

Conversation

@MegaManSec

Copy link
Copy Markdown

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.

Note this tightens strict-mode parsing: GET /\n\n was previously accepted and now errors. Callers relying on it need the lenient flag.

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.
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.

1 participant