/

CVE-2024-48928

Severity:

HIGH RISK

(7.5)

Insufficient Entropy / Weak Cryptographic Secrets

CVE-2024-48928

Analyzed

Vulnerability type

Category:

Insufficient Entropy / Weak Cryptographic Secrets

CWE:

CWE-330

Impact:

Security Token Prediction and Weakening of CSRF and Ephemeral Key Protections

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Piwigo 14.x initializes its secret_key configuration parameter using MD5(RAND()) in MySQL, where RAND() provides only about 30 bits of entropy.

This low randomness makes it feasible to brute-force the secret key in roughly an hour, which in turn weakens CSRF token strength and other tokenized security mechanisms that partially depend on this key.

Affected context

The vulnerability arises during fresh installations of Piwigo in the 14.x branch, where the application generates its secret_key directly in the database using MD5(RAND()).

In this configuration, the global application secret that underpins CSRF tokens and other derived tokens is created with only around 30 bits of entropy.

Any Piwigo instance that retains this default-generated secret key and exposes web-accessible endpoints using CSRF and ephemeral tokens could be affected, especially in environments where an attacker can make repeated requests and observe token behavior.

Exploit preconditions

  • Attack surface: Web interface that exposes CSRF tokens and other values derived from the secret_key.
  • Required access: Ability to interact with the application as an external client (e.g., unauthenticated or low-privileged user) and repeatedly obtain CSRF or related tokens.
  • Trigger point: Repeated token collection and offline or online brute-force search over the limited key space to identify the correct secret_key.
  • Why exploitation is possible: The secret_key is generated from MD5(RAND()), where RAND() has only about 30 bits of randomness, making exhaustive search computationally feasible.

Why this happens

The core issue is the use of an insufficiently random source for generating a long-term cryptographic secret.

Instead of leveraging a cryptographically secure random number generator with high entropy, the installation process relies on MySQL's RAND() function and then hashes it with MD5, which does not add entropy but merely transforms the low-entropy value.

This aligns with CWE-330: Use of Insufficiently Random Values, where security-sensitive keys, tokens, or nonces are derived from predictable or low-entropy values, making them vulnerable to brute-force or prediction attacks.

Potential impact

  • Attackers may brute-force the secret_key in a practical time frame (on the order of about an hour).
  • CSRF tokens, which depend partially on the secret_key, can be more easily predicted or validated by an attacker.
  • Ephemeral keys or API-style tokens derived from the secret_key (e.g., values from get_ephemeral_key) can potentially be generated by an attacker who has recovered the key.
  • Some protections relying on secret token strength may be weakened, although features that also incorporate user passwords or session identifiers retain additional layers of protection.

General mitigation guidance

Mitigation focuses on using cryptographically strong randomness for application secrets and breaking the dependence on weak database RNG functions:

  • Generate long-lived application secrets (like secret_key) using a cryptographically secure random number generator provided by the operating system or a vetted crypto library.
  • Ensure that hashing (e.g., with MD5, SHA-256, etc.) is not misused as a substitute for entropy; hashing should not be relied upon to "strengthen" weak randomness.
  • Store generated secrets in configuration or environment variables managed outside of the database initialization logic, with secure defaults and rotation mechanisms.
  • Periodically review all token constructions (CSRF tokens, auto-login keys, ephemeral keys) to verify that they incorporate adequate entropy from secure sources and are not trivially derivable.
  • Follow a "secure-by-default" approach so that fresh installs always start with robust secret material without requiring extra administrator steps.

How teams detect issues like this

Detection typically involves both code-level and configuration-level analysis:

  • Static analysis / code review: Search for uses of general-purpose RNGs (RAND(), rand(), non-cryptographic PRNGs) in paths that generate secrets, tokens, keys, or session identifiers.
  • Configuration inspection: Check existing installations for known weak secret generation patterns (e.g., secrets that match MD5(RAND())-style formats or are short/structured).
  • Security testing: Perform focused tests on token generation endpoints to confirm token space size, collision rates, and predictability characteristics.
  • Policy enforcement: Establish engineering guidelines and automated checks that disallow non-cryptographic randomness for security-sensitive values, and integrate these into CI pipelines and code review tooling.

Sources

SourceLink
github.comgithub.com/Piwigo/Piwigo/commit/552499e0533ce54b55f4304b41ca6cd7ccce51f8
github.comgithub.com/Piwigo/Piwigo/security/advisories/GHSA-hghg-37rg-7r42

Frequently asked

questions

Exploitation is constrained by the need to perform a targeted brute-force search over the secret key space, but the reduced entropy makes that search practical in many environments, especially where an attacker can script repeated requests and observe CSRF or related tokens.

Typically no elevated backend access is required; an attacker generally only needs network access to the application and the ability to collect tokens over time. However, some impact areas (like auto login keys) may still require knowledge of user-specific secrets such as passwords.

Replace any use of RAND() (or similar non-cryptographic RNGs) in secret generation with a cryptographically secure random generator, and ensure that all secrets and tokens are derived from high-entropy values rather than from predictable or low-entropy sources.

Adopt a standard cryptography and secret-management guideline for the project: always use OS-level CSPRNG APIs, avoid relying on hashing to "improve" weak randomness, regularly review token and key generation logic, and include automated checks that flag non-cryptographic randomness in security-sensitive code paths.

Find out what's already
exploitable in your codebase.