GHSA-F9VC-QVC8-P7CF
Two-factor authentication bypass in the Gogs web API through a leading-slash path mismatch
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-F9VC-QVC8-P7CF divulgada · CVSS 8.1 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
An attacker who knows a user's password but not the user's second factor can send HTTP Basic credentials to a path with an extra leading slash, such as `//api/web/user/settings/two-factor`. The authentication check compares the raw request path against the literal prefix `/api/web/`, so the extra slash makes the check skip and the password is accepted. The router trims leading slashes before matching and still sends the request to the intended handler.
The attacker can then call the web API routes that change credentials and two-factor authentication. Disabling two-factor authentication with a single DELETE request is enough. After that, a normal password sign-in succeeds without any second factor. On an administrator account this gives full site administration. The independent reviewer also read all recovery codes and used one to complete the MFA challenge, read the admin user list and configuration while two-factor authentication was enabled, changed the account password, and reproduced the behavior on a non-admin account. The issue is present in commit `4816842955f4b49e0dc510b5c088f6da13f26455` and was introduced by commit `766ef97` (PR #8618), whose stated purpose was to block password-only Basic authentication on `/api/web`.
Root Cause
The Basic authentication branch of `AuthenticatedUser` in `internal/context/auth.go:140-163` decides whether to accept Basic credentials from the raw request path:
// Check with basic auth. The web API under "/api/web" serves the browser,
// which signs in with the session, and includes the routes that change
// the credentials and two-factor authentication of an account. A password
// alone, without the second factor, must not reach them.
baHead := r.Header.Get("Authorization")
if len(baHead) > 0 && !strings.HasPrefix(r.URL.Path, "/api/web/") {The prefix test is the only barrier. Gogs uses `github.com/flamego/flamego v1.14.0` (`go.mod:17`). Its router first tries an exact lookup on `req.URL.Path` (`router.go:492-500`), then falls back to `routeTree.Match(req.URL.Path, req)` (`router.go:509`). Every route, static routes included, is also registered in the route tree (`router.go:283-289`).
`internal/route/tree.go:570-571` in v1.14.0 begins with:
func (t *baseTree) Match(path string, req *http.Request) (Leaf, Params, bool) {
path = strings.TrimLeft(path, "/")So a request to `//api/web/user/settings/two-factor` fails the exact static lookup, is trimmed to `api/web/user/settings/two-factor`, and matches the same handler as `/api/web/user/settings/two-factor`. The `r.URL.Path` seen by the authentication check is still `//api/web/user/settings/two-factor`, which does not start with `/api/web/`, so the Basic authentication branch runs and accepts the password.
The same mismatch appears with a percent-encoded slash. A request to `/%2Fapi/web/user/settings/two-factor` is decoded by Go to `//api/web/...` in `r.URL.Path`, so the prefix test fails again, while the router trims the decoded duplicate slash and matches the route. The percent-encoded form also survives proxies that merge literal duplicate slashes, because the duplicate only appears after decoding.
Once authenticated, `DELETE /api/web/user/settings/two-factor` reaches `deleteUserTwoFactor` (`cmd/gogs/internal/web/webapi_user_credentials.go:290-299`). That handler verifies only that the viewer is authenticated and that two-factor authentication is enabled. It does not ask for the account password or a current passcode before deleting the second factor.
Prerequisites
- The target account has two-factor authentication enabled.
- The attacker knows the account password but not the second factor.
- The attacker has network access to the Gogs instance. No session is needed.
- The instance runs a build that contains commit `766ef97` and this authentication code, including current `main` at `4816842`.
- The test was performed on SQLite, PHP-independent Go code, so the database backend does not affect the result.
- A reverse proxy that merges duplicate slashes before forwarding blocks the literal `//` form. The `/%2F...` form still reaches the application as `//...` after Go decodes the path. Direct access to Gogs is not affected by proxy behavior.
No victim interaction is required.
Steps to Reproduce
- Build the image from the source tree at commit `4816842`:
- Create `app.ini` with `TYPE = sqlite3`, `INSTALL_LOCK = true`, `DISABLE_REGISTRATION = false`, and `ENABLE_REGISTRATION_CAPTCHA = false`.
- Start the server with `command: ["/app/gogs/gogs", "web"]` and mount the data volume at `/data`.
- Create the first account through `POST /api/web/user/sign-up` with `{"userName":"labadmin","email":"labadmin@lab.local","password":"Lab-Passw0rd-9x"}`. The first account becomes the site administrator.
- Sign in with `POST /api/web/user/sign-in` using the password. The response sets a session cookie.
- Call `GET /api/web/user/settings/two-factor/enrollment` with that session. The response returns a TOTP `secret`.
- Compute the current six-digit TOTP code for the secret and call `POST /api/web/user/settings/two-factor` with `{"passcode":"<code>"}`. The response is 204 and two-factor authentication is now enabled.
- Control: call `GET /api/web/user/settings/two-factor` with `Authorization: Basic base64(labadmin:Lab-Passw0rd-9x)`. The response is 401.
- Control: call `POST /api/web/user/sign-in` with only the password. The response is 200 with `{"mfa":true}` and no authenticated session.
- Bypass: call `GET //api/web/user/settings/two-factor` with the same Basic header. The response is 200 with `{"enabled":true}`. The percent-encoded form `GET /%2Fapi/web/user/settings/two-factor` also returns 200.
- Exploit: call `DELETE //api/web/user/settings/two-factor` with the same Basic header and `Content-Type: application/json`. The response is 204.
- Verify: call `GET //api/web/user/settings/two-factor` again. The response is 200 with `{"enabled":false}`.
- Verify: call `POST /api/web/user/sign-in` with only the password. The response is 200 without `mfa`, and the session can read `GET /api/web/admin/dashboard` with 200.
The client used for these steps is poc.py https://github.com/user-attachments/files/34987263/2026-11-17_poc.py. It uses Python's `http.client` so the request path is sent exactly as written, including the duplicate slash and the percent-encoded slash.
Impact
Confidentiality and integrity of the account are fully exposed once the password is known.
- The second factor is removed, so the control that exists to protect against a leaked or reused password stops working for that account. This matches the class and consequence of the published Gogs recovery-code bypass (CVE-2025-64175), which is rated High.
- All recovery codes of the account can be read through `//api/web/user/settings/two-factor/recovery-codes` with the password only. The reviewer used one code at `POST /api/web/user/mfa/recovery` and obtained a fully authenticated session while two-factor authentication stayed enabled.
- The web API routes that change the account password are reachable in the same way. The password change handler asks for the current password, which the attacker already has. The reviewer changed the password on a third account and then signed in with the new password.
- On an administrator account, the attacker reaches the admin routes with the password only while two-factor authentication is enabled. The reviewer read `/api/web/admin/dashboard`, `/api/web/admin/users` including email addresses, `/api/web/admin/repos`, and `/api/web/admin/config`.
- The behavior is the same on a non-admin account. The reviewer disabled two-factor authentication and then signed in with the password only on `revuser`.
- The same password also mints an access token through `POST /api/v1/users/<user>/tokens` with Basic authentication, which returned 201 in the lab. PR #8618 states that API v1 still accepts Basic authentication by design, so that result is recorded as an additional path and not the core claim. The token gives persistent API access without the second factor.
The demonstrated impact is a full account takeover, including administrator accounts. The attack does not require a session, user interaction, or a valid second factor. It does require knowledge of the account password. It does not by itself give code execution on the server; it gives the rights of the compromised account.
The behavior is reachable in the default direct-listening configuration. A reverse proxy that merges duplicate literal slashes before forwarding blocks the `//` form. The `/%2F` form still reaches the application as `//` after Go decodes the path, so a filter that only normalizes literal double slashes is not enough. The exact proxy behavior was not tested.
Expected Result
A request that authenticates with only a password must be rejected for the `/api/web` routes no matter how the request path is written. The server should return 401 and leave two-factor authentication enabled. The router should not accept a non-canonical path as equivalent to `/api/web/...` for an authentication decision.
Suggested Fix
The reliable fix is to stop using the raw request path as the security boundary. After `store.AuthenticateUser` succeeds in `internal/context/auth.go`, check the account's two-factor state and refuse Basic authentication for any account that has it enabled. The store already exposes `IsTwoFactorEnabled` and both the Git HTTP and LFS handlers use it. That closes the bypass for every path form and also closes the password-to-token path through API v1.
As a second layer, reject non-canonical request paths before authentication. For example, reject a path where `r.URL.Path != "/" + strings.TrimLeft(r.URL.Path, "/")` with 400, or use the matched route pattern rather than `r.URL.Path` for the `/api/web/` decision. Do the same for any other security decision that currently compares a path prefix.
Add regression tests that use `//api/web/...`, `///api/web/...`, `/%2Fapi/web/...`, and a normal `/api/web/...` path against `AuthenticatedUser`, and an end-to-end test that enables two-factor authentication and confirms the DELETE handler cannot be reached with Basic credentials in any of those forms.
References
- Gogs commit `4816842955f4b49e0dc510b5c088f6da13f26455`, main on 2026-11-17.
- Gogs PR #8618 and commit `766ef97`, which added the `/api/web` Basic authentication restriction.
- `internal/context/auth.go:140-163`, the prefix check.
- `cmd/gogs/internal/web/webapi_user_credentials.go:290-299`, the DELETE handler.
- `internal/context/auth_test.go:115-143`, the unit tests that cover only canonical paths.
- Flamego v1.14.0 `router.go:283-289`, `router.go:492-514`, and `internal/route/tree.go:570-571`.
- GHSA-p6x6-9mx6-26wj / CVE-2025-64175, the earlier Gogs two-factor bypass via recovery codes, rated High.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Versiones afectadas
0.15.0+devEstado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
gogogs.io/gogs |
Sin parche | — | — | v0.13.3 no afectada |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/gogs/gogs/security/advisories/GHSA-f9vc-qvc8-p7cfLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
