GHSA-Q47M-RVR6-JQW7
copy_folder writes into folders the caller cannot access and copies restricted items; the API item move ignores the no-delete (ND) right
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-Q47M-RVR6-JQW7 divulgada · CVSS 6.3 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Maintainer assessment
Verified against the development branch. Fixed in 3.2.2.5.
Issue A — confirmed, impact corrected. `copy_folder` only rejected a target listed in the caller's read-only folders, and the "personal" flag that satisfies the creation gate was read from any folder row. Any authenticated, non-read-only user could therefore create folders (and copies of items they can already read) inside another user's personal tree — or, when *users can create folders* is enabled or the caller is a manager, inside a shared folder they cannot see. The impact is on integrity only: the planted items get no sharekey for the tree's owner, and nothing the owner stores afterwards becomes readable by the attacker (personal items are encrypted for their owner only). Fix: the target must be one of the caller's accessible folders.
Issue B — the source-side half is confirmed; the destination-side half is aligned as hardening.
`PUT /api/v1/item/update` never required the delete right on the item's current folder, so a user holding the `ND` (no delete) level could move items out of it — which the web interface refuses. Moving a shared item into the caller's own personal folder also removed every other user's encryption keys on it. Writing content while moving into an `NE` folder did not cross a boundary on its own (`NE` grants item creation and no item already stored there is modified), but the API now applies the web rule on both sides: a move requires the delete right on the source folder and the edit right on the target folder.
Issue C — found while triaging this report. `copy_folder` also copied items the caller had been restricted from (per-item user or role restriction). Items are decrypted server-side and the copy carries no restriction, so the caller obtained a readable copy of a password the item card refuses to show. Fix: items the caller is restricted from are no longer copied.
---
Follow-up sibling sweep after GHSA-vxv5-cr34-5q7g (`update_item`'s move check computed against
the wrong folder). Two more instances of the same family — "an authorization check for a move/copy
operation is computed against only one side (source or destination), or the wrong side, of the
operation" — found in code GHSA-vxv5 does not touch.
## Issue A (more severe) -- `copy_folder` (`app/sources/folders.queries.php:1194`) lets any
non-read-only user graft folders and items into any other user's personal folder tree, with no
accessibility check on the destination at all, and permanently retains a decryption key for the
copies
The destination-folder gate only rejects a folder the caller marked read-only -- it never checks
that the destination is even in the caller's accessible folders:
// line 1241-1252
// Test if target folder is Read-only
if (in_array($post_target_folder_id, $session->get('user-read_only_folders')) === true) {
... reject ...
}
// line 1254-1284
$dataParent = DB::queryFirstRow(
'SELECT personal_folder FROM ' . prefixTable('nested_tree') . ' WHERE id = %i',
$post_target_folder_id
);
$isPersonal = (isset($dataParent['personal_folder']) === true && (int) $dataParent['personal_folder'] === 1) ? 1 : 0;
if (!(
(int) $isPersonal === 1 // <-- true for ANY user's personal folder
|| (int) $session->get('user-admin') === 1
|| (int) $session->get('user-manager') === 1
|| (int) $session->get('user-can_manage_all_users') === 1
|| (isset($SETTINGS['enable_user_can_create_folders']) === true && ... == 1)
|| (int) $session->get('user-can_create_root_folder') === 1
)) {
... reject ...
}`user-read_only_folders` is a subset of `user-accessible_folders` (both built from the same merge
in `main.functions.php:955-959`), so a folder the caller cannot see at all is *not* in
`read_only_folders` either -- the first check silently passes. And `$isPersonal` is read from the
raw DB row of *any* folder in the instance, not scoped to the caller in any way -- so whenever
`$post_target_folder_id` happens to be a personal folder (root or subfolder) belonging to **any
other user, the entire allow-gate is satisfied with zero privilege required**. Contrast with
`FolderModel::createFolder()`'s API equivalent, which explicitly calls
`isFolderInsideAllowedPersonalRoot()` to exclude other users' personal trees.
The write (line 1331-1342) then creates the folder directly under the attacker-supplied
`$post_target_folder_id`:
DB::insert(prefixTable('nested_tree'), array(
'parent_id' => $parentId, // == $post_target_folder_id for the first level
'title' => ...,
'personal_folder' => $nodeInfo->personal_folder, // forced to $isPersonal, i.e. 1
...
));Each copied item then gets a sharekey minted for the attacker's own account, unconditionally
(line 1524-1538):
insertOrUpdateSharekey(
prefixTable('sharekeys_items'),
(int) $newItemId,
(int) $session->get('user-id'), // the attacker, not the folder's real owner
encryptUserObjectKey($cryptedStuff['objectKey'], $session->get('user-public_key'))
);
if ((int) $nodeInfo->personal_folder !== 1 && (int) $session->get('user-id') !== (int) TP_USER_ID) {
insertOrUpdateSharekey(prefixTable('sharekeys_items'), (int) $newItemId, (int) TP_USER_ID, ...);
}Only the *second* (`TP_USER`) sharekey is skipped for a personal target -- the attacker's own key
is always written. I did not find anywhere in this code path that also grants a sharekey to the
personal folder's real owner, which would mean the victim's own vault gains an item they cannot
decrypt while the attacker who planted it can.
The caller's own session is updated to include the new folder inside the victim's tree
(line 1360-1364):
$session->set('user-accessible_folders', array_unique(array_merge($session->get('user-accessible_folders'), [$newFolderId]), SORT_NUMERIC));
if ((int) $nodeInfo->personal_folder === 1) {
SessionManager::addRemoveFromSessionArray('user-personal_folders', [$newFolderId], 'add');
SessionManager::addRemoveFromSessionArray('user-personal_visible_folders', [$newFolderId], 'add');
}Impact: any authenticated, non-read-only user can call `copy_folder` with `target_folder_id`
set to any folder ID that happens to be `personal_folder=1` -- root or subfolder, belonging to
anyone -- and (a) graft new folder(s) plus copied items into that victim's personal tree with no
accessibility check on the destination whatsoever, and (b) retain a durable `sharekeys_items` row
letting them decrypt the copies indefinitely, inside a tree the victim believes is private to them.
## Issue B -- `PUT /api/v1/item/update` checks the wrong side (or the wrong permission) when a
folder move is combined with a content edit
Confirmed correct reference model, from the web's already-fixed siblings (`move_item` /
`mass_move_items` in `app/sources/items.queries.php`): a move needs delete right on the source
folder and edit right on the destination folder, checked independently.
`ItemController::updateAction()` (line 1154) checks only the *source* folder, and only for *edit*,
before it's even known whether the request is a move:
} elseif ($folderAccessModel->canEditInFolder((int) $itemInfo['id_tree'], (int) $userData['id']) === false) {
// Blocks R (read-only) as well as NE / NDNE (no edit)`canEditInFolder()` returns `true` for access type `ND` (create=true, edit=true, delete=false)
-- so a user with only `ND` on the source folder (explicitly no delete right) passes this gate and
can move an item out of that folder, which the correct delete-right check would refuse.
`canDeleteInFolder()` exists in `FolderAccessModel.php:411` but is never called anywhere on this
update/move path (only in the separate delete endpoint).
For the destination, `ItemModel::updateItem()` (line 1805-1819) checks only:
if ($folderAccessModel->canUseFolder($userData, $newFolderId) === false) { ... 403 ... }
if ($folderAccessModel->isFolderReadOnlyForUser($newFolderId, (int) $userData['id'])) { ... 403 ... }`isFolderReadOnlyForUser()` only blocks access type `R`; type `NE` (create=true, edit=false,
delete=true) passes both checks. This is a documented, intentional choice for the *move itself*
(the destination only needs "creation" semantics per the repo's own API reference doc) -- the gap
is that a single `PUT /item/update` can combine `folder_id` with a content field (`password`,
`label`, etc.) in the same request for every transition except personal-to-shared, which is the
only transition explicitly guarded against combination (line 1827-1851,
`conflictingUpdateFields`). For every other transition (shared-to-shared, shared-to-personal,
personal-to-personal), execution falls to:
// line 1904-1906
} else {
$updateData['id_tree'] = $newFolderId;
$updateData['perso'] = (int) $targetItemInfos['personal_folder'];and the password-handling block later in the same function (confirmed by reading to the final
`DB::update(prefixTable('items'), $updateData, ...)` call) merges straight into the same
`$updateData` array with no further `canEditInFolder($newFolderId, ...)` call anywhere on this
path.
Impact: a user with `NE` (no-edit) rights on folder B, but ordinary edit rights on folder A
where they own/can-edit an item, can send one `PUT /api/v1/item/update?id=<item>` with
`{"folder_id": B, "password": "..."}` and write a new password into folder B in the same request,
bypassing B's no-edit restriction -- the edit-right check that ran (`canEditInFolder`) was
evaluated against A, the source folder, not B, the folder actually being written to.
What I did and did not verify
I read every line quoted above directly from the current `nilsteampassnet/TeamPass` `master`
(`folders.queries.php`, `ItemController.php::updateAction`, `ItemModel.php::updateItem`,
`FolderAccessModel.php`), confirmed `user-read_only_folders ⊆ user-accessible_folders` from
`main.functions.php:955-959`, and confirmed the correct two-sided pattern in `move_item` /
`mass_move_items` as the reference. I have not stood up a live instance with two provisioned users
to capture an actual cross-user personal-folder graft or a cross-folder password write -- these are
logic-level findings traced from source, not captured exploits. For Issue A specifically, I did not
confirm whether the personal folder's real owner ever receives a sharekey for the attacker-planted
item (i.e., whether the item becomes visible-but-undecryptable to the victim, or entirely
undiscoverable without inspecting `nested_tree` directly) -- flagging this as an open question for
your own follow-up rather than asserting it.
Suggested fix
Issue A: before creating anything under `$post_target_folder_id`, require it to be in
`user-accessible_folders` (not merely absent from `user-read_only_folders`), and require
`isFolderInsideAllowedPersonalRoot()`-equivalent scoping so `$isPersonal` can only be true for the
*caller's own* personal tree, mirroring `FolderModel::createFolder()`'s API-side check.
Issue B: in `ItemController::updateAction()`, use `canDeleteInFolder()` on the source folder
instead of `canEditInFolder()` when the request includes a `folder_id` different from the item's
current one; in `ItemModel::updateItem()`, add a `canEditInFolder($newFolderId, ...)` check in the
non-personal-to-shared branch (mirroring the existing `isFolderReadOnlyForUser` call) before
allowing any other field to be written in the same request.
Regards,
kta1kri
https://github.com/kta1kri
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 |
|---|---|---|---|---|
Packagistnilsteampassnet/teampass |
Sin parche | — | — | — |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/nilsteampassnet/TeamPass/security/advisories/GHSA-q47m-rvr6-jqw7Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
