Skip to content

Commit

Permalink
Send back HTTP code 422 when argument fails "allow"
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 18, 2024
1 parent 6728104 commit bb7dd23
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for CGI-Info

0.85
Send back HTTP code 422 when argument fails "allow"

0.84 Fri Oct 18 08:21:05 EDT 2024
Intercept SQL Injection
entry=-4346" OR 1749\=1749 AND "dgiO"\="dgiO;page=people
Expand Down
2 changes: 2 additions & 0 deletions lib/CGI/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ sub params {
if($self->{logger}) {
$self->{logger}->info("discard $key");
}
$self->status(422);
next;
}

Expand All @@ -749,6 +750,7 @@ sub params {
if($self->{logger}) {
$self->{logger}->info("block $key = $value");
}
$self->status(422);
next;
}
}
Expand Down
24 changes: 23 additions & 1 deletion t/params.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::Most tests => 181;
use Test::Most tests => 185;
use Test::NoWarnings;
use File::Spec;
use lib 't/lib';
Expand Down Expand Up @@ -489,4 +489,26 @@ EOF
};

ok($@ =~ /Reset is a class method/);

$ENV{'GATEWAY_INTERFACE'} = 'CGI/1.1';
$ENV{'REQUEST_METHOD'} = 'GET';
$ENV{'QUERY_STRING'} = 'country=/etc/passwd&page=by_location';
delete $ENV{'CONTENT_TYPE'};
delete $ENV{'CONTENT_LENGTH'};
$i = new_ok('CGI::Info');

my $allow = {
'entry' => undef,
'country' => qr/^[A-Z\s]+$/i, # Must start with a letter
'county' => qr/^[A-Z\s]+$/i,
'string' => undef,
'page' => 'by_location',
'lang' => qr/^[A-Z][A-Z]/i,
};

my %params = %{$i->params({ allow => $allow })};

cmp_ok($params{'page'}, 'eq', 'by_location', 'allow lets through legal parameters');
is($params{'country'}, undef, 'allow blocks illegal parameters');
cmp_ok($i->status(), '==', 422, 'HTTP Unprocessable Content');
}

0 comments on commit bb7dd23

Please sign in to comment.