//nefariousplan

Hash Is Not Entropy

A security token is derived by running a cryptographic hash over a low-entropy value (a timestamp, a counter, a username, an autoincrement primary key). The cryptographic strength of the hash function is treated as compensating for the predictability of the input. It does not. The hash is a deterministic function; the output's entropy is bounded by the input's entropy, regardless of how the bits are spread across the digest.

A handler needs to mint a token that looks random. A cryptographic hash function maps any input to a digest whose bytes pass every visual and statistical test for randomness. The construction is one line: take something the handler already has, pass it through SHA-256 or MD5, call the digest the token. The developer is reasoning about the hash function's pre-image resistance, which is real and very strong. The attacker is reasoning about the input.

The hash is a deterministic function. Its output's entropy is bounded by its input's entropy. If the input is the current time, a sequence counter, a username, or a row's primary key, the number of outputs the construction can produce is the number of inputs it can accept, and the attacker enumerates that set in the forward direction. Hash functions are designed to run fast in that direction. The appearance of randomness in the digest is a visual illusion the developer sees when they print the hex. It is not randomness the attacker has to invert.

Mechanism

The class requires three things: a security-relevant token (password reset, session, invite, API key, confirmation code), a deterministic derivation routine that includes a cryptographic hash, and an input to that derivation drawn from a space the attacker can observe or enumerate.

The input is often not literally secret-looking, and the derivation was chosen because the developer was reasoning about pre-image resistance. Allegra's calculateTokenExpDate returned System.currentTimeMillis() + 28_800_000 and the next line was sha256(String.valueOf(expDate)). The handler's own response carried a Date: header that named the second the token was minted, inside a one-thousand-millisecond window the attacker enumerated at one HTTP GET per candidate. The function's name is the audit trail: it computes when the token expires, and the line that called it computed the token from the return value. Hashing a return value does not change what the return value was; calculateTokenExpDate returned an expiration date, and the token was the hash of an expiration date.

OpenMage's API session handler composed md5(time() . uniqid('', true) . $sessionName). The three inputs collapse to one: time() is the wall clock to the second, uniqid() is an LCG seeded from the wall clock whose PHP manual page warns it "does not generate cryptographically secure values," and $sessionName is a handler constant. The attacker read the clock from the response Date: header, narrowed the microsecond and LCG window from a handful of self-minted tokens, and brute-forced the remainder against an unrate-limited XML-RPC endpoint. A 2012 upstream change added uniqid to this same construction in response to "a randomness concern," replacing one time-derived input with a time-derived function. The schema column sized at forty characters (MD5 hex digest) had to be widened to sixty-four (SHA-256) in the fix; the storage layer's testimony that the field's design only ever expected a hash output.

FiberHome's HG6145F1 default PSK is the degenerate case. The derivation is not a hash at all, it is 'wlan' + ~SSID_suffix, a constant-prefix concatenation with the bitwise complement of twenty-four bits the device is required to broadcast. The exhibit isolates the cognitive error from the hash function itself. SHA-256 is not where the mistake lives. The mistake lives in reading the appearance of transformation as the production of entropy. A deterministic function with an attacker-observable input has no more output entropy than the input bits the attacker can see; the choice of function is an accounting detail for how long the enumeration takes. FiberHome's per-device PSK keyspace is one.

The cognitive error is predictable. The developer who chose the hash was reasoning about the difficulty of inverting SHA-256, which is genuinely high. Inverting the hash is not what an attacker needs to do here. The attacker enumerates a small set of plausible inputs and hashes each one forward. Hash functions are designed to make exactly that operation cheap. A laptop runs tens of millions of SHA-256s per second. Twenty-five bits of input is thirty-three million candidates and resolves in a second with no network involved; collapsed to ten bits by one Date: header, it resolves in a thousand GETs.

The failure repeats across implementations because the construction is a one-line shortcut for "make this field look like a random-looking string." Every language's standard library ships a cheap hash primitive; many do not ship a cheap CSPRNG primitive at the same reach. The developer who typed sha256(something) had the primitive already loaded; typing SecureRandom.nextBytes or secrets.token_bytes is a different reflex. The patch for every instance of this class is the same shape: stop deriving the token from a public value, generate it from a CSPRNG, and let the hash out of the construction. Allegra's 8.1.4 and OpenMage's fix both arrive there. The function whose name describes the expiration date keeps its name; the line that called it to derive the token is the line that gets deleted.

Exhibits

CVE-2025-6216: Allegra's Password-Reset Token Was the SHA-256 of Its Own Expiration Date. Allegra's password-reset handler computes expDate = currentTimeMillis() + 28_800_000, then ships SHA-256(String.valueOf(expDate)) as the reset token. The function that returns the integer is named calculateTokenExpDate, the function whose name describes when the token expires returns the value the token is hashed from. The eight-hour expiration window bounds the input space at roughly 25 bits; the Date: HTTP response header from the same POST that issued the token collapses that to ~10 bits. SHA-256 of a 25-bit integer is recoverable on a laptop in seconds; SHA-256 of one of a thousand integers is recoverable in roughly a thousand HTTP GETs. This post is the canonical exhibit for the pattern: hash output looks unguessable, hash input is guessable, output entropy is input entropy.

CVE-2025-63353: FiberHome's HG6145F1 Default PSK Is the SSID, Inverted. FiberHome's default PSK for the HG6145F1 is 'wlan' + ~SSID_suffix, where the transform is bitwise complement across twenty-four bits and the input is the device's broadcast SSID. The pattern's canonical Allegra and OpenMage exhibits used a cryptographic hash over a low-entropy input; LiteLLM used a substring; this one uses constant XOR. The mathematical claim is the same in all four cases: the entropy of a derived secret is bounded by the entropy of the input region the derivation actually reads, regardless of how the bits are spread by whatever function sits in between. FiberHome's variant is the bare-floor version: the smallest deterministic function the pattern admits, applied to twenty-four bits the device is required to broadcast. The per-device PSK keyspace is one.

CVE-2026-42155: OpenMage's API Session ID Is the MD5 of When You Logged In. OpenMage's API session ID is md5(time . uniqid('', true) . sessionName), three inputs that all derive from the wall clock or a non-cryptographic PRNG seeded from the wall clock. The reporter recovers the second from the Date: response header, narrows the microsecond and LCG window with a few observed tokens minted under their own account, and brute-forces the remainder over the unrate-limited XML-RPC endpoint. The construction has shipped continuously since Magento 1.3.2 (2009); a 2012 release added uniqid to fix a randomness concern, replacing one time-derived input with the function whose own PHP manual page warns it "does not generate cryptographically secure values." The schema column for the token was sized at forty characters in 2009 and had to be widened to sixty-four in the patch, the schema's testimony that the field's design only ever expected a hash digest. The exhibit pairs with the Allegra password-reset one: same shape, this time the hashed input is observable rather than computable from the response time alone, and three sibling handlers in the same codebase (getRandomConfirmationKey, generateResetPasswordLinkCustomerId, uniqHash) still use the same construction unpatched.

CVE-2026-35030: LiteLLM Cached the User Under the JWT Header. Hash-is-not-entropy is the cousin pattern at the same level of abstraction. There a cryptographic hash is applied to a guessable input and the developer treats the digest's surface randomness as if it compensates for the input's low entropy. Here the transform is not a hash at all, it is a substring, and the developer treats token[:20] as if it captures per-actor entropy on the same misreading. Both cases share the underlying error: a derived key whose entropy is bounded by the entropy of the input region the derivation actually reads. Allegra and OpenMage misread the input as random; LiteLLM misread the region.

Boundaries

Not every hash of user input is this pattern. HMAC-based message authentication, password hashing with a slow KDF (bcrypt, scrypt, argon2), and HKDF-with-strong-IKM all run a hash over attacker-influenced bytes correctly, because the construction's security rests on a secret key, a memory-hard work factor, or a high-entropy key-material slot that the hash composes with the public input. The pattern lands only when the only input to the derivation is low-entropy or attacker-observable; adding a server-side CSPRNG-generated secret to the hash (keyed MAC, salted KDF) moves the construction out of this class.

Not every short or truncated token is this pattern. A token generated from SecureRandom.nextBytes(32) and truncated to its first eight hex characters still carries thirty-two bits of real entropy and is enumerable only up to that bound. The mechanism of this class is input entropy, not output length. A sixty-four-character hex token with twenty-five bits of input entropy is this class; a twelve-character hex token with forty-eight bits of input entropy is not, regardless of how uncomfortable the output length looks in review.

Not every low-entropy-input collapse is this pattern. prefix-is-not-identity covers the case where the derivation is a fixed-length slice of a high-entropy value whose entropy happens to sit outside the slice window; the input had the entropy, the derivation threw it away. shared-prng-stream covers the case where the derivation reads a non-cryptographic PRNG whose state is also observable through another unauthenticated code path; the input had nominal entropy, the attacker reads it through the side channel. Hash-is-not-entropy covers the case where the input itself is low-entropy or attacker-observable from the start, regardless of what deterministic function wraps it. All three are cousin collapses of a secret's attacker-visible entropy to its attacker-unobservable input region, and the distinctions matter at the patch site.

Defender playbook

Trace every security-token generator back to its entropy source. For each call site that mints a secret (reset tokens, session IDs, invitation codes, confirmation keys, API keys), identify the first bytes that enter the construction and classify them. SecureRandom.nextBytes, /dev/urandom, crypto.getRandomValues, secrets.token_bytes: these are the token's real entropy. Anything else, a wall-clock timestamp, a monotonic counter, an autoincrement primary key, a user-supplied string, is low-entropy and attacker-observable; a hash wrapper does not change that. The audit is one pass up the call stack per minting site.

Grep the intermediate variable name. If the value passed into your token-generation hash is bound to an identifier that mentions time, date, millis, now, epoch, counter, seq, id, name, email, uuid1, or uniqid, treat it as a confirmed finding until proven otherwise. Allegra's function was literally named calculateTokenExpDate; OpenMage hashed time . uniqid('', true) . $sessionName; the pattern is usually visible in the identifier of the variable that reaches the digest. The grep is faster than reading the handler and finds the shape when the handler's control flow hides it.

Prove the brute force. Mint a legitimate token under an account you control and capture the response's Date: header to the second. Enumerate the plausible input range (the millisecond window inside that second, the counter step since a recent account you also created, the ID gap between two rows you own) and hash each candidate under the same construction. If one of those hashes equals a token the server would accept on the authenticating endpoint, the class is live in production. The exercise runs in under a minute per endpoint, requires no vendor cooperation, and produces an exploit artifact a reviewer can replay.

Audit the storage schema. The column width that holds a security token tells you what the designer expected to store. A fixed-width column sized exactly to one digest, forty characters for MD5 hex, sixty-four for SHA-256, thirty-two for raw MD5, is testimony that the field was only ever designed to carry a hash output. A column widened in a security patch (OpenMage's grew from forty to sixty-four bytes in the CVE fix) is the audit trail of this class being recognized after the fact. For any column whose width is a digest width, confirm the application layer writes CSPRNG bytes into it, not a hash of something else.

Kinship

Prefix Is Not Identity. Cousin pattern at the same abstraction level. Prefix-is-not-identity covers a derivation that slices a fixed-length prefix off a value and treats the slice as per-actor entropy; when the producer's encoding concentrates the entropy past the slice window (a JWT payload past the {"alg":"RS256", header, a URL path past the host, a salted hash past the salt), every actor's value collapses to one bucket. Hash-is-not-entropy covers a derivation whose input is low-entropy from the start, regardless of whether the function is a hash, a prefix, a cast, or a bitwise XOR. The shared principle is that a derived secret's attacker-visible entropy is bounded by the entropy of the input region the derivation actually reads; the LiteLLM CVE-2026-35030 exhibit bridges the two patterns and names hash-is-not-entropy as the cousin on its own gloss here.

Caller Chosen Key. Adjacent cryptographic-primitive pattern on a different axis. Caller-chosen-key covers a verifier that correctly runs the cryptographic step against inputs the caller selected (the signing key, the algorithm, or the trust anchor comes from the artifact being verified). Hash-is-not-entropy covers a minter that correctly runs the derivation function against inputs the attacker can enumerate. Both read a sound primitive's ok return as authentication evidence it does not carry; in caller-chosen-key the attacker chose the policy, in hash-is-not-entropy the attacker chose nothing because the designer never put a secret in the construction.

The digest looked random to the developer who typed the function call. It did not look random to anyone enumerating its inputs.