{"id":"GHSA-r44w-v6gf-x3p6","title":"pyLoad has an authentication bypass in API key validation (check_apikey cache)","summary":"pyLoad has an authentication bypass in API key validation (check_apikey cache)","severity":"high","cvss":8.1,"cwe":["CWE-287"],"vendor":"pyload-ng","product":"pyload-ng","ecosystem":"pip","affected":["pyload-ng < 0.5.0b3.dev101"],"patched":["pyload-ng 0.5.0b3.dev101"],"published":"2026-10-09","updated":"2026-10-09","sourceUpdated":"2026-10-09T16:43:56Z","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-r44w-v6gf-x3p6","references":[{"url":"https://github.com/pyload/pyload/security/advisories/GHSA-r44w-v6gf-x3p6"},{"url":"https://github.com/pyload/pyload/commit/00d1372510f915f843b1574a3f1b28fbb724a42e"},{"url":"https://github.com/advisories/GHSA-r44w-v6gf-x3p6"}],"tags":["ghsa","pip"],"ingestedAt":"2026-10-09T17:04:42.813Z","slug":"GHSA-r44w-v6gf-x3p6","body":"## Overview\n\n## Summary\n\nThe API-key cache in `check_apikey()` allows an attacker to authenticate with a **forged API key** as long as the legitimate key for the same `key_id` has been used recently.\n\nOn a cache hit, the API key **secret is never verified**, resulting in a complete authentication bypass during the cache lifetime.\n\n---\n\n# Affected Components\n\n- `src/pyload/core/api/init.py`\n  - `Api.check_apikey()`\n\n- `src/pyload/core/database/apikey_database.py`\n  - `check_apikey()`\n  - `_check_key()`\n\nThe cache is used by normal API requests through:\n\n- `src/pyload/webui/app/helpers.py`\n\nwhich calls:\n\n```python\napi.check_apikey(api_key)\n```\n\nwithout providing a `ttl`, meaning the default **300-second cache** is always enabled.\n\n---\n\n# Root Cause\n\nSuccessful API key validations are cached in:\n\n```python\nself._apikey_cache\n```\n\nusing the following structure:\n\n```python\n{\n    key_id: (timestamp, cached_data)\n}\n```\n\nThe cache key is based **only on `key_id`**, and that value is parsed directly from the user-supplied API key rather than being obtained from a trusted lookup.\n\nWhen a cache hit occurs within the TTL, `check_apikey()` returns:\n\n```python\n{\n    \"success\": True,\n    \"data\": cached_data\n}\n```\n\nafter checking only:\n\n- `expires_at`\n\nAt no point on this execution path is the supplied secret:\n\n```text\napikey[-43:]\n```\n\ncompared against the stored key hash.\n\n---\n\nThe actual secret verification exists only in:\n\n```python\n_check_key()\n```\n\nwhich correctly uses:\n\n```python\nhmac.compare_digest()\n```\n\nHowever, this function is only reached on a **cache miss** through the database layer's `check_apikey()` implementation.\n\nFurthermore, the cached object cannot be used for verification because it intentionally does **not** include the stored key hash.\n\nThe cached record contains only:\n\n- `id`\n- `user_id`\n- `name`\n- `created_at`\n- `expires_at`\n- `last_used`\n\nSince `key_hash` is absent, the cache lacks the information required to validate the presented secret.\n\nAs a result, once a legitimate request populates the cache, every subsequent request using the same `key_id` within the 300-second cache window is accepted **without validating the secret**.\n\n---\n\n# Impact\n\n`key_id` values are small sequential integers assigned when API keys are created (1, 2, 3, ...), making them trivial to enumerate.\n\nThe API key format is also publicly reconstructable from the source code.\n\nAn attacker therefore does **not** need to know any valid API key secret.\n\nThey only need a `key_id` whose legitimate key has been used within the previous five minutes, which is likely on an actively used deployment.\n\nDuring that cache window, a forged API key follows exactly the same authentication path as a legitimate key and inherits the associated user's permissions.\n\nThis results in a **complete remote authentication bypass**.\n\nI would classify the issue as **Critical** severity.\n\n---\n\n# Estimated CVSS v3.1\n\n```\nAV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H\n```\n\n(`AC:H` only because successful exploitation depends on the cache already containing an entry.)\n\n---\n\n# Reproduction\n\n### 1. Create an administrator account.\n\n---\n\n### 2. Generate an API key.\n\nExample:\n\n```text\npl_11<43-character-secret>\n```\n\nwhere:\n\n```\nkey_id = 1\n```\n\n---\n\n### 3. Send a legitimate authenticated request.\n\n```bash\ncurl \\\n  -H \"X-API-Key: pl_11<real-43-char-secret>\" \\\n  http://127.0.0.1:8000/api/status\n```\n\nExpected response:\n\n```text\nHTTP/1.1 200 OK\n```\n\n---\n\n### 4. Within 300 seconds, send the same request using a forged API key.\n\n```bash\ncurl \\\n  -H \"X-API-Key: pl_11xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\" \\\n  http://127.0.0.1:8000/api/status\n```\n\nObserved response:\n\n```text\nHTTP/1.1 200 OK\n```\n\nThe request succeeds even though the API key secret is entirely incorrect.\n\n---\n\n# Control Test\n\nIf the forged API key is sent **before** any legitimate request has populated the cache, the server correctly returns:\n\n```text\nHTTP/1.1 401 Unauthorized\n```\n\nThe only difference between the failing and succeeding forged request is whether the cache already contains an entry for that `key_id`.\n\nThis isolates the vulnerability specifically to the cache-hit path.\n\n---\n\n# Suggested Fix\n\nCache hits should **never replace secret verification**.\n\nPossible approaches include:\n\n- Store a value derived from the complete API key (or its hash) in the cache and verify it using `hmac.compare_digest()` on every cache hit before returning success.\n\n- Alternatively, key the cache using a value derived from the **entire API key secret** (for example, a cryptographic hash of the complete API key) rather than using only `key_id`.\n\nRegardless of implementation, the security invariant should remain:\n\n> **The API key secret must be validated on every authenticated request, regardless of whether the cache is hit or missed.**\n\n## Affected packages\n\n- `pyload-ng < 0.5.0b3.dev101`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `pyload-ng 0.5.0b3.dev101`","depth":"twilight","depthScore":45,"depthScoreParts":{"impact":44.6,"likelihood":0,"exploitation":0,"ransomware":0},"changes":[]}