forked from hidek/Catalyst-Plugin-HTML-Scrubber
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from bigpresh/bigpresh/scrub_deserialised_body_…
…data_params Scrub body_data / data params too (e.g. POSTed JSON)
- Loading branch information
Showing
8 changed files
with
281 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use strict; | ||
use Test::More tests => 1; | ||
|
||
BEGIN { use_ok 'Catalyst::Plugin::HTML::Scrubber' } | ||
BEGIN { use Catalyst; use_ok 'Catalyst::Plugin::HTML::Scrubber' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use FindBin qw($Bin); | ||
use lib "$Bin/lib"; | ||
|
||
use Test::More; | ||
|
||
|
||
eval 'use Catalyst::Controller::REST'; | ||
plan skip_all => 'Catalyst::Controller::REST not available, skip REST tests' if $@; | ||
|
||
use Catalyst::Test 'MyApp05'; | ||
use HTTP::Request::Common; | ||
use HTTP::Status; | ||
|
||
{ | ||
# Test that data in a JSON body POSTed gets scrubbed too | ||
my $json_body = <<JSON; | ||
{ | ||
"foo": "Top-level <img src=foo.jpg title=fun>", | ||
"baz":{ | ||
"one":"Second-level <img src=test.jpg>" | ||
}, | ||
"arr": [ | ||
"one test <img src=arrtest1.jpg>", | ||
"two <script>window.alert('XSS!');</script>" | ||
], | ||
"some_html": "Leave <b>this</b> alone: <img src=allowed.gif>" | ||
} | ||
JSON | ||
my $req = POST('/foo', | ||
Content_Type => 'application/json', Content => $json_body | ||
); | ||
my ($res, $c) = ctx_request($req); | ||
is($res->code, RC_OK, 'response ok'); | ||
is( | ||
$c->req->data->{foo}, | ||
'Top-level ', # note trailing space where img was removed | ||
'Top level body param scrubbed', | ||
); | ||
is( | ||
$c->req->data->{baz}{one}, | ||
'Second-level ', | ||
'Second level body param scrubbed', | ||
); | ||
is( | ||
$c->req->data->{arr}[0], | ||
'one test ', | ||
'Second level array contents scrubbbed', | ||
); | ||
is( | ||
$c->req->data->{some_html}, | ||
'Leave <b>this</b> alone: <img src=allowed.gif>', | ||
'Body data param matching ignore_params left alone', | ||
); | ||
} | ||
|
||
done_testing(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.