GHSA-J5V7-QCWP-5G32
API token scopes collide between v1 and v2, granting a different verb than intended
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:L
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-J5V7-QCWP-5G32 divulgada · CVSS 5.4 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
API token permission keys are generated separately for the v1 and v2 route tables. Collisions are resolved by registration order, and v1 and v2 register the background routes in opposite orders. The result is:
- In v1, `projects.background` means GET.
- In v2, `projects.background` means DELETE.
`tokenAuthorizesRoute` accepts a key that matches either table, so a token issued only to read a project background can delete it through `/api/v2`. GHSA-v479-vf79-mg83 fixed the same impact on v1.
Buckets collide the same way for a different reason: v1 uses PUT for create and POST for update, v2 uses POST for create and PUT for update. A bucket create-only scope therefore allows updating buckets on the other version.
Reproduced by execution on 2.4.0, 2.7.0 and `main` @ `e7d7f173`. 2.3.0 is not affected (it has no v2 background route).
Details
`pkg/models/api_routes.go`, `CollectRoutesForAPITokenUsage`: `stripAPIVersion` (`:74`) merges v1 and v2 into one permission group, but the routes live in separate maps (`:29/35`). On a key collision, the route registered second gets an `_<method>` suffix (`:316-321`), so the meaning of a non-CRUD key depends on registration order.
- v1 registers GET, then DELETE (`pkg/routes/routes.go:897-898`): `background` = GET, `background_delete` = DELETE.
- `pkg/routes/api/v2/backgrounds.go:50-66` registers DELETE, then GET: `background` = DELETE, `background_get` = GET.
`tokenAuthorizesRoute` checks `[apiTokenRoutes[group], apiTokenRoutesV2[group]]` under the same key (`:475`).
The same collision suffix, combined with the bucket PUT/POST swap (v1 `pkg/routes/routes.go:692-694`: PUT = create, POST = update; v2 `pkg/routes/api/v2/buckets.go:58-68`: POST = create, PUT = update), swaps bucket create and update with write-to-write impact only: `projects.views_buckets_put` (v1 create) authorizes the v2 bucket update, and the reverse also holds.
`getRouteDetail`'s verb inversion is not the cause.
Proof of concept
A token with `{"projects":["background"]}` belongs to a user who has write access to a project that has a background.
GET /api/v1/projects/<id>/background -> 200 (intended)
DELETE /api/v1/projects/<id>/background -> 401 (correct)
DELETE /api/v2/projects/<id>/background -> 200 (background deleted; v1 GET now 404)Controls:
- A `projects.read_one` token on the v2 DELETE returns 401.
- A `projects.background_delete` token on the v2 DELETE returns 401. This is a functional bug too: the key that is meant to allow the delete doesn't work on v2.
With the patch, `projects.background` gets 401 on the v2 DELETE and `projects.background_delete` gets 200.
Executed on the official release binaries v2.4.0 (sha256 `eefc0e31587e0c9d7b18f38d4d50dd1fa03fd5fc6879eb9894ce9909620072ea`) and v2.7.0 (sha256 `569861fd690f9ffc812e39e20be3943b882d4549a19e556e47066e71e29ca1b9`), and on `main` @ `e7d7f173`. Official v2.3.0 (sha256 `c37f8291698e288cd95198b52b826ffca40c3665d351041b93358e142862994d`) is not affected: the v2 background route does not exist there (404). The patch below applies to v2.7.0 and was verified there.
Impact
A token scoped to read a background can permanently delete project backgrounds, which deletes the file and clears `background_file_id`. This is the same impact as GHSA-v479. The bucket swap lets a token scoped to create buckets rename existing buckets and change their limits.
### Fix
Name non-CRUD permission keys by meaning (read/create/update/delete) instead of by registration order or HTTP method, applying the v1/v2 method swap for buckets, so a key means the same operation on both versions. Add a v1/v2 parity test covering backgrounds and buckets.
The reporter's order-independent patch below fixes backgrounds only:
if existing, has := target[routeParts[0]][subkey]; has {
if route.Method == http.MethodGet && existing.Method != http.MethodGet {
target[routeParts[0]][subkey+"_"+strings.ToLower(existing.Method)] = existing
} else {
subkey += "_" + strings.ToLower(route.Method)
}
}For buckets, v1 uses PUT for create while v2 uses POST, so names derived from the HTTP method can't line up. Naming keys by operation covers both cases.
I would appreciate a CVE being requested for this issue.
### Credits
Please credit as: Dylan McGuinness, Ambit Security (finder, reporter).
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
gocode.vikunja.io/api |
Sin parche | — | — | v0.24.6 no afectada |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/go-vikunja/vikunja/security/advisories/GHSA-j5v7-qcwp-5g32Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
