# HG changeset patch # User Kim Alvefur # Date 1685805012 -7200 # Node ID 90394be5e6a5d3470f8d54e17eb8c6a10732705d # Parent f15e23840780204db38b798010cf5d0f981eb637 mod_http: Handle bracketed IP address format from RFC 7239 There are hints that this format might be used in X-Forwarded-For as well, so best handle it everywhere. Strips both brackets and optional port number. diff -r f15e23840780 -r 90394be5e6a5 plugins/mod_http.lua --- a/plugins/mod_http.lua Sat Jun 03 16:15:52 2023 +0200 +++ b/plugins/mod_http.lua Sat Jun 03 17:10:12 2023 +0200 @@ -297,7 +297,13 @@ local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; +--- deal with [ipv6]:port / ip:port format +local function normal_ip(ip) + return ip:match("^%[([%x:]*)%]") or ip:match("^([%d.]+)") or ip; +end + local function is_trusted_proxy(ip) + ip = normal_ip(ip); if trusted_proxies[ip] then return true; end