-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strict validation of content length and chunk length. (#20)
- Loading branch information
Showing
4 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# frozen_string_literal: true | ||
|
||
# Released under the MIT License. | ||
# Copyright, 2019-2023, by Samuel Williams. | ||
|
||
require 'protocol/http1/connection' | ||
require 'connection_context' | ||
|
||
describe Protocol::HTTP1::Connection do | ||
include_context ConnectionContext | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
def before | ||
super | ||
|
||
client.stream.write(input) | ||
client.stream.close | ||
end | ||
|
||
with "invalid hexadecimal content-length" do | ||
def input | ||
<<~HTTP.gsub("\n", "\r\n") | ||
POST / HTTP/1.1 | ||
Host: a.com | ||
Content-Length: 0x10 | ||
Connection: close | ||
0123456789abcdef | ||
HTTP | ||
end | ||
|
||
it "should fail to parse the request body" do | ||
expect do | ||
server.read_request | ||
end.to raise_exception(Protocol::HTTP1::BadRequest) | ||
end | ||
end | ||
|
||
with "invalid +integer content-length" do | ||
def input | ||
<<~HTTP.gsub("\n", "\r\n") | ||
POST / HTTP/1.1 | ||
Host: a.com | ||
Content-Length: +16 | ||
Connection: close | ||
0123456789abcdef | ||
HTTP | ||
end | ||
|
||
it "should fail to parse the request body" do | ||
expect do | ||
server.read_request | ||
end.to raise_exception(Protocol::HTTP1::BadRequest) | ||
end | ||
end | ||
|
||
with "invalid -integer content-length" do | ||
def input | ||
<<~HTTP.gsub("\n", "\r\n") | ||
POST / HTTP/1.1 | ||
Host: a.com | ||
Content-Length: -16 | ||
Connection: close | ||
0123456789abcdef | ||
HTTP | ||
end | ||
|
||
it "should fail to parse the request body" do | ||
expect do | ||
server.read_request | ||
end.to raise_exception(Protocol::HTTP1::BadRequest) | ||
end | ||
end | ||
|
||
with "invalid hexidecimal chunk size" do | ||
def input | ||
<<~HTTP.gsub("\n", "\r\n") | ||
POST / HTTP/1.1 | ||
Host: a.com | ||
Transfer-Encoding: chunked | ||
Connection: close | ||
0x10 | ||
0123456789abcdef | ||
0 | ||
HTTP | ||
end | ||
|
||
it "should fail to parse the request body" do | ||
authority, method, target, version, headers, body = server.read_request | ||
|
||
expect(body).to be_a(Protocol::HTTP1::Body::Chunked) | ||
|
||
expect do | ||
body.read | ||
end.to raise_exception(Protocol::HTTP1::BadRequest) | ||
end | ||
end | ||
|
||
with "invalid +integer chunk size" do | ||
def input | ||
<<~HTTP.gsub("\n", "\r\n") | ||
POST / HTTP/1.1 | ||
Host: a.com | ||
Transfer-Encoding: chunked | ||
Connection: close | ||
+10 | ||
0123456789abcdef | ||
0 | ||
HTTP | ||
end | ||
|
||
it "should fail to parse the request body" do | ||
authority, method, target, version, headers, body = server.read_request | ||
|
||
expect(body).to be_a(Protocol::HTTP1::Body::Chunked) | ||
|
||
expect do | ||
body.read | ||
end.to raise_exception(Protocol::HTTP1::BadRequest) | ||
end | ||
end | ||
end |
curl 8.1.2 (x86_64-apple-darwin21.0) libcurl/8.1.2 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.45.1
Release-Date: 2023-05-30
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe UnixSockets