CVE-2022-31081: Inconsistent Interpretation of HTTP Requests ('HTTP Request/Response Smuggling') (CWE-444)
value: HTTP::Daemon is a simple http server class written in perl. Versions prior to 6.15 are subject to a vulnerability which could potentially be exploited to gain privileged access to APIs or poison intermediate caches. It is uncertain how large the risks are, most Perl based applications are served on top of Nginx or Apache, not on the `HTTP::Daemon`. This library is commonly used for local development and tests. Users are advised to update to resolve this issue. Users unable to upgrade may add additional request handling logic as a mitigation. After calling `my $rqst = $conn->get_request()` one could inspect the returned `HTTP::Request` object. Querying the 'Content-Length' (`my $cl = $rqst->header('Content-Length')`) will show any abnormalities that should be dealt with by a `400` response. Expected strings of 'Content-Length' SHOULD consist of either a single non-negative integer, or, a comma separated repetition of that number. (that is `42` or `42, 42, 42`). Anything else MUST be rejected.
CWE description: The product acts as an intermediary HTTP agent
         (such as a proxy or firewall) in the data flow between two
         entities such as a client and server, but it does not
         interpret malformed HTTP requests or responses in ways that
         are consistent with how the messages will be processed by
         those entities that are at the ultimate destination.
CVSS v3 base score: 6.5
Published: 2022-06-27T21:15Z
Repository: https://github.com/libwww-perl/HTTP-Daemon
Language: Perl
Files changed: lib/HTTP/Daemon.pm
Commit date: 2022-06-27 10:35:42 -0400
Commit message: Include reason in response body content
Diff: diff --git a/lib/HTTP/Daemon.pm b/lib/HTTP/Daemon.pm
index a5112b3f..2d022aec 100644
--- a/lib/HTTP/Daemon.pm
+++ b/lib/HTTP/Daemon.pm
@@ -297,20 +297,22 @@ READ_HEADER:
         my @vals = map {my $str = $_; $str =~ s/^\s+//; $str =~ s/\s+$//; $str }
             split ',', $ct_len;
         # check that they are all numbers (RFC: Content-Length = 1*DIGIT)
         my @nums = grep { /^[0-9]+$/} @vals;
         unless (@vals == @nums) {
-            $self->send_error(400);
-            $self->reason("Content-Length value must be a unsigned integer");
+            my $reason = "Content-Length value must be an unsigned integer";
+            $self->send_error(400, $reason);
+            $self->reason($reason);
             return;
         }
         # check they are all the same
         my $ct_len = shift @nums;
         foreach (@nums) {
             next if $_ == $ct_len;
-            $self->send_error(400);
-            $self->reason("Content-Length values are not the same");
+            my $reason = "Content-Length values are not the same";
+            $self->send_error(400, $reason);
+            $self->reason($reason);
             return;
         }
         # ensure we have now a fixed header, with only 1 value
         $r->header('Content-Length' => $ct_len);
 

Vulnerable code:             $self->send_error(400);
            $self->reason("Content-Length value must be a unsigned integer");
            $self->send_error(400);
            $self->reason("Content-Length values are not the same");
Fixed code:             my $reason = "Content-Length value must be an unsigned integer";
            $self->send_error(400, $reason);
            $self->reason($reason);
            my $reason = "Content-Length values are not the same";
            $self->send_error(400, $reason);
            $self->reason($reason);