Software /
code /
prosody
Diff
plugins/mod_http.lua @ 13834:61df1404dd7a 13.0
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 09 Apr 2025 15:54:54 +0200 (6 weeks ago) |
parent | 13249:5884d58707fa |
child | 13835:a4b58ea5bf7b |
line wrap: on
line diff
--- 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)