# HG changeset patch # User Kim Alvefur # Date 1744206894 -7200 # Node ID 61df1404dd7af9897b0bd531f4aee944b397375f # Parent 497efa2cbf2c29b6d0f5c12e848d6dde094ba72e mod_http: Fix IP address normalization (Thanks Boris) This fixes the problem that an un-bracketed IPv6 address will not match the first pattern (since it matches brackets) and instead the first decimal digits will match the pattern meant to strip port numbers from IPv4 addresses, e.g. 2001:db8::1 --> 2000 This pattern instead matches enough of a regular IPv4 address to make an IPv6 address fall back to the last case. diff -r 497efa2cbf2c -r 61df1404dd7a plugins/mod_http.lua --- a/plugins/mod_http.lua Wed Apr 09 15:06:48 2025 +0200 +++ b/plugins/mod_http.lua Wed Apr 09 15:54:54 2025 +0200 @@ -331,7 +331,7 @@ --- deal with [ipv6]:port / ip:port format local function normal_ip(ip) - return ip:match("^%[([%x:]*)%]") or ip:match("^([%d.]+)") or ip; + return ip:match("^%[([%x:]*)%]") or ip:match("^%d+%.%d+%.%d+%.%d+") or ip; end local function is_trusted_proxy(ip)