Feb 24, 2026·6 min read·50 visits
Craft CMS failed to atomically validate token usage limits. Attackers can race simultaneous requests to reuse 'single-use' tokens (like admin impersonation links) before the database updates. Fixed in 4.16.19 and 5.8.23 via Mutex locking.
A classic Time-of-Check Time-of-Use (TOCTOU) race condition in Craft CMS allows attackers to bypass usage limits on sensitive tokens. By flooding the server with concurrent requests, a single-use administrative impersonation token can be reused multiple times, leading to potential privilege escalation and unauthorized access.
In the world of web security, "once" is a very difficult number to enforce. We build systems that rely on the concept of ephemeral access: password reset links, email verification codes, and the holy grail of Craft CMS workflow—User Impersonation Tokens.
These tokens are the digital equivalent of a "Self-Destructs in 5 Seconds" tape. The developer promises that a token can be used exactly N times (usually 1). Once consumed, it vanishes into the ether, preventing replay attacks or accidental reuse. It is a simple contract: Check Limit -> Permit Access -> Increment Counter.
But here is the dirty secret of web development: between the "Check" and the "Increment," time exists. And where time exists, hackers exist. CVE-2026-27128 is a pristine example of what happens when you trust PHP to handle concurrency without adult supervision. It turns out, if you scream at Craft CMS loud enough (and in parallel), it forgets how to count.
The vulnerability is a textbook Time-of-Check Time-of-Use (TOCTOU) race condition located in the Tokens service. This is CWE-367 in its purest form.
The logic flaw occurred because the application treated a database transaction as a casual conversation rather than a strictly serialized event. Here is the sequence of events that the code thought was happening:
usageCount < usageLimit? (e.g., is 0 < 1?).usageCount or delete the token.In a single-threaded universe, this is fine. But the web is not single-threaded. When an attacker sends 50 requests simultaneously (using HTTP/2 multiplexing or just a really fast script), all 50 requests might hit Step 1 and Step 2 before the first request reaches Step 4.
Since the database hasn't been updated yet, all 50 threads see usageCount = 0. All 50 threads pass the check. All 50 threads grant access. By the time the database catches up, the damage is done. The "single-use" token has just been used 50 times.
Let's dissect the vulnerable code in src/services/Tokens.php. This is a simplified view of the crime scene before the fix.
// The Vulnerable Logic
$result = (new Query())
->select(['id', 'usageLimit', 'usageCount'])
->from([Table::TOKENS])
->where(['token' => $token])
->one();
// THE GAP IS HERE
// Thousands of CPU cycles pass between the SELECT above
// and the logic below.
if ($result['usageLimit']) {
// The fatal check: PHP is checking stale memory
if ($result['usageCount'] < $result['usageLimit']) {
// Access Granted!
$this->incrementTokenUsageCountById($result['id']);
} else {
// Too late (in theory)
$this->deleteTokenById($result['id']);
}
}The fix implemented in commit 3e4afe18279951c024c64896aa2b93cda6d95fdf introduces a Mutex (Mutual Exclusion) lock. This forces the requests to form a single-file line. Request B cannot even check the token until Request A has finished updating it.
// The Fix (Mutex Implementation)
$mutex = Craft::$app->getMutex();
$lockKey = "token:$token";
// Try to acquire lock for 5 seconds
if (!$mutex->acquire($lockKey, 5)) {
return false; // Go away if busy
}
try {
// Re-fetch logic happens INSIDE the lock
// ... validation ...
} finally {
$mutex->release($lockKey);
}> [!NOTE]
> While a Mutex works, a more performant database-native solution would have been an atomic update: UPDATE tokens SET usageCount = usageCount + 1 WHERE token = ? AND usageCount < usageLimit. If the affected rows = 0, the token is dead. No Mutex required. But hey, a patch is a patch.
To exploit this, we don't need complex memory corruption exploits or ROP chains. We just need speed.
asyncio script.We configure the attack to hold back the TCP connection establishment and send the last byte of the HTTP request for 20 threads simultaneously (the "Last-Byte Sync" technique).
In a successful exploitation, the attacker ends up with multiple valid session cookies for the target user, effectively bypassing the security control that was supposed to limit exposure to a single click.
Why is getting 5 sessions better than 1? Persistence and stealth.
If I steal a single-use token and use it, the legitimate user might click the link 5 minutes later, get an error, and alert IT. "Hey, my link didn't work."
However, if I race the condition, I can consume the token and potentially leave it in a state where the legitimate user might still squeeze in (depending on how the race resolves on the delete), or more likely, I establish multiple sessions on different devices. One session is for active browsing; the others are backups in case I get kicked out.
Furthermore, in complex workflows where tokens trigger actions (like "Approve Expense Report" or "Deploy to Production"), replaying the token could trigger the business logic multiple times, leading to financial loss or corruption of state.
The official fix relies on Craft's Mutex component. This is effective, but it comes with a major infrastructure caveat that many sysadmins miss.
The Trap: If your Craft CMS application is load-balanced across multiple servers (e.g., AWS Autoscaling Group) and you are using the default FileMutex, you are still vulnerable. The file lock only exists on the local server's filesystem. Request A hits Server 1 (locked), but Request B hits Server 2 (unlocked). Race condition succeeds.
The Proper Fix:
config/app.php is using RedisMutex, MysqlMutex, or PgsqlMutex for distributed locking.// config/app.php
'components' => [
'mutex' => [
'class' => \craft\mutex\Mutex::class, // Ensure this maps to a distributed driver
],
],If you cannot patch immediately, you can mitigate this at the WAF level by strictly rate-limiting endpoints like actions/users/login-by-token, though this is a fragile bandage at best.
CVSS:4.0/AV:N/AC:H/AT:P/PR:H/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N| Product | Affected Versions | Fixed Version |
|---|---|---|
Craft CMS Pixel & Tonic | >= 4.5.0-RC1, < 4.16.19 | 4.16.19 |
Craft CMS Pixel & Tonic | >= 5.0.0-RC1, < 5.8.23 | 5.8.23 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-367 |
| Attack Vector | Network (Race Condition) |
| CVSS Score | 6.9 (Medium) |
| Impact | Security Bypass / Privilege Escalation |
| Affected Component | Tokens Service (getTokenRoute) |
| Exploit Status | PoC Available (Theoretical) |
The product checks the state of a resource before using it, but the resource's state can change between the check and the use in a way that invalidates the results of the check.
NATS Server prior to versions 2.12.8 and 2.14.3 contains an incorrect authorization vulnerability (CWE-863) in its message tracing subsystem. When evaluating whether a connection is permitted to publish trace events to a destination subject specified in the Nats-Trace-Dest header, the server only checks standard client permissions and omits permission checks for leaf node connections. This allows a connected leaf node operator with restricted publishing privileges to emit internal trace events to unauthorized subjects and suppress standard message delivery using the Nats-Trace-Only header.
CVE-2026-63341 is a high-severity Denial of Service (DoS) vulnerability in the Aedes MQTT broker for Node.js affecting all versions prior to 1.1.1. The flaw stems from missing input validation on the hierarchical depth of incoming MQTT topic strings before they are passed to the underlying topic-matching engine, qlobber. Because qlobber enforces a hardcoded limit of 100 topic levels and throws a synchronous exception when this threshold is exceeded, an attacker can send a single MQTT packet containing 101 or more forward-slash-separated levels to trigger an uncaught exception that immediately terminates the Node.js broker process.
CVE-2026-61725 is a path traversal vulnerability (CWE-22) in the sevenz-rust2 Cargo package prior to version 0.21.1. The vulnerability occurs because the decompression utility fails to validate or sanitize archive entry filenames before joining them with the destination directory path via std::path::Path::join. An attacker who supplies a crafted 7z archive containing parent directory traversal sequences or absolute paths can write or overwrite arbitrary files on the host filesystem with the privileges of the extracting process.
CVE-2026-77309 (GHSA-jrjx-9jjw-747m) is a high-severity unauthenticated remote code execution vulnerability affecting NASA-AMMOS AIT-GUI versions 1.0.0 through 2.5.0. The flaw results from chaining an incomplete file cleanup error in the telemetry query endpoint (/tlm/query) with a directory traversal flaw in the script execution endpoint (/script/run). An attacker on an adjacent network can stage arbitrary Python statements into a static file on disk and execute that file under the privileges of the AIT-GUI web server process.
A vulnerability classified under CWE-116 (Improper Encoding or Escaping of Output) exists in memtomem-stm versions 0.1.0 through 0.1.33. The software acts as a Model Context Protocol (MCP) short-term memory proxy gateway for AI agent architectures. When surfacing retrieved memories and scratchpad items into downstream Large Language Model (LLM) context envelopes, the SurfacingFormatter component fails to properly sanitize untrusted memory attributes. An attacker with the ability to plant untrusted content into the agent's long-term or working memory store can inject arbitrary structural delimiters, close the <surfaced-memories> XML boundary prematurely, visually obscure instructions using Unicode bidirectional overrides, and execute stored prompt injection attacks against downstream LLM agents.
CVE-2026-77331 (GHSA-72jh-722p-rqr3) is a concurrency and session-state synchronization vulnerability in memtomem-stm, a short-term memory proxy gateway for AI agents. In versions 0.1.2 prior to 0.1.34, concurrent Model Context Protocol (MCP) Remote Procedure Call (RPC) failures or mid-flight task cancellations can initiate duplicate reconnect loops and permit dirty or cancelled transport sessions to be reused. This deficiency results in session-state integrity loss and local service degradation.