Summary
A logic flaw in the Caddy Defender middleware causes IP-based blocking decisions to rely on the immediate peer address rather than the real client IP when Caddy is deployed behind trusted proxies.
In proxy, CDN, or load-balancer deployments that depend on Caddy's trusted proxy resolution, clients from blocked IP ranges can bypass Defender as long as the proxy's own IP is allowed.
Affected context
This vulnerability arises in Caddy deployments that:
- Use the Caddy Defender plugin for IP-based blocking or request manipulation
- Place Caddy behind trusted proxies, CDNs, or load balancers
- Rely on Caddy's
trusted_proxieshandling to resolve the original client IP
In these environments, Defender evaluated requests using RemoteAddr (the proxy's IP) instead of Caddy's resolved client_ip, allowing clients from blocked IP ranges to appear allowed when connecting through non-blocked intermediaries.
Exploit preconditions
- Attack surface: HTTP(S) endpoints protected by Caddy Defender, reachable via a trusted proxy, CDN, or load balancer
- Required access: Ability to send requests through an intermediary whose IP is not blocked by Defender
- Trigger point: Evaluation of IP-based rules in Caddy Defender that use
RemoteAddrinstead of the resolved client IP - Why exploitation is possible: The plugin trusts the immediate peer address as the client identity, ignoring Caddy's
client_ipresolution logic in proxied deployments, which maps to broken trust and authorization decisions.
Why this happens
The core issue is an authorization decision based on the wrong identity attribute. Defender relied on r.RemoteAddr, which represents the direct TCP peer, even in deployments where Caddy already resolved the actual client IP using its trusted_proxies configuration.
This misalignment between trust resolution and policy enforcement means the access control logic did not operate on the true client identity, corresponding to CWE-284: Improper Access Control and CWE-348: Use of Incorrect Validation of Client-Side Data, where security checks depend on an attribute that does not faithfully represent the entity being controlled.
Potential impact
- Clients from blocked IP ranges may bypass IP-based blocking when routed through allowed proxies
- Attackers can reach endpoints that administrators intended to shield via Defender rules
- Increased exposure of administrative, diagnostic, or rate-limited paths
- Potential abuse of IP-based throttling, geo-blocking, or ban lists
General mitigation guidance
Effective mitigation focuses on aligning identity resolution with access control decisions and treating network topology explicitly:
- Ensure IP-based authorization logic consistently uses the canonical, server-resolved client IP attribute rather than raw peer addresses
- Design middleware and policies to honor existing trusted-proxy and client IP resolution mechanisms provided by the web server or framework
- Favor edge-layer enforcement (firewalls, CDNs, load balancers) for coarse IP blocking, using application-layer controls as a secondary defense
- Keep trust boundaries minimal and explicit, avoiding assumptions that the immediate peer always represents the original client
- Regularly review IP-based rules and security plugins for awareness of proxy headers and trust policies
How teams detect issues like this
Detection typically involves a mix of configuration review and runtime validation:
- Inspect middleware and access control code for use of direct peer address fields (e.g.,
RemoteAddr) instead of canonical client IP abstractions - Review Caddy and plugin configurations to confirm that trusted proxy resolution and blocking rules rely on the same client IP source
- Use logging or security analytics to compare recorded client IPs with enforcement decisions, looking for discrepancies between blocked lists and observed traffic
- Apply static analysis or automated configuration checks to flag authorization logic that bypasses established trust resolution mechanisms
- Incorporate regression tests that simulate proxied requests from blocked IP ranges to validate that IP-based policies behave as expected

