Skip to content

Commit ecb44cf

Browse files
committed
Fix a bug in Mojo::Message::Request where message size limits were not always correctly applied
1 parent 1c6b7f5 commit ecb44cf

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

Changes

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
9.39 2024-08-18
2+
9.39 2024-08-28
3+
- Fixed a bug in Mojo::Message::Request where message size limits were not always correctly applied.
4+
(Alexander Kuehne)
35

46
9.38 2024-08-17
57
- Added support for new core booleans in Perl 5.36+ to Mojo::JSON. (haarg)

lib/Mojo/Message/Request.pm

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ sub parse {
116116
if (($self->{state} // '') ne 'cgi') { $self->SUPER::parse($chunk) }
117117

118118
# Parse CGI content
119-
else { $self->content($self->content->parse_body($chunk))->SUPER::parse('') }
119+
else {
120+
$self->{raw_size} += length $chunk unless defined $env;
121+
$self->content($self->content->parse_body($chunk))->SUPER::parse('');
122+
}
120123

121124
# Check if we can fix things that require all headers
122125
return $self unless $self->is_finished;

lib/Mojolicious.pm

+2
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ Alex Salimon
871871
872872
Alexander Karelas
873873
874+
Alexander Kuehne
875+
874876
Alexey Likhatskiy
875877
876878
Anatoly Sharifulin

t/mojo/request_cgi.t

+31
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,37 @@ subtest 'Parse Apache CGI environment variables and body' => sub {
9393
'right absolute URL';
9494
};
9595

96+
subtest 'Parse CGI environment with maximum message size' => sub {
97+
my $req = Mojo::Message::Request->new;
98+
$req->max_message_size(10);
99+
$req->parse({
100+
CONTENT_LENGTH => 26,
101+
CONTENT_TYPE => 'application/x-www-form-urlencoded',
102+
HTTP_DNT => 1,
103+
PATH_INFO => '/test/index.cgi/foo/bar',
104+
QUERY_STRING => 'lalala=23&bar=baz',
105+
REQUEST_METHOD => 'POST',
106+
SCRIPT_NAME => '/test/index.cgi',
107+
HTTP_HOST => 'localhost:8080',
108+
SERVER_PROTOCOL => 'HTTP/1.0'
109+
});
110+
$req->parse('abcdefghijklm');
111+
$req->parse('nopqrstuvwxyz');
112+
ok $req->is_finished, 'request is finished';
113+
ok $req->is_limit_exceeded, 'limit exceeded';
114+
is $req->method, 'POST', 'right method';
115+
is $req->url->path, 'foo/bar', 'right path';
116+
is $req->url->base->path, '/test/index.cgi/', 'right base path';
117+
is $req->url->base->host, 'localhost', 'right base host';
118+
is $req->url->base->port, 8080, 'right base port';
119+
is $req->url->query, 'lalala=23&bar=baz', 'right query';
120+
is $req->version, '1.0', 'right version';
121+
is $req->headers->dnt, 1, 'right "DNT" value';
122+
is $req->body, 'abcdefghijklm', 'right content';
123+
is $req->url->to_abs->to_string, 'http://localhost:8080/test/index.cgi/foo/bar?lalala=23&bar=baz',
124+
'right absolute URL';
125+
};
126+
96127
subtest 'Parse Apache CGI environment variables and body (file storage)' => sub {
97128
local $ENV{MOJO_MAX_MEMORY_SIZE} = 10;
98129
my $req = Mojo::Message::Request->new;

0 commit comments

Comments
 (0)