Skip Menu |

This queue is for tickets about the Net-Async-HTTP CPAN distribution.

Report information
The Basics
Id: 101498
Status: resolved
Priority: 0/
Queue: Net-Async-HTTP

People
Owner: Nobody in particular
Requestors: frioux [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.39



Subject: Add require_SSL => 1 option
Date: Mon, 12 Jan 2015 10:06:25 -0600
To: bug-Net-Async-HTTP [...] rt.cpan.org
From: fREW Schmidt <frioux [...] gmail.com>
Basically, a way to force the client to only connect via SSL and throw an exception if a plaintext request is attempted. -- fREW Schmidt https://blog.afoolishmanifesto.com
Download (untitled)
application/pgp-signature 819b

Message body not shown because it is not plain text.

See attached. -- Paul Evans
Subject: rt101498.patch
=== modified file 'lib/Net/Async/HTTP.pm' --- lib/Net/Async/HTTP.pm 2015-07-13 12:34:29 +0000 +++ lib/Net/Async/HTTP.pm 2015-07-13 13:31:22 +0000 @@ -269,6 +269,12 @@ passed on requests to perform SSL requests. This simplifies configuration of common SSL parameters. +=head2 require_SSL => BOOL + +Optional. If true, then any attempt to make a request that does not use SSL +(either by calling C<request>, or as a result of a redirection) will +immediately fail. + =cut sub configure @@ -279,7 +285,7 @@ foreach (qw( user_agent max_redirects max_in_flight max_connections_per_host timeout stall_timeout proxy_host proxy_port cookie_jar pipeline local_host local_port local_addrs local_addr fail_on_error - read_len write_len decode_content )) + read_len write_len decode_content require_SSL )) { $self->{$_} = delete $params{$_} if exists $params{$_}; } @@ -634,6 +640,11 @@ $self->prepare_request( $request ); + if( $self->{require_SSL} and not $args{SSL} ) { + return Future->fail( "Non-SSL request is not allowed with 'require_SSL' set", + http => undef, $request ); + } + return $self->get_connection( host => $args{proxy_host} || $self->{proxy_host} || $host, port => $args{proxy_port} || $self->{proxy_port} || $port, === modified file 't/21local-connect-ssl.t' --- t/21local-connect-ssl.t 2014-10-14 10:17:32 +0000 +++ t/21local-connect-ssl.t 2015-07-13 13:31:22 +0000 @@ -90,4 +90,14 @@ is( $response->content_type, "text/plain", '$response->content_type' ); is( $response->content, "OK", '$response->content' ); +# require_SSL +{ + $http->configure( require_SSL => 1 ); + + my $f = $http->GET( "http://127.0.0.1:$port/" ); + + ok( $f->failure, '->GET on http with require_SSL fails' ); + like( scalar $f->failure, qr/require_SSL/, 'require_SSL failure' ); +} + done_testing; === modified file 't/24local-connect-redir-ssl.t' --- t/24local-connect-redir-ssl.t 2013-09-10 00:28:12 +0000 +++ t/24local-connect-redir-ssl.t 2015-07-13 13:31:22 +0000 @@ -25,6 +25,8 @@ $loop->add( $http ); +my $redir_url; + my $port; $loop->SSL_listen( host => "127.0.0.1", @@ -51,7 +53,7 @@ my $response = ( $header =~ m{^GET /redir} ) ? "HTTP/1.1 301 Moved Permanently$CRLF" . "Content-Length: 0$CRLF" . - "Location: https://127.0.0.1:$port/moved$CRLF" . + "Location: $redir_url$CRLF" . "Connection: Keep-Alive$CRLF" . "$CRLF" : "HTTP/1.1 200 OK$CRLF" . @@ -77,6 +79,8 @@ wait_for { defined $port }; +$redir_url = "https://127.0.0.1:$port/moved"; + my $response; $http->do_request( @@ -96,4 +100,18 @@ is( $response->content_type, "text/plain", '$response->content_type' ); is( $response->content, "OK", '$response->content' ); +# require_SSL +{ + $http->configure( require_SSL => 1 ); + + $redir_url = "http://127.0.0.1:$port/moved_to_plaintext"; + + my $f = $http->GET( "https://127.0.0.1:$port/redir" ); + + wait_for { $f->is_ready }; + + ok( $f->failure, '->GET on http with require_SSL fails' ); + like( scalar $f->failure, qr/require_SSL/, 'require_SSL failure' ); +} + done_testing;
Was released in 0.39 -- Paul Evans