{"id":"CVE-2026-40594","aliases":["CVE-2026-40594","GHSA-mp82-fmj6-f22v","PYSEC-2026-125"],"related":[],"kind":"vulnerability","state":"published","title":"pyLoad: Session Cookie Security Downgrade via Untrusted X-Forwarded-Proto Header Spoofing (Global State Race Condition)","summary":"pyLoad is a free and open-source download manager written in Python. Prior to 0.5.0b3.dev98, 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. This vulnerability is fixed in 0.5.0b3.dev98.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"pyLoad is a free and open-source download manager written in Python. Prior to 0.5.0b3.dev98, 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. This vulnerability is fixed in 0.5.0b3.dev98.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nThe `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.\n\n## Details\n\nThe vulnerable code is in `src/pyload/webui/app/__init__.py:75-84`:\n\n```python\n# Dynamically set SESSION_COOKIE_SECURE according to the value of X-Forwarded-Proto\n# TODO: Add trusted proxy check\n@app.before_request\ndef set_session_cookie_secure():\n    x_forwarded_proto = flask.request.headers.get(\"X-Forwarded-Proto\", \"\")\n    is_secure = (\n        x_forwarded_proto.split(',')[0].strip() == \"https\" or\n        app.config[\"PYLOAD_API\"].get_config_value(\"webui\", \"use_ssl\")\n    )\n    flask.current_app.config['SESSION_COOKIE_SECURE'] = is_secure\n```\n\nThe root cause has two components:\n\n1. **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 spoof it. The code itself acknowledges this with the TODO on line 76.\n\n2. **Global state mutation in a multi-threaded server:** `flask.current_app.config['SESSION_COOKIE_SECURE']` is application-wide shared state. When Thread A (attacker) writes `False` to this config, Thread B (victim) may read `False` when Flask's `save_session()` runs in the after_request phase, producing a `Set-Cookie` response without the `Secure` flag.\n\nThe Cheroot WSGI server is configured with `request_queue_size=512` in `src/pyload/webui/webserver_thread.py:46`, confirming concurrent multi-threaded request processing.\n\nNo `ProxyFix` or equivalent middleware is configured anywhere in the codebase (confirmed via codebase-wide search).\n\n## PoC\n\n**Attack Path 1 — Cookie Security Downgrade (behind TLS-terminating proxy, `use_ssl=False`):**\n\nAn attacker with direct access to the backend (e.g., in a containerized/Kubernetes deployment) sends concurrent requests to keep `SESSION_COOKIE_SECURE` set to `False`:\n\n```bash\n# Attacker floods backend directly, bypassing TLS proxy\nfor i in $(seq 1 200); do\n  curl -s -H 'X-Forwarded-Proto: http' http://pyload-backend:8000/ &\ndone\n\n# Meanwhile, a legitimate user behind the TLS proxy receives a session cookie\n# During the race window, their Set-Cookie header lacks the Secure flag\n# The cookie is then vulnerable to interception over plain HTTP\n```\n\n**Attack Path 2 — Session Denial of Service (default plain HTTP deployment):**\n\n```bash\n# Attacker causes SESSION_COOKIE_SECURE=True on a plain HTTP server\nfor i in $(seq 1 200); do\n  curl -s -H 'X-Forwarded-Proto: https' http://localhost:8000/ &\ndone\n\n# Concurrent legitimate users receive Set-Cookie with Secure flag\n# Browser refuses to send Secure cookies over HTTP\n# Users' sessions silently break — they appear logged out\n```\n\nThe second attack path works against the default configuration (`use_ssl=False`) and requires no special network position.\n\n## Impact\n\n- **Session cookie exposure (Attack Path 1):** When deployed behind a TLS-terminating proxy, an attacker can cause session cookies to be issued without the `Secure` flag. If the victim's browser subsequently makes an HTTP request (e.g., via a mixed-content link or downgrade attack), the session cookie is transmitted in cleartext, enabling session hijacking.\n\n- **Session denial of service (Attack Path 2):** On default plain HTTP deployments, an attacker can continuously set `SESSION_COOKIE_SECURE=True`, causing browsers to refuse sending session cookies back to the server. This silently breaks all concurrent users' sessions with no user-visible error message, only a redirect to login.\n\n- **No authentication required:** Both attack paths are fully unauthenticated — the `before_request` handler fires before any auth checks.\n\n## Recommended Fix\n\nReplace the global config mutation with per-response cookie handling, and add proxy validation:\n\n```python\n# Option A: Set Secure flag per-response instead of mutating global config\n@app.after_request\ndef set_session_cookie_secure(response):\n    # Only trust X-Forwarded-Proto if ProxyFix is configured\n    is_secure = app.config[\"PYLOAD_API\"].get_config_value(\"webui\", \"use_ssl\")\n    if 'Set-Cookie' in response.headers:\n        # Modify cookie flags per-response, not global config\n        cookies = response.headers.getlist('Set-Cookie')\n        response.headers.remove('Set-Cookie')\n        for cookie in cookies:\n            if is_secure and 'Secure' not in cookie:\n                cookie += '; Secure'\n            response.headers.add('Set-Cookie', cookie)\n    return response\n\n# Option B (preferred): Use Werkzeug's ProxyFix with explicit trust\nfrom werkzeug.middleware.proxy_fix import ProxyFix\n\n# In App.__new__, before returning:\nif trusted_proxy_count:  # from config\n    app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=trusted_proxy_count)\n# Then set SESSION_COOKIE_SECURE once at startup based on use_ssl config,\n# and let ProxyFix handle X-Forwarded-Proto transparently\n```\n\nAt minimum, remove the `before_request` handler entirely and set `SESSION_COOKIE_SECURE` once at startup (line 130 already does this in `_configure_session`). The dynamic per-request adjustment is the root cause of both the spoofing and the race condition.","format":"markdown","source":"ghsa"},{"lang":"es","text":"pyLoad es un gestor de descargas gratuito y de código abierto escrito en Python. Antes de la versión 0.5.0b3.dev98, el gestor before_request set_session_cookie_secure en src/pyload/webui/app/__init__.py lee la cabecera X-Forwarded-Proto de cualquier solicitud HTTP sin validar que la solicitud se origina de un proxy de confianza, luego muta la configuración global de Flask SESSION_COOKIE_SECURE en cada solicitud. Debido a que pyLoad utiliza el servidor WSGI Cheroot multiproceso (request_queue_size=512), esto crea una condición de carrera donde la solicitud de un atacante puede influir en la bandera Secure de las cookies de sesión de otros usuarios - ya sea degradando la seguridad de las cookies detrás de un proxy TLS o causando una denegación de servicio de sesión en implementaciones HTTP simples. Esta vulnerabilidad se corrige en la versión 0.5.0b3.dev98.","source":"nvd"}],"published":"2026-04-16T01:20:49.000Z","modified":"2026-11-11T23:10:00.263Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:L","score":4.8,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:L","score":4.8,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:L","score":4.8,"rating":"MEDIUM"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:L","score":4.8,"rating":"MEDIUM"}],"cwes":["CWE-346"],"affected":[{"ranges":[{"version":"< 0.5.0b3.dev98","status":"affected"}],"vendor":"pyload","product":"pyload","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.5.0b3.dev98"}],"ecosystem":"PyPI","package":"pyload-ng","purl":"pkg:pypi/pyload-ng","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"0.5.0b3.dev69"}],"vendor":"pyload-ng_project","product":"pyload-ng","cpe":"cpe:2.3:a:pyload-ng_project:pyload-ng:*:*:*:*:*:python:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.5.0b3.dev69"}],"ecosystem":"PyPI","package":"pyload-ng","purl":"pkg:pypi/pyload-ng","source":"pysec"}],"references":[{"url":"https://github.com/pyload/pyload/security/advisories/GHSA-mp82-fmj6-f22v","tags":["evidence","exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40594","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/pyload/pyload","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/pyload-ng/PYSEC-2026-125.yaml","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-04-21T18:01:27.681Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-40594","url":"https://www.cve.org/CVERecord?id=CVE-2026-40594","licence":"CVE Terms of Use","modified":"2026-04-21T18:01:30.556Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-mp82-fmj6-f22v","url":"https://github.com/advisories/GHSA-mp82-fmj6-f22v","licence":"CC-BY-4.0","modified":"2026-06-08T20:00:10.592Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-40594","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40594","licence":"Public domain","modified":"2026-11-11T23:10:00.263Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-125","url":"https://osv.dev/vulnerability/PYSEC-2026-125","licence":"CC-BY-4.0","modified":"2026-05-20T09:19:15.897Z"}],"updatedAt":"2026-11-25T22:59:19.125Z","epss":{"score":0.00177,"percentile":0.07649,"date":"2026-12-01T12:00:22.000Z"}}