# GHSA-X239-6JQX-5HJH: getgrav/grav-plugin-login timing side channel

- Database: GitHub
- Severity: low (stated by ghsa, no CVSS score)
- Published: 2026-08-10
- Modified: 2026-08-10

## Affected versions

- getgrav/grav-plugin-login (Packagist): through 3.9.0

## Description

## Summary

classes/Controller.php's taskReset() and login.php's account activation handler both
compare the stored secret token against the user-supplied token using a plain ===
string comparison, a non-constant-time, early-exit comparison. This is CWE-208. The
same plugin correctly uses hash_equals() for two adjacent, analogous checks (the
RememberMe token storage and the magic-link login flow), so this looks like an
oversight on the two highest-stakes comparisons in the plugin rather than an
intentional choice.

## The core evidence

Password reset, classes/Controller.php, taskReset():

    [$good_token, $expire] = explode('::', $user->reset);
    if ($good_token === $token) {
        ...
        $user->password = $password;
        $user->save();

Account activation, login.php:

    [$good_token, $expire] = explode('::', $user->activation_token);
    if ($good_token === $token) {

Compare with the correct pattern already used elsewhere in this same plugin:

    classes/RememberMe/TokenStorage.php:
        if (!hash_equals($stored, $token)) { ... }

    login.php magic link flow:
        if (!hash_equals($storedHash, $tokenHash)) { ... }

## Live demonstration of the underlying timing effect

I measured PHP's === versus hash_equals() directly, 200,000 iterations per case,
median filtered, on a 32-character token matching the md5(uniqid($random_bytes, true))
format used here.

    === (used in reset/activation):
      wrong from position 0:    69 ns
      correct first 31 chars:   72 ns
      spread: 4.3%

    hash_equals (used elsewhere in this plugin):
      wrong from position 0:   128 ns
      correct first 31 chars:  128 ns
      spread: 0.0%

This confirms the real, language level effect exists and behaves exactly as expected.
hash_equals shows zero variance regardless of match position. I want to be precise
about scope. At roughly 3ns per character locally, this is a weak signal to extract
over real network jitter, which is normally microsecond to millisecond scale. This is
not a one request exploit.

## What changes the practical risk: no rate limiting on the actual guessing endpoint

I checked whether taskReset(), the endpoint that receives and compares $token, is rate
limited. It is not. The only rate limiter I found in this flow (the pw_resets context)
fires earlier, on the step that requests a reset email be sent, not on token
submission. Nothing stops an attacker from submitting unlimited attempts against a
known username to statistically average out network noise, which is exactly what a
practical remote timing attack needs in order to overcome a weak per request signal.

## Honest scoping

I have not built, and do not have a way to ethically build, a genuine network based
demonstration proving this is exploitable end to end against real infrastructure. That
would require a live target and heavy statistical sampling. I am reporting the
confirmed facts: the wrong comparison function is used, the underlying timing effect is
real and measured, there is no rate limit on the endpoint that would otherwise blunt a
repeated sampling attack, and the fix has zero downside. I would rather hand over an
honestly scoped moderate finding than an overclaimed critical one I cannot back with a
live network PoC.

## Impact

An attacker who can extract enough signal from the timing difference, aided by the
complete absence of rate limiting on the token submission endpoint, could recover a
valid password reset token for a known username and set an arbitrary new password on
that account, or recover a valid activation token and activate (and in some
configurations, per plugins.login.user_registration.options.login_after_registration,
log in as) an account they do not control.

## Suggested fix

Replace both === comparisons with hash_equals(), matching the pattern already used
correctly elsewhere in this plugin. Also add rate limiting to taskReset()'s token
check itself, not only to the earlier email request step.

## Affected component

- classes/Controller.php, taskReset()
- login.php, account activation token check

## References

- https://github.com/getgrav/grav/security/advisories/GHSA-x239-6jqx-5hjh

Page: https://cve.now/GHSA-X239-6JQX-5HJH

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
