GHSA-R44W-V6GF-X3P6

Vulnerability from github – Published: 2026-10-09 16:43 – Updated: 2026-10-09 16:43
VLAI
Summary
pyLoad has an authentication bypass in API key validation (check_apikey cache)
Details

Summary

The 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.

On a cache hit, the API key secret is never verified, resulting in a complete authentication bypass during the cache lifetime.


Affected Components

  • src/pyload/core/api/init.py
  • Api.check_apikey()

  • src/pyload/core/database/apikey_database.py

  • check_apikey()
  • _check_key()

The cache is used by normal API requests through:

  • src/pyload/webui/app/helpers.py

which calls:

api.check_apikey(api_key)

without providing a ttl, meaning the default 300-second cache is always enabled.


Root Cause

Successful API key validations are cached in:

self._apikey_cache

using the following structure:

{
    key_id: (timestamp, cached_data)
}

The 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.

When a cache hit occurs within the TTL, check_apikey() returns:

{
    "success": True,
    "data": cached_data
}

after checking only:

  • expires_at

At no point on this execution path is the supplied secret:

apikey[-43:]

compared against the stored key hash.


The actual secret verification exists only in:

_check_key()

which correctly uses:

hmac.compare_digest()

However, this function is only reached on a cache miss through the database layer's check_apikey() implementation.

Furthermore, the cached object cannot be used for verification because it intentionally does not include the stored key hash.

The cached record contains only:

  • id
  • user_id
  • name
  • created_at
  • expires_at
  • last_used

Since key_hash is absent, the cache lacks the information required to validate the presented secret.

As 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.


Impact

key_id values are small sequential integers assigned when API keys are created (1, 2, 3, ...), making them trivial to enumerate.

The API key format is also publicly reconstructable from the source code.

An attacker therefore does not need to know any valid API key secret.

They only need a key_id whose legitimate key has been used within the previous five minutes, which is likely on an actively used deployment.

During that cache window, a forged API key follows exactly the same authentication path as a legitimate key and inherits the associated user's permissions.

This results in a complete remote authentication bypass.

I would classify the issue as Critical severity.


Estimated CVSS v3.1

AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H

(AC:H only because successful exploitation depends on the cache already containing an entry.)


Reproduction

1. Create an administrator account.


2. Generate an API key.

Example:

pl_11<43-character-secret>

where:

key_id = 1

3. Send a legitimate authenticated request.

curl \
  -H "X-API-Key: pl_11<real-43-char-secret>" \
  http://127.0.0.1:8000/api/status

Expected response:

HTTP/1.1 200 OK

4. Within 300 seconds, send the same request using a forged API key.

curl \
  -H "X-API-Key: pl_11xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  http://127.0.0.1:8000/api/status

Observed response:

HTTP/1.1 200 OK

The request succeeds even though the API key secret is entirely incorrect.


Control Test

If the forged API key is sent before any legitimate request has populated the cache, the server correctly returns:

HTTP/1.1 401 Unauthorized

The only difference between the failing and succeeding forged request is whether the cache already contains an entry for that key_id.

This isolates the vulnerability specifically to the cache-hit path.


Suggested Fix

Cache hits should never replace secret verification.

Possible approaches include:

  • 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.

  • 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.

Regardless of implementation, the security invariant should remain:

The API key secret must be validated on every authenticated request, regardless of whether the cache is hit or missed.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "PyPI",
        "name": "pyload-ng"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "0.5.0b3.dev101"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [],
  "database_specific": {
    "cwe_ids": [
      "CWE-287"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-10-09T16:43:55Z",
    "nvd_published_at": null,
    "severity": "HIGH"
  },
  "details": "## 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\u0027s `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\u0027s 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\u003c43-character-secret\u003e\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\u003creal-43-char-secret\u003e\" \\\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\u003e **The API key secret must be validated on every authenticated request, regardless of whether the cache is hit or missed.**",
  "id": "GHSA-r44w-v6gf-x3p6",
  "modified": "2026-10-09T16:43:55Z",
  "published": "2026-10-09T16:43:55Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/pyload/pyload/security/advisories/GHSA-r44w-v6gf-x3p6"
    },
    {
      "type": "WEB",
      "url": "https://github.com/pyload/pyload/commit/00d1372510f915f843b1574a3f1b28fbb724a42e"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/pyload/pyload"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "pyLoad has an authentication bypass in API key validation (check_apikey cache)"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.