From 687108b34926c538749cb496a1922cd64ecc2d98 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Wed, 18 Nov 2026 19:46:09 -0700 Subject: [PATCH] INBUXA_HTTP_USE_FORWARDED: read the forwarding header without a store setting A deployment that only ever reaches the server through its own proxies (Kubernetes, behind an ingress, with the webmail) needs the server to count clients by the address those proxies pass on: otherwise the limits and bans for failed sign-ins and anonymous requests charge everything to the proxy, and a hundred wrong passwords a day between all users ban it. true or false overrides the store's "Use X-Forwarded-For"; trusted proxies still apply. --- crates/common/src/config/network.rs | 50 ++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/crates/common/src/config/network.rs b/crates/common/src/config/network.rs index 232ebcb4..1bcc9af3 100644 --- a/crates/common/src/config/network.rs +++ b/crates/common/src/config/network.rs @@ -545,6 +545,27 @@ impl Http { Err(_) => ForwardedHeader::XForwardedFor, }; + // inbuxa: whether to read the forwarding header at all. The store's + // setting, unless INBUXA_HTTP_USE_FORWARDED says otherwise: a + // deployment that only ever reaches the server through its own + // proxies (Kubernetes, behind an ingress) sets it, so the limits and + // bans for failed sign-ins count each client, not the proxy. + let use_forwarded = match types::branding::env_var("HTTP_USE_FORWARDED") { + Ok(value) => match parse_env_bool(&value) { + Some(value) => value, + None => { + bp.build_warning( + ObjectType::Http.singleton(), + format!( + "INBUXA_HTTP_USE_FORWARDED is {value:?}; expected true or false. The setting in the store applies." + ), + ); + http.use_x_forwarded + } + }, + Err(_) => http.use_x_forwarded, + }; + if use_permissive_cors { http_headers.push(( hyper::header::ACCESS_CONTROL_ALLOW_ORIGIN, @@ -602,7 +623,7 @@ impl Http { }, response_headers: http_headers, cors_origins, - use_forwarded: http.use_x_forwarded, + use_forwarded, trusted_proxies, forwarded_header, redirect_root: http.redirect_root, @@ -621,6 +642,15 @@ pub enum ForwardedHeader { Forwarded, } +// inbuxa: true/1/yes/on or false/0/no/off, any case; None for anything else. +fn parse_env_bool(value: &str) -> Option { + match value.trim().to_ascii_lowercase().as_str() { + "true" | "1" | "yes" | "on" => Some(true), + "false" | "0" | "no" | "off" => Some(false), + _ => None, + } +} + // inbuxa: loopback and the private ranges, where a reverse proxy on the same // host, container network or LAN connects from. fn default_trusted_proxies() -> Vec { @@ -727,3 +757,21 @@ impl Default for ClusterRoles { } } } + +#[cfg(test)] +mod tests { + use super::parse_env_bool; + + #[test] + fn env_bool() { + for yes in ["true", "TRUE", " 1 ", "yes", "On"] { + assert_eq!(parse_env_bool(yes), Some(true), "{yes}"); + } + for no in ["false", "0", "no", "OFF"] { + assert_eq!(parse_env_bool(no), Some(false), "{no}"); + } + for neither in ["", "2", "enabled", "y"] { + assert_eq!(parse_env_bool(neither), None, "{neither:?}"); + } + } +} -- 2.54.0