@ -48,11 +48,11 @@ Subject: [PATCH] Change verify_SSL default to 1, add ENV var to enable
Backported from HTTP::Tiny 0.083
---
lib/HTTP/Tiny.pm | 86 ++++ ++++++++++++++----------
lib/HTTP/Tiny.pm | 72 ++++++++++++++----------
t/180_verify_SSL.t | 109 ++++++++++++++++++++++++++++++++++++
t/210_live_ssl.t | 136 ++++++++++++++++++++++++++++++---------------
t/snake-oil.crt | 33 +++++++++++
4 files changed, 291 insertions(+), 73 deletions(-)
4 files changed, 277 insertions(+), 73 deletions(-)
create mode 100644 t/180_verify_SSL.t
create mode 100644 t/snake-oil.crt
@ -68,12 +68,12 @@ index 2ece5ca..58be640 100644
-#pod certificate of an C<https> — connection (default is false)
+#pod * C<verify_SSL> — A boolean that indicates whether to validate the TLS/SSL
+#pod certificate of an C<https> ? connection (default is true). Changed from false
+#pod to true for CVE-2023-31486 .
+#pod to true for RHBZ#2228412 .
#pod * C<SSL_options> — A hashref of C<SSL_*> — options to pass through to
#pod L<IO::Socket::SSL>
+#pod * C<$ENV{PERL_HTTP_TINY_SSL_INSECURE_BY_DEFAULT}> - Changes the default
+#pod certificate verification behavior to not check server identity if set to 1.
+#pod Only effective if C<verify_SSL> is not set. Added for CVE-2023-31486 .
+#pod Only effective if C<verify_SSL> is not set. Added for RHBZ#2228412 .
#pod
#pod Passing an explicit C<undef> for C<proxy>, C<http_proxy> or C<https_proxy> will
#pod prevent getting the corresponding proxies from the environment.
@ -104,13 +104,13 @@ index 2ece5ca..58be640 100644
+ my ($self) = @_;
+ # Check if insecure default certificate verification behaviour has been
+ # changed by the user by setting PERL_HTTP_TINY_SSL_INSECURE_BY_DEFAULT=1
+ return (($ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} || '') eq '1') ? 0 : 1;
+ return (($ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} || '') eq '1') ? 0 : 1;
+}
+
sub _set_proxies {
my ($self) = @_;
@@ -10 34,7 +1051 ,7 @@ sub new {
@@ -10 41,7 +1058 ,7 @@ sub new {
timeout => 60,
max_line_size => 16384,
max_header_lines => 64,
@ -119,7 +119,7 @@ index 2ece5ca..58be640 100644
SSL_options => {},
%args
}, $class;
@@ -20 05,11 +2022 ,11 @@ proxy
@@ -20 12,11 +2029 ,11 @@ proxy
timeout
verify_SSL
@ -133,7 +133,7 @@ index 2ece5ca..58be640 100644
encryption fails. You can also use C<HTTP::Tiny::can_ssl()> utility function
that returns boolean to see if the required modules are installed.
@@ -20 17,7 +2034 ,7 @@ An C<https> connection may be made via a
@@ -20 24,7 +2041 ,7 @@ An C<https> connection may be made via a
command (i.e. RFC 2817). You may not proxy C<https> via a proxy that itself
requires C<https> to communicate.
@ -142,7 +142,7 @@ index 2ece5ca..58be640 100644
=over 4
@@ -203 1,24 +2048 ,17 @@ Verification of server identity
@@ -203 8,24 +2055 ,17 @@ Verification of server identity
=back
@ -165,7 +165,7 @@ index 2ece5ca..58be640 100644
-Assuming you trust the CA, this will protect against a L<man-in-the-middle
-attack|http://en.wikipedia.org/wiki/Man-in-the-middle_attack>. If you are
-concerned about security, you should enable this option.
+This was changed for CVE-2023-31486 due to security concerns. The previous default
+This was changed for RHBZ#2228412 due to security concerns. The previous default
+behavior can be enabled by setting C<$ENV{PERL_HTTP_TINY_SSL_INSECURE_BY_DEFAULT}>
+to 1.
+
@ -177,7 +177,7 @@ index 2ece5ca..58be640 100644
Certificate verification requires a file containing trusted CA certificates.
@@ -20 56,9 +2066 ,7 @@ If the environment variable C<SSL_CERT_F
@@ -20 63,9 +2073 ,7 @@ If the environment variable C<SSL_CERT_F
will try to find a CA certificate file in that location.
If the L<Mozilla::CA> module is installed, HTTP::Tiny will use the CA file
@ -188,7 +188,7 @@ index 2ece5ca..58be640 100644
If that module is not available, then HTTP::Tiny will search several
system-specific default locations for a CA certificate file:
@@ -20 77,13 +2085 ,33 @@ system-specific default locations for a
@@ -20 84,13 +2092 ,33 @@ system-specific default locations for a
/etc/ssl/ca-bundle.pem
@ -224,7 +224,7 @@ index 2ece5ca..58be640 100644
C<IO::Socket::SSL::start_SSL()>, overriding any options set by HTTP::Tiny. For
example, to provide your own trusted CA file:
@@ -2 093,7 +2121 ,7 @@ example, to provide your own trusted CA
@@ -2 100,7 +2128 ,7 @@ example, to provide your own trusted CA
The C<SSL_options> attribute could also be used for such things as providing a
client certificate for authentication to a server or controlling the choice of
@ -248,7 +248,7 @@ index 0000000..d6bc412
+
+use HTTP::Tiny;
+
+delete $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT};
+delete $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT};
+
+{
+ my $ht = HTTP::Tiny->new();
@ -294,54 +294,54 @@ index 0000000..d6bc412
+}
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = "1";
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = "1";
+ my $ht = HTTP::Tiny->new();
+ is($ht->verify_SSL, 0, "PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT=1 changes verify_SSL default to 0");
+ is($ht->verify_SSL, 0, "PERL_HTTP_TINY_ INSECURE_BY_DEFAULT=1 changes verify_SSL default to 0");
+}
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = "0";
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = "0";
+ my $ht = HTTP::Tiny->new();
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT=0 keeps verify_SSL default at 1");
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ INSECURE_BY_DEFAULT=0 keeps verify_SSL default at 1");
+}
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = "False";
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = "False";
+ my $ht = HTTP::Tiny->new();
+ is($ht->verify_SSL, 1, "Unsupported PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT=False keeps verify_SSL default at 1");
+ is($ht->verify_SSL, 1, "Unsupported PERL_HTTP_TINY_ INSECURE_BY_DEFAULT=False keeps verify_SSL default at 1");
+}
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = "1";
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = "1";
+ my $ht = HTTP::Tiny->new(verify_SSL=>1);
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT=1 does not override verify_SSL attribute set to 1");
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ INSECURE_BY_DEFAULT=1 does not override verify_SSL attribute set to 1");
+}
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = "1";
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = "1";
+ my $ht = HTTP::Tiny->new(
+ verify_SSL => 1,
+ verify_ssl => 1
+ );
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT=1, verify_SSL=>1 and verify_ssl=>1 sets 1");
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ INSECURE_BY_DEFAULT=1, verify_SSL=>1 and verify_ssl=>1 sets 1");
+}
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = "1";
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = "1";
+ my $ht = HTTP::Tiny->new(
+ verify_SSL => 1,
+ verify_ssl => 0
+ );
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT=1, verify_SSL=>1 and verify_ssl=>0 sets 1");
+ is($ht->verify_SSL, 1, "PERL_HTTP_TINY_ INSECURE_BY_DEFAULT=1, verify_SSL=>1 and verify_ssl=>0 sets 1");
+}
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = "1";
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = "1";
+ my $ht = HTTP::Tiny->new(
+ verify_SSL => 0,
+ verify_ssl => 0
+ );
+ is($ht->verify_SSL, 0, "PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT=1, verify_SSL=>0 and verify_ssl=>0 sets 0");
+ is($ht->verify_SSL, 0, "PERL_HTTP_TINY_ INSECURE_BY_DEFAULT=1, verify_SSL=>0 and verify_ssl=>0 sets 0");
+}
+
+
@ -356,7 +356,7 @@ index 6f80e51..7b84f93 100644
}
use HTTP::Tiny;
+delete $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT};
+delete $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT};
+
plan skip_all => 'Only run for $ENV{AUTOMATED_TESTING}'
unless $ENV{AUTOMATED_TESTING};
@ -428,7 +428,7 @@ index 6f80e51..7b84f93 100644
+});
+
+{
+ local $ENV{PERL_HTTP_TINY_ SSL_ INSECURE_BY_DEFAULT} = 1;
+ local $ENV{PERL_HTTP_TINY_ INSECURE_BY_DEFAULT} = 1;
+ test_ssl('https://wrong.host.badssl.com/' => {
+ host => 'wrong.host.badssl.com',
+ pass => { verify_SSL => 0 },