TryBugHunt

The Spoofed Header Rate Limiter Bypass

hardpython

Leftmost X-Forwarded-For parsing and lax peer verification allow distributed quota evasion

0:00
Step 1: Test Traffic & Expose Flaw
"""
Proxy Middleware - Client IP Resolver
Resolves client remote IP from incoming HTTP headers and network peer address.
"""

class ProxyMiddleware:
    def __init__(self, trusted_hops=1):
        self.trusted_hops = trusted_hops

    def resolve_client_ip(self, headers, peer_ip):
        # AI Attempt: Extract client IP from X-Forwarded-For
        # BUG: Blindly parses leftmost entry! An attacker who sends
        # 'X-Forwarded-For: 1.2.3.4, 198.51.100.77' can spoof any arbitrary IP!
        xff = headers.get("X-Forwarded-For")
        if xff:
            parts = [p.strip() for p in xff.split(",") if p.strip()]
            if parts:
                return parts[0]
        return peer_ip
Step 1: Test Traffic & Expose Flaw

Simulate an attacker injecting spoofed IP addresses into the X-Forwarded-For header to punch through the 5 req/sec quota.

Choose Traffic Scenario to TestClick to simulate
Architectural Guide & Interview Notes
↑ Jump to Interactive Studio

Deep Dive: The Spoofed Header Rate Limiter Bypass

An engineering analysis of why this AI-generated Pull Request passed isolated unit tests, how multi-tenant traffic exposes the architectural flaw, and how interviewers score your response.

The Root Cause Anti-Pattern

The Interviewer's Scoring Rubric

Candidates are assessed on whether they jump to trial-and-error editing or follow a hypothesis-driven approach. A "Strong Hire" candidate restates the data flow between modules, explains why single-client unit tests passed, crafts an adversarial probe showing cross-tenant leakage, and implements a surgical 1-line patch without breaking existing contracts.

Candidate Strategy for the Code Comprehension Round

  1. 1Map Module ContractsTrace how the gateway invokes the underlying service. Note what data is passed by reference vs. by value.
  2. 2Break It With An Adversarial ProbeSimulate concurrent or sequential traffic across multiple identities to force shared state mutation.
  3. 3Deliver a Surgical PatchMake the minimal required diff to ensure proper per-client state isolation without refactoring unnecessary files.