Subject: | PoCoCl::HTTP::Request dies for non http URIs |
PoCoCl::HTTP::Requst dies when
$http_request->uri is not http uri
for example this URLs will make DoS
file://test/file.txt
javascript:alert('test')
mailto:john@smith.com
Attached patch will fix this problem. Also test case for this problem
attached.
Subject: | 09_bad_scheme.t |
#! /usr/bin/perl
use strict;
use warnings;
use Test::More tests => 2;
use POE qw(Component::Client::HTTP);
use HTTP::Request::Common qw(GET);
POE::Component::Client::HTTP->spawn( Alias => 'ua' );
POE::Session->create
(
inline_states =>
{
_start => sub {
$_[KERNEL]->post(ua => request => good_response => GET 'http://poe.perl.org/');
$_[KERNEL]->post(ua => request => bad_response => GET 'file://test/file.txt');
},
good_response => sub {
$_[HEAP]->{good_response} = $_[ARG1]->[0]->code == 200;
},
bad_response => sub {
$_[HEAP]->{bad_response} = $_[ARG1]->[0]->code == 400;
},
_stop => sub {
ok($_[HEAP]->{good_response}, 'got correct response for good scheme');
ok($_[HEAP]->{bad_response}, 'got correct response for bad scheme');
}
}
);
POE::Kernel->run;
Subject: | patch.diff |
Index: lib/POE/Component/Client/HTTP.pm
===================================================================
--- lib/POE/Component/Client/HTTP.pm (revision 237)
+++ lib/POE/Component/Client/HTTP.pm (working copy)
@@ -44,6 +44,11 @@
chunked => 'POE::Filter::HTTPChunk',
);
+my %supported_schemes = (
+ http => 1,
+ https => 1
+);
+
# }}} INIT
#------------------------------------------------------------------------------
@@ -152,6 +157,21 @@
$proxy_override
) = @_[KERNEL, HEAP, SENDER, ARG0, ARG1, ARG2, ARG3, ARG4];
+ unless ($supported_schemes{$http_request->uri->scheme}) {
+ my $rsp = HTTP::Response->new(
+ 400 => 'Bad Request', [],
+ "<html>\n"
+ . "<HEAD><TITLE>Error: Bad Request</TITLE></HEAD>\n"
+ . "<BODY>\n"
+ . "<H1>Error: Bad Request</H1>\n"
+ . "Unsupported URI scheme\n"
+ . "</BODY>\n"
+ . "</HTML>\n"
+ );
+ $kernel->post($sender, $response_event, [$http_request, $tag], [$rsp]);
+ return;
+ }
+
if (defined $proxy_override) {
POE::Component::Client::HTTP::RequestFactory->parse_proxy($proxy_override);
}