Mercurial > prosody-hg
comparison plugins/mod_http.lua @ 13125:90394be5e6a5
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.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 03 Jun 2023 17:10:12 +0200 |
| parents | 9c4dc1e6d2c9 |
| children | d043834f15d2 |
comparison
equal
deleted
inserted
replaced
| 13124:f15e23840780 | 13125:90394be5e6a5 |
|---|---|
| 295 | 295 |
| 296 module.add_host(module); -- set up handling on global context too | 296 module.add_host(module); -- set up handling on global context too |
| 297 | 297 |
| 298 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; | 298 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; |
| 299 | 299 |
| 300 --- deal with [ipv6]:port / ip:port format | |
| 301 local function normal_ip(ip) | |
| 302 return ip:match("^%[([%x:]*)%]") or ip:match("^([%d.]+)") or ip; | |
| 303 end | |
| 304 | |
| 300 local function is_trusted_proxy(ip) | 305 local function is_trusted_proxy(ip) |
| 306 ip = normal_ip(ip); | |
| 301 if trusted_proxies[ip] then | 307 if trusted_proxies[ip] then |
| 302 return true; | 308 return true; |
| 303 end | 309 end |
| 304 local parsed_ip = new_ip(ip) | 310 local parsed_ip = new_ip(ip) |
| 305 for trusted_proxy in trusted_proxies do | 311 for trusted_proxy in trusted_proxies do |
