Fixes for referer checking and SSL under IPv6
authorJamie Cameron <jcameron@webmin.com>
Tue, 16 Nov 2010 21:47:58 +0000 (13:47 -0800)
committerJamie Cameron <jcameron@webmin.com>
Tue, 16 Nov 2010 21:47:58 +0000 (13:47 -0800)
miniserv.pl
web-lib-funcs.pl

index abf5c89..78c90cb 100755 (executable)
@@ -405,7 +405,7 @@ if ($config{'inetd'}) {
 
        # Initialize SSL for this connection
        if ($use_ssl) {
-               $ssl_con = &ssl_connection_for_ip(SOCK);
+               $ssl_con = &ssl_connection_for_ip(SOCK, 0);
                $ssl_con || exit;
                }
 
@@ -850,7 +850,8 @@ while(1) {
 
                                # Initialize SSL for this connection
                                if ($use_ssl) {
-                                       $ssl_con = &ssl_connection_for_ip(SOCK);
+                                       $ssl_con = &ssl_connection_for_ip(
+                                                       SOCK, $ipv6fhs{$s});
                                        $ssl_con || exit;
                                        }
 
@@ -4094,17 +4095,17 @@ Net::SSLeay::CTX_use_certificate_file(
 return $ssl_ctx;
 }
 
-# ssl_connection_for_ip(socket)
+# ssl_connection_for_ip(socket, ipv6-flag)
 # Returns a new SSL connection object for some socket, or undef if failed
 sub ssl_connection_for_ip
 {
-local ($sock) = @_;
+local ($sock, $ipv6) = @_;
 local $sn = getsockname($sock);
 if (!$sn) {
        print STDERR "Failed to get address for socket $sock\n";
        return undef;
        }
-local $myip = inet_ntoa((unpack_sockaddr_in($sn))[1]);
+local (undef, $myip, undef) = &get_address_ip($sn, $ipv6);
 local $ssl_ctx = $ssl_contexts{$myip} || $ssl_contexts{"*"};
 local $ssl_con = Net::SSLeay::new($ssl_ctx);
 if ($config{'ssl_cipher_list'}) {
index 33db76c..cb9f9f3 100755 (executable)
@@ -4292,11 +4292,14 @@ if ($module_name && !$main::no_acl_check &&
 # Check the Referer: header for nasty redirects
 my @referers = split(/\s+/, $gconfig{'referers'});
 my $referer_site;
-if ($ENV{'HTTP_REFERER'} =~/^(http|https|ftp):\/\/([^:\/]+:[^@\/]+@)?([^\/:@]+)/) {
+my $r = $ENV{'HTTP_REFERER'};
+if ($r =~ /^(http|https|ftp):\/\/([^:\/]+:[^@\/]+@)?\[([^\]]+)\]/ ||
+    $r =~ /^(http|https|ftp):\/\/([^:\/]+:[^@\/]+@)?([^\/:@]+)/) {
        $referer_site = $3;
        }
 my $http_host = $ENV{'HTTP_HOST'};
 $http_host =~ s/:\d+$//;
+$http_host =~ s/^\[(\S+)\]$/$1/;
 my $unsafe_index = $unsafe_index_cgi ||
                   &get_module_variable('$unsafe_index_cgi');
 if ($0 &&
@@ -4319,7 +4322,7 @@ if ($0 &&
        if ($referer_site) {
                # From a known host
                print &text('referer_warn',
-                    "<tt>".&html_escape($ENV{'HTTP_REFERER'})."</tt>", $url);
+                           "<tt>".&html_escape($r)."</tt>", $url);
                print "<p>\n";
                print &text('referer_fix1', &html_escape($http_host)),"<p>\n";
                print &text('referer_fix2', &html_escape($http_host)),"<p>\n";