-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require CRLF line endings in request line and headers #138
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -458,7 +458,7 @@ def read_request_line(socket) | |
end | ||
|
||
@request_time = Time.now | ||
if /^(\S+)\s+(\S++)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line | ||
if /^(\S+) (\S++)(?: HTTP\/(\d+\.\d+))?\r\n/mo =~ @request_line | ||
@request_method = $1 | ||
@unparsed_uri = $2 | ||
@http_version = HTTPVersion.new($3 ? $3 : "0.9") | ||
|
@@ -471,7 +471,7 @@ def read_request_line(socket) | |
def read_header(socket) | ||
if socket | ||
while line = read_line(socket) | ||
break if /\A(#{CRLF}|#{LF})\z/om =~ line | ||
break if /\A#{CRLF}\z/om =~ line | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, breaking lines on bare LF is allowed by the RFCs, so the old behavior was not a violation. From RFC 9112, section 2.2:
Again, many popular servers (Apache, Lighttpd, Node.js, Passenger, Puma) require CRLF line endings, so you're unlikely to break compatibility by joining that club. |
||
if (@request_bytes += line.bytesize) > MAX_HEADER_LENGTH | ||
raise HTTPStatus::RequestEntityTooLarge, 'headers too large' | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the old behavior is technically RFC-compliant.
RFC 9112 section 3:
That said, this isn't a bad change. Apache rejects request lines that use whitespace other than a single SP octet, so I don't think you'll break compatibility with any clients by tightening this up.