pyLoad has a Session Cookie Security Downgrade via Untrusted X-Forwarded-Proto Header Spoofing (Global State Race Condition)
Date: 2026-04
Affected: pip/pyload-ng
Attack vector: dos
Category: vulnerability-disclosure
Severity: Medium
CVE: CVE-2026-40594
CWE: CWE-346
CVSS: 4.8 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:L)

## Summary The `set_session_cookie_secure` `before_request` handler in `src/pyload/webui/app/__init__.py` reads the `X-Forwarded-Proto` header from any HTTP request without validating that the request originates from a trusted proxy, then mutates the **global** Flask configuration `SESSION_COOKIE_SECURE` on every request. Because pyLoad uses the multi-threaded Cheroot WSGI server (`request_queue_size=512`), this creates a race condition where an attacker's request can influence the `Secure` flag on other users' session cookies — either downgrading cookie security behind a TLS proxy or causing a session denial-of-service on plain HTTP deployments. ## Details The vulnerable code is in `src/pyload/webui/app/__init__.py:75-84`: ```python # Dynamically set SESSION_COOKIE_SECURE according to the value of X-Forwarded-Proto # TODO: Add trusted proxy check @app.before_request def set_session_cookie_secure(): x_forwarded_proto = flask.request.headers.get("X-Forwarded-Proto", "") is_secure = ( x_forwarded_proto.split(',')[0].strip() == "https" or app.config["PYLOAD_API"].get_config_value("webui", "use_ssl") ) flask.current_app.config['SESSION_COOKIE_SECURE'] = is_secure ``` The root cause has two components: 1. **No origin validation (CWE-346):** The `X-Forwarded-Proto` header is read from any client request. This header is only trustworthy when set by a known reverse proxy. Without `ProxyFix` middleware or a trusted proxy allowlist, any client can


Mitigations:

Architectural layers (MAESTRO):