GHSA-4X9H-4683-5FCX
Login form skips an account's two-factor code when the global 2FA setting is off
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-4X9H-4683-5FCX divulgada | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
When the Login plugin's global `twofa_enabled` setting is off (the default), the site login form at `/login` signs in an account that has set up two-factor authentication with its password alone. Admin2 asks the same account for its code, because the API sign-in enforces two-factor for every account that has set it up. The API plugin also accepts the front-end session cookie, so a person who has only the account's password gets a session the API accepts with the account's full permissions, which on a stock install is a super-admin. The remember-me cookie and the magic link (when enabled) sign in the same way.
Affected versions
grav-plugin-login up to and including 3.10.1, on Grav 2.x sites that also run the API plugin (bundled with Admin2 in the `grav-admin` package) with `plugins.api.auth.session_enabled` on (the default). The login form has keyed the second factor off the global setting since two-factor support was added; it became a bypass when API 1.0.0 started letting every account set up two-factor from Admin2 whatever the global setting says, and accepting the front-end session. Grav 1.7 is not affected in the same way: the classic admin keeps its own session and enforces its own two-factor setting.
Details
`Controller::taskLogin()` passes `'twofa' => plugins.login.twofa_enabled` into `Login::login()`, and `LoginPlugin::userLoginAuthorize()` only delays authorization for the code when that option is set and the account has `twofa_enabled` and `twofa_secret`. The remember-me sign-in in `initializeSession()` and `handleMagicLogin()` pass the same option, and `taskTwoFa()` / `taskTwofa_cancel()` refuse to run while the setting is off. With the default `twofa_enabled: false`, a password-only login leaves the session user `authenticated` and `authorized`.
The API plugin decides two-factor from the account (`AbstractApiController::userRequiresTwoFactor()`: `twofa_enabled && twofa_secret`) and offers setup in Admin2 regardless of the Login setting (getgrav/grav#4145). Its `SessionAuthenticator` accepts any session user that is `authenticated` and `authorized`, so the front-end session above is accepted for every API route the account may use.
Reproduced on Grav 2.2.12 with Login 3.10.1, API 1.0.56 and Admin2 2.1.39: an `api.super` account set up two-factor through the API (as Admin2 does); `POST /api/v1/auth/token` then answered `requires_2fa: true`. A `POST /login` with the same username and password and no code answered 303, after which `GET /api/v1/me` on the same cookie returned 200 with `"super_admin": true`, and `POST /api/v1/users` created a new super-admin account. A remember-me cookie from a password-only login reached the API the same way.
Related: with the global setting on, the profile page's two-factor toggle could be saved as on without a secret (the secret shown on the page is only stored when Regenerate is pressed), leaving an account that reads as protected but is never asked for a code.
Impact
An attacker who has an account's password (phished, reused or leaked) but not its second factor gets a session with that account's full API permissions, defeating the second factor the account owner set up and that Admin2 visibly enforces. For an administrator account this is full control of the site.
Workarounds until updated: set `plugins.login.twofa_enabled: true`, or set `plugins.api.auth.session_enabled: false`.
Patches
Fixed in grav-plugin-login 3.11.0: an account that has set up two-factor is asked for its code at the site login, by the remember-me cookie and by a magic link whatever the global setting says, and the setting now only decides whether the profile page offers the setup. Turning two-factor on from the profile page without a saved secret is refused.
Credits
Reported by @onetrev.
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Packagistgetgrav/grav-plugin-login |
Corregida | 3.11.0 | — | — |
3.11.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/getgrav/grav/security/advisories/GHSA-4x9h-4683-5fcxLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
