Skip to content

Improve compliance with RFC 9112 for status line parsing#298

Open
osyoyu wants to merge 1 commit into
ruby:masterfrom
osyoyu:rfc9112-statusline
Open

Improve compliance with RFC 9112 for status line parsing#298
osyoyu wants to merge 1 commit into
ruby:masterfrom
osyoyu:rfc9112-statusline

Conversation

@osyoyu
Copy link
Copy Markdown
Contributor

@osyoyu osyoyu commented May 13, 2026

This patch improves compliance with RFC 9112 Section 4 for parsing the status-line of the HTTP response.

  • Require the HTTP version to be in the format "HTTP/x.y"
    • Disallow cases like "http/1.1" (lowercase "http"), "HTTP" (missing version), "HTTP/10.23" (multidigit versions)
  • Require a space between the status-code and the reason-phrase, even when the reason-phrase is empty
    • Disallow cases like "HTTP/1.1 200" (missing space after status code)
  • Make clear that SP parsing operates on the lenient behavior, which allows 'HTAB, VT (%x0B), FF (%x0C), or bare CR' in addition to space

https://datatracker.ietf.org/doc/html/rfc9112#name-status-line

This patch improves compliance with RFC 9112 Section 4 for parsing the
status-line of the HTTP response.

- Require the HTTP version to be in the format "HTTP/x.y"
  - Disallow cases like "http/1.1" (lowercase "http"), "HTTP" (missing
    version), "HTTP/10.23" (multidigit versions)
- Require a space between the status-code and the reason-phrase, even
  when the reason-phrase is empty
  - Disallow cases like "HTTP/1.1 200" (missing space after status code)
- Make clear that SP parsing operates on the lenient behavior, which
  allows 'HTAB, VT (%x0B), FF (%x0C), or bare CR' in addition to space
@osyoyu osyoyu force-pushed the rfc9112-statusline branch 2 times, most recently from 1965596 to b9212e4 Compare May 13, 2026 15:06
@osyoyu
Copy link
Copy Markdown
Contributor Author

osyoyu commented May 13, 2026

Regarding the lenient behavior on parsing SP: I personally don't think we need to keep this. OpenJDK java.net.http, Go net/http, undici all only accept single whitespaces, indicating status lines like HTTP/1.1\t200\rOK do not exist much in the wild.

Reference (RFC 9112 Section 4):

Although the status-line grammar rule requires that each of the component elements be separated by a single SP octet, recipients MAY instead parse on whitespace-delimited word boundaries and, aside from the line terminator, treat any form of whitespace as the SP separator while ignoring preceding or trailing whitespace; such whitespace includes one or more of the following octets: SP, HTAB, VT (%x0B), FF (%x0C), or bare CR. However, lenient parsing can result in response splitting security vulnerabilities if there are multiple recipients of the message and each has its own unique interpretation of robustness (see Section 11.1).

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