Skip to content

Predictable Token Generation in auth.py and exam.py

High
inducer published GHSA-rvx5-95mm-p77v Apr 17, 2026

Package

pip relate-courseware (pip)

Affected versions

<=2024.1

Patched versions

2f68e16cd3b96d25c188c1aa3f7e13cdb15cdaeb

Description

I discovered a security vulnerability in the RELATE project related to
the use of a non-cryptographic PRNG for security-sensitive token
generation.

Location 1: course/auth.py → make_sign_in_key()

def make_sign_in_key(user: User) -> str:
    import random        ** * # ← Mersenne Twister (not cryptographic)***
    from time import time
    m = hashlib.sha1()
    m.update(user.email.encode("utf-8"))
    m.update(hex(random.getrandbits(128)).encode())  # predictable
    m.update(str(time()).encode("utf-8"))
    return m.hexdigest()

This token is used for:

  • Password reset links
  • Email-based sign-in
  • API authentication tokens

Location 2: course/exam.py → gen_ticket_code()

def gen_ticket_code():
    from random import choice  # ← PRNG, not CSPRNG
    return "".join(choice(ticket_alphabet) for _i in range(8))

This token is used for exam ticket codes.

Impact
Python's random module uses Mersenne Twister which is not
cryptographically secure. An attacker who observes enough
outputs can predict future tokens, potentially allowing:

  • Account takeover via password reset token prediction
  • Unauthorized exam access via ticket code prediction

Recommended Fix

Location 1:

import secrets
def make_sign_in_key(user: User) -> str:
    return secrets.token_hex(32)**

Location 2:

import secrets
ticket_alphabet =
"ABCDEFGHJKLPQRSTUVWXYZabcdefghjkpqrstuvwxyz23456789"
def gen_ticket_code():
    return "".join(secrets.choice(ticket_alphabet) for _ in range(8))

Credit: Ruslan Amrahov

Severity

High

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 v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Changed
Confidentiality
None
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:N/I:H/A:H

CVE ID

CVE-2026-41505

Weaknesses

Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)

The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong. Learn more on MITRE.