fix(gateway): trim trusted proxy entries before matching

This commit is contained in:
Rain
2026-02-16 21:28:24 +08:00
committed by Peter Steinberger
parent e24e465c00
commit d3698f4eb6
2 changed files with 15 additions and 3 deletions

View File

@@ -210,12 +210,16 @@ export function isTrustedProxyAddress(ip: string | undefined, trustedProxies?: s
}
return trustedProxies.some((proxy) => {
const candidate = proxy.trim();
if (!candidate) {
return false;
}
// Handle CIDR notation
if (proxy.includes("/")) {
return ipMatchesCIDR(normalized, proxy);
if (candidate.includes("/")) {
return ipMatchesCIDR(normalized, candidate);
}
// Exact IP match
return normalizeIp(proxy) === normalized;
return normalizeIp(candidate) === normalized;
});
}