From fc4e2751dc817e24e70d22e4114e50b459eafbd2 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 1 Oct 2025 01:03:45 +0300 Subject: [PATCH] Fix broken redirect when there is no way to get FQDN *Note: "$host = &get_socket_name(SOCK, $ipv6fhs{$s});" won't return FQDN if it can't be resolved (or if it isn't in /etc/hosts), breaking some redirects, most likely proxied ones that aren't using HTTPS in its config. --- miniserv.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/miniserv.pl b/miniserv.pl index f3e45ae1d..01a67253d 100755 --- a/miniserv.pl +++ b/miniserv.pl @@ -1382,7 +1382,12 @@ print DEBUG "handle_request reqline=$reqline\n"; alarm(0); if (!$use_ssl && $config{'ssl'} && $config{'ssl_enforce'}) { # This is an http request when https must be enforced - local $urlhost = $config{'musthost'} || $host; + local $hostname = $host; + if ($hostname !~ /\./) { + my $system_hostname = &get_system_hostname(); + $hostname = $system_hostname if ($system_hostname =~ /\./); + } + local $urlhost = $config{'musthost'} || $hostname; $urlhost = "[".$urlhost."]" if (&check_ip6address($urlhost)); local $wantport = $port; if ($wantport == 80 && @@ -1400,7 +1405,7 @@ if (!$use_ssl && $config{'ssl'} && $config{'ssl_enforce'}) { &write_data("Location: $url\r\n"); &write_keep_alive(0); &write_data("\r\n"); - &log_error("Redirecting HTTP request to HTTPS for $acptip"); + &log_error("Redirecting HTTP request to HTTPS using $urlhost host"); &log_request($loghost, $authuser, $reqline, 302, 0); return 0; }