Math.random is not secure for secrets or tokens
Math.random is not cryptographically secure; HFS CVE-2026-61500 shows the cost, and four calls replace it.
Published here · 10 sources · Resume reading
Math.random() is not secure for secrets: MDN says it does not provide cryptographically secure random numbers and should not be used for anything related to security. [1] Rejetto HFS 3.0.0 through 3.2.0 built its session-cookie signing key from it, and CISA added that bug, CVE-2026-61500, to its list of exploited vulnerabilities on 2026-11-30. [2][3]
Related reading: read what a JWT gives away to anyone, pick the OAuth flow that resists stolen codes and patch the Xen Orchestra empty-object login bypass. Browse the Security topic.
Update HFS to 3.2.1 or later
If you run HFS, this is the step with a deadline. VulnCheck rates the bug CVSS 9.3 and lists versions 3.0.0 through 3.2.0. [2] Version 3.2.1 was released on 2026-07-13, and its notes say "Multiple security vulnerabilities have been found in all previous versions, potentially allowing an attacker to gain administrative access to HFS." [4]
The newest release on the HFS releases page is 3.4.2, published 2026-11-24 and labelled "Important security update", so update to that rather than stopping at 3.2.1. [5]
CISA gave US federal agencies until 2026-12-03 to act and marked forensic triage as required. [3]
Check whether someone already got in
Updating closes the hole. It does not undo an admin session an attacker already forged.
The VulnCheck advisory describes the attack: collect a few login responses, rebuild the state of the Math.random() generator from the values they leak, recover the signing key, forge an administrator cookie, then run code through the server_code configuration feature. [2] Read what is in server_code on your server and remove anything you did not put there.
The HFS 3.2.1 notes credit Zach Hanley of Horizon3.ai, "in collaboration with Claude and Anthropic Research". [4]
Find Math.random in your own code
The HFS bug is not specific to file servers. Any session key, reset link, API token or invite code made with Math.random() has the same weakness. [1]
In a git repository, git grep lists every line that matches, with -n adding line numbers. [6]
git grep -n "Math.random"Most hits will be harmless: shuffling a list, jitter on a retry, a random colour. Replace the ones that make something secret.
Replace it with a secure generator
Every language here ships a generator meant for secrets. Use it for anything a stranger should not be able to guess.
In Node.js, crypto.randomBytes() "generates cryptographically strong pseudorandom data". [7]
const { randomBytes } = require('node:crypto');
const buf = randomBytes(256);In the browser, MDN points to Crypto.getRandomValues(), which fills a typed array in place. MDN also says to prefer generateKey() when you are making a key. [1][8]
const array = new Uint32Array(10);
self.crypto.getRandomValues(array);In Python, the secrets module is meant for this. The docs say to use it in preference to the random module, which is "designed for modelling and simulation, not security or cryptography". [9]
import secrets
token = secrets.token_urlsafe()In Go, crypto/rand is the secure generator. rand.Text(), added in Go 1.24, returns a random string with at least 128 bits of randomness, meant for a secret string, token or password. [10]
import "crypto/rand"
token := rand.Text()You now have one search that finds the risky calls and a secure replacement for each runtime.
Send this to the developer on your team whose reset links come from Math.random().
Keep this guide
Questions about this guide
Is Math.random cryptographically secure?
No. MDN says Math.random() does not provide cryptographically secure random numbers and should not be used for anything related to security. It points to Crypto.getRandomValues() instead.
Which HFS versions are affected by CVE-2026-61500?
VulnCheck lists Rejetto HFS 3.0.0 through 3.2.0. Version 3.2.1, released on 2026-07-13, fixes it, and the newest release on the HFS releases page is 3.4.2 from 2026-11-24.
Is CVE-2026-61500 being exploited?
CISA added it to the Known Exploited Vulnerabilities catalog on 2026-11-30, with a due date of 2026-12-03 for US federal agencies and forensic triage required.
What replaces Math.random in Node.js?
crypto.randomBytes() from node:crypto. The Node.js docs say it generates cryptographically strong pseudorandom data.
Sources
- MDN: Math.random()developer.mozilla.org
- rejetto/hfs: release 3.2.1github.com
- rejetto/hfs: releasesgithub.com
- Git docs: git grepgit-scm.com
- Node.js docs: crypto.randomBytesnodejs.org
- MDN: Crypto.getRandomValues()developer.mozilla.org
- Python docs: secretsdocs.python.org
- Go docs: crypto/randpkg.go.dev