Mercurial > prosody-hg
comparison 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 |
| parents | 5884d58707fa |
| children | a4b58ea5bf7b |
comparison
equal
deleted
inserted
replaced
| 13833:497efa2cbf2c | 13834:61df1404dd7a |
|---|---|
| 329 | 329 |
| 330 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; | 330 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; |
| 331 | 331 |
| 332 --- deal with [ipv6]:port / ip:port format | 332 --- deal with [ipv6]:port / ip:port format |
| 333 local function normal_ip(ip) | 333 local function normal_ip(ip) |
| 334 return ip:match("^%[([%x:]*)%]") or ip:match("^([%d.]+)") or ip; | 334 return ip:match("^%[([%x:]*)%]") or ip:match("^%d+%.%d+%.%d+%.%d+") or ip; |
| 335 end | 335 end |
| 336 | 336 |
| 337 local function is_trusted_proxy(ip) | 337 local function is_trusted_proxy(ip) |
| 338 ip = normal_ip(ip); | 338 ip = normal_ip(ip); |
| 339 if trusted_proxies[ip] then | 339 if trusted_proxies[ip] then |
