Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions tests/modsecurity-request-body.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Test::Nginx;
select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/http auth_request/);
my $t = Test::Nginx->new()->has(qw/http proxy auth_request/);

$t->write_file_expand('nginx.conf', <<'EOF');

Expand All @@ -49,7 +49,7 @@ http {
SecRequestBodyAccess On
SecRule REQUEST_BODY "@rx BAD BODY" "id:11,phase:request,deny,log,status:403"
';
proxy_pass http://127.0.0.1:8081;
proxy_pass http://127.0.0.1:%%PORT_8081%%;
}

location /nobodyaccess {
Expand All @@ -59,7 +59,7 @@ http {
SecRule REQUEST_BODY "@rx BAD BODY" "id:21,phase:request,deny,log,status:403"
SecRule ARGS_POST|ARGS_POST_NAMES "@rx BAD ARG" "id:22,phase:request,deny,log,status:403"
';
proxy_pass http://127.0.0.1:8081;
proxy_pass http://127.0.0.1:%%PORT_8081%%;
}

location /bodylimitreject {
Expand All @@ -70,7 +70,12 @@ http {
SecRequestBodyLimitAction Reject
SecRule REQUEST_BODY "@rx BAD BODY" "id:31,phase:request,deny,log,status:403"
';
proxy_pass http://127.0.0.1:8081;
proxy_pass http://127.0.0.1:%%PORT_8081%%;
}

location /bodylimitrejectserver {
modsecurity off;
proxy_pass http://127.0.0.1:%%PORT_8082%%;
}

location /bodylimitprocesspartial {
Expand All @@ -81,7 +86,7 @@ http {
SecRequestBodyLimitAction ProcessPartial
SecRule REQUEST_BODY "@rx BAD BODY" "id:41,phase:request,deny,log,status:403"
';
proxy_pass http://127.0.0.1:8081;
proxy_pass http://127.0.0.1:%%PORT_8081%%;
}

location = /auth {
Expand All @@ -95,7 +100,22 @@ http {
SecRequestBodyAccess On
';
auth_request /auth;
proxy_pass http://127.0.0.1:8081;
proxy_pass http://127.0.0.1:%%PORT_8081%%;
}
}

server {
listen 127.0.0.1:%%PORT_8082%%;
modsecurity on;
modsecurity_rules '
SecRuleEngine On
SecRequestBodyAccess On
SecRequestBodyLimit 128
SecRequestBodyLimitAction Reject
SecRule REQUEST_BODY "@rx BAD BODY" "id:31,phase:request,deny,log,status:403"
';
location / {
proxy_pass http://127.0.0.1:%%PORT_8081%%;
}
}
}
Expand All @@ -104,7 +124,7 @@ EOF
$t->run_daemon(\&http_daemon);
$t->run()->waitforsocket('127.0.0.1:' . port(8081));

$t->plan(36);
$t->plan(40);

###############################################################################

Expand Down Expand Up @@ -146,6 +166,14 @@ like(
'POST with auth_request (request size < client_header_buffer_size), no preread'
);

TODO: {
local $TODO = 'not yet';

foreach my $method (('GET', 'POST', 'PUT', 'DELETE')) {
like(http_req_body($method, '/bodylimitrejectserver', 'BODY' x 33), qr/403 Forbidden/, "$method request body limit reject, block (inherited SecRequestBodyLimit)");
}
}

###############################################################################

sub http_daemon {
Expand Down