Advisory

GHSA-9q47-3cm2-2rp8

Details, part 2 of 2. The advisory

Details

Root Causes

  1. A client-controlled HTTP header (X-Forwarded-For) is used directly in security decisions (rate-limit bucketing and audit attribution) without any trusted-proxy validation (CWE-807).
  2. The leftmost XFF token is selected, which is always the value supplied by the original client; this is spoofable both in direct-exposure and behind-a-proxy deployments (CWE-348).
  3. No ProxyFix / trusted-proxy-hop configuration exists, and the server terminates client connections directly, so there is no basis for trusting forwarded headers at all.
  4. Inconsistent handling across the codebase (loopback checks distrust these headers while rate-limit/logging trust them) indicates the trust is accidental rather than designed.

Suggested Fix

  1. By default, use request.remote_addr (the real TCP peer) for rate limiting and logging; do not trust X-Forwarded-For unless a proxy is explicitly configured.
  2. Add an explicit, operator-configured trusted-proxy count (default 0 = trust none). When set, apply Werkzeug's ProxyFix(app.wsgi_app, x_for=N) and read the correct hop (the value inserted by the trusted proxy — typically the Nth-from-right token — not the leftmost client-supplied token).
  3. Derive the trusted client IP once in a single helper and use it consistently for rate limiting, logging, and the loopback checks, removing the duplicated inline expressions.
  4. Consider defense-in-depth: cap the number of distinct rate-limit buckets and/or additionally rate-limit on remote_addr so a spoofed header cannot create unbounded buckets.

Invariant to restore: security decisions and audit attribution must be based on a connection-level
or trusted-proxy-validated address, never on a raw client-supplied header.

Sources & licences