user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH 1/3] http: reject excessive headers
Date: Sun,  6 Mar 2016 02:09:20 +0000	[thread overview]
Message-ID: <1457230162-10960-2-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1457230162-10960-1-git-send-email-e@80x24.org>

HTTP::Parser::XS::PP does not reject excessively large
headers like the XS version.  Ensure we reject headers
over 16K since public-inbox should never need such large
request headers.
---
 lib/PublicInbox/HTTP.pm |  6 +++++-
 t/httpd-corner.t        | 12 ++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 6c4c20d..8988e7d 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -70,7 +70,11 @@ sub rbuf_process {
 
 	# We do not support Trailers in chunked requests, for now
 	# (they are rarely-used and git (as of 2.7.2) does not use them)
-	return quit($self, 400) if $r == -1 || $env{HTTP_TRAILER};
+	if ($r == -1 || $env{HTTP_TRAILER} ||
+			# this length-check is necessary for PURE_PERL=1:
+			($r == -2 && length($self->{rbuf}) > 0x4000)) {
+		return quit($self, 400);
+	}
 	return $self->watch_read(1) if $r < 0; # incomplete
 	$self->{rbuf} = substr($self->{rbuf}, $r);
 
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index 833eb42..8670846 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -84,6 +84,18 @@ my $spawn_httpd = sub {
 	is($body, "hello world\n", 'callback body matches expected');
 }
 
+{
+	my $conn = conn_for($sock, 'excessive header');
+	$SIG{PIPE} = 'IGNORE';
+	$conn->write("GET /callback HTTP/1.0\r\n");
+	foreach my $i (1..500000) {
+		last unless $conn->write("X-xxxxxJunk-$i: omg\r\n");
+	}
+	ok(!$conn->write("\r\n"), 'broken request');
+	ok($conn->read(my $buf, 8192), 'read response');
+	my ($head, $body) = split(/\r\n\r\n/, $buf);
+	like($head, qr/\b400\b/, 'got 400 response');
+}
 
 # Unix domain sockets
 {
-- 
EW


  reply	other threads:[~2016-03-06  2:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-06  2:09 [PATCH 0/3] http: some DoS prevention Eric Wong
2016-03-06  2:09 ` Eric Wong [this message]
2016-03-06  2:09 ` [PATCH 2/3] http: ensure errors are printable before PSGI env Eric Wong
2016-03-06  2:09 ` [PATCH 3/3] http: reject excessively large HTTP request bodies Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457230162-10960-2-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).