Skip to content

SEC: Rate Limiting Bypass with X-Forwarded-For Header Spoofing #181

Closed

Description

@vybe

Pentest Finding 3.2.4 — Medium (CVSS 5.1)

CVSS Vector: CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N

Location: POST /api/public/chat/{TOKEN} — routers/public.py lines 55–61

Impact

The IP rate limiter trusts the client-supplied X-Forwarded-For header without proxy validation. An attacker can bypass all rate limits by rotating the spoofed header on each request, enabling unlimited public chat flooding, brute-force, and unrestricted AI API cost consumption.

Root Cause

def _get_client_ip(request: Request) -> str:
    forwarded_for = request.headers.get("X-Forwarded-For")
    if forwarded_for:
        return forwarded_for.split(",")[0].strip()  # fully attacker-controlled
    return request.client.host

Steps to Reproduce

# All 35 requests succeed — rate limiter sees 35 distinct IPs
for i in $(seq 1 35); do
  curl -s -X POST "/api/public/chat/{token}" \
    -H "X-Forwarded-For: 10.0.0.$i" \
    -d '{"message":"test","async_mode":true}' -o /dev/null -w "%{http_code} "
done
# Output: 200 200 200 ... (35 times)

Remediation

  • Only trust X-Forwarded-For from known reverse proxies (trusted_hosts=["<nginx_ip>"])
  • Alternatively, always use request.client.host (real TCP connection IP) for rate limiting
  • Add a secondary rate limit based on the public link token itself (not just IP)

References

Source: UnderDefense Web Pentest Report, March 2026

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpentestpriority-p1securityseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions