Insufficient Session Expiration
Description
Description Component: classes/RememberMe/TokenStorage.php, method findTriplet() Package: getgrav/grav-plugin-login (Composer: getgrav/grav-plugin-login) Confirmed version: 3.8.12 (current develop HEAD, commit 322b6b9) Root cause TokenStorage implements the StorageInterface used by the birke/rememberme persistent-login library to validate the "Remember Me" cookie triplet (credential, token, persistentToken) on every auto-login attempt. storeTriplet() persists the record as a nested array: php$tokens[$persistentToken] = [$token => time()]; findTriplet() is intended to reject the triplet once it is older than the configured $timeout (constructor default 604800 seconds = 7 days): phppublic function findTriplet($credential, $token, $persistentToken) { $persistentToken = sha1($persistentToken); $token = sha1($token);
$file = $this->getFile($credential); $tokens = (array)$file->content();
if (!isset($tokens[$persistentToken]) || $tokens[$persistentToken] < time() + $this->timeout) { return self::TRIPLET_NOT_FOUND; } ... } The bug: tokens[tokens[ tokens[persistentToken] is an array ([$token => time()]), not the stored timestamp — the timestamp is one level deeper. PHP's comparison rules state an array is always considered greater than a scalar in </> comparisons, regardless of contents. I confirmed this empirically: Stored timestamp: 784010494 (~31 years in the past) $tokens[$key] < time()+timeout → bool(false) So the expiry branch of the || can never evaluate true — it is dead code. The only condition that actually causes rejection is !isset($tokens[$persistentToken]) (i.e., the record was deleted or overwritten). As a secondary, related defect, the $expire parameter accepted by storeTriplet()/replaceTriplet() is silently discarded and never used, so even an explicit expiry passed in by the caller has no effect. Impact The server-side validity window for a persistent "Remember Me" authentication token is supposed to be bounded (default 7 days) — this is the actual security boundary, since an attacker replaying a captured cookie value directly over HTTP is not constrained by client-side Expires/Max-Age cookie attributes. Due to this bug, a valid (token, persistentToken) pair remains accepted indefinitely — until the on-disk YAML record (user-data://rememberme/<sha1(credential)>.yaml) is overwritten by a subsequent auto-login or explicitly cleared (logout-everywhere / password change). Practical consequence: if a Remember Me cookie is ever exposed — via device theft, browser sync/backup leakage, XSS, log/proxy capture, or a stale browser profile — the exposure window is unbounded rather than the administrator-configured timeout, directly undermining the security control the rememberme.timeout setting is meant to provide. Proof of Concept php$storage = new \Grav\Plugin\Login\RememberMe\TokenStorage('user-data://rememberme', 604800); // Simulate a triplet stored 10 years ago $storage->storeTriplet('admin@example.com', 'plaintoken', 'persistenttoken'); // manually backdate the YAML file's timestamp to 10 years ago, then: $result = $storage->findTriplet('admin@example.com', 'plaintoken', 'persistenttoken'); // Expected: TRIPLET_NOT_FOUND (expired) // Actual: TRIPLET_FOUND — auto-login succeeds Suggested fix php$entry = $tokens[$persistentToken] ?? null; $storedTime = $entry ? current($entry) : null; if ($storedTime === null || $storedTime + $this->timeout < time()) { return self::TRIPLET_NOT_FOUND; } $stored = key($entry); if (!hash_equals($token, $stored)) { // also fixes the non-constant-time compare below return self::TRIPLET_INVALID; } (Also wire the ignored $expire parameter through, and switch $stored !== $token to hash_equals() while touching this method — that comparison is not currently timing-safe.)