]> Sergey Matveev's repositories - public-inbox.git/commitdiff
http: reject excessive headers
authorEric Wong <e@80x24.org>
Sun, 6 Mar 2016 02:09:20 +0000 (02:09 +0000)
committerEric Wong <e@80x24.org>
Sun, 6 Mar 2016 02:10:24 +0000 (02:10 +0000)
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
t/httpd-corner.t

index 6c4c20d7cf801663af01beb71d3676bc941c6479..8988e7d22ef17534ea83d1f2293e501c44493fe7 100644 (file)
@@ -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);
 
index 833eb4294687361c06c38277e6bf3d7c98dc9ae9..8670846cad68eac0deb4e935c9f9ac3ec2d75da7 100644 (file)
@@ -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
 {