From 0d5a3da478dfb6c052ac90bf0de1535f3e923dad Mon Sep 17 00:00:00 2001 From: CPANSec Security Scanner Bot Date: Tue, 24 Nov 2026 14:31:02 +0000 Subject: [PATCH] Net::Server::Proto::SSL: bound the TLS handshake and drop failed clients With proto ssl the TLS handshake runs in post_accept, before the allow/deny rules are applied. accept_SSL was called without a timeout, so a client that connected and sent nothing held the server process indefinitely, whether or not the allow/deny rules would have rejected it. A handshake that failed, for example because the client sent plaintext, died out of post_accept, and nothing in the server loop caught it: a PreFork child exited and a Single server stopped. Pass a Timeout to accept_SSL, taken from the new SSL_handshake_timeout parameter (default 30 seconds, 0 disables it), so a client that does not complete the handshake in time is disconnected. Catch an error raised by the protocol's post_accept in Net::Server::post_accept and record it, and have run_client_connection log it, close the client and return without processing the request. A failed handshake now ends only that connection. Notes for deciding whether to apply this patch: - Adds an SSL_handshake_timeout parameter with a default of 30 seconds. Clients on slow links that need longer to complete the handshake are disconnected unless it is raised, or set to 0 to restore the old unlimited wait. - The handshake still runs before the allow/deny rules. A client those rules would reject can still hold a server process, but only until the handshake timeout. - Errors from any protocol's post_accept, not only proto ssl, now end the connection instead of the server process. - Not tested on a running server. It was checked by review and by applying it to Net-Server 2.018. - Applies on its own to Net-Server 2.018, and together with the other CPANSec patches for Net-Server 2.018 when they are applied in CVE-ID order. --- lib/Net/Server.pm | 10 +++++++++- lib/Net/Server/Proto/SSL.pm | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/Net/Server.pm b/lib/Net/Server.pm index 17353d3..c5b7ca9 100644 --- a/lib/Net/Server.pm +++ b/lib/Net/Server.pm @@ -84,6 +84,11 @@ sub run_client_connection { my $c = $self->{'server'}->{'client'}; $self->post_accept($c); # prepare client for processing + if (my $err = delete $self->{'server'}->{'client_setup_error'}) { # protocol setup (such as an SSL handshake) failed + $self->log(3, "Client setup failed: $err"); + eval { $c->close }; + return; + } $self->get_client_info($c); # determines information about peer and local $self->post_accept_hook($c); # user customizable hook @@ -513,7 +518,10 @@ sub post_accept { return; } - $client->post_accept() if $client->can("post_accept"); + if ($client->can("post_accept") && ! eval { $client->post_accept(); 1 }) { + ($prop->{'client_setup_error'} = $@ || "Unknown error") =~ s/\s+$//; + return; + } if (! $prop->{'no_client_stdout'}) { close STDIN; # duplicate some handles and flush them close STDOUT; diff --git a/lib/Net/Server/Proto/SSL.pm b/lib/Net/Server/Proto/SSL.pm index d15105a..6b115b3 100644 --- a/lib/Net/Server/Proto/SSL.pm +++ b/lib/Net/Server/Proto/SSL.pm @@ -45,6 +45,7 @@ my @ssl_args = qw( SSL_error_callback SSL_verify_callback SSL_version + SSL_handshake_timeout ); sub NS_proto { 'SSL' } @@ -213,7 +214,9 @@ sub _accept_ssl { my $client = shift; ${*$client}{'_accept_ssl'} = 1; my $sock = delete(${*$client}{'_parent_sock'}) || die "Could not get handshake from accept\n"; - $sock->accept_SSL($client) || die "Could not finalize SSL connection with client handle ($@)\n"; + my $timeout = $sock->SSL_handshake_timeout; + $timeout = 30 if ! defined $timeout; + $sock->accept_SSL($client, ($timeout ? (Timeout => $timeout) : ())) || die "Could not finalize SSL connection with client handle ($@)\n"; } sub read_until { # allow for an interface that can be tied to STDOUT @@ -324,6 +327,17 @@ L for information on setting this up. All arguments prefixed with SSL_ will be passed to the IO::Socket::SSL->configure method. +=over 4 + +=item SSL_handshake_timeout + +Number of seconds a client has to complete the SSL handshake after +the connection is accepted. Default is 30. A client that has not +completed the handshake in that time is disconnected, as is a client +whose handshake fails. Set to 0 to wait without a time limit. + +=back + =head1 BUGS Until version Net::Server version 2, Net::Server::Proto::SSL used the -- 2.53.0