mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
GHSA-3vjg-3p4q-8fwh. The REST card DELETE looked the card up on the board the caller was authorised for, destroyed its checklists, checklist items, comments, attachments and subcards by cardId, and removed the card itself last, keyed on that board and list. A move to another board landing in between left the card alive on a board the deleter cannot read, stripped of every child, with both requests answering 200 (CWE-367). Every hooked removal had the same shape: collection-hooks runs Cards.before.remove (where the cascade was) and then removes by the caller's original selector - by swimlane, delete batch or parent - which a moved card no longer matches. The custom-field link clean-up did the same to the cards linked to it. The card document is now the claim (models/lib/claimedCardRemoval.js): the single and bulk REST deletes remove the card first and cascade only when that removal matched, and the hooked removals cascade from Cards.after.remove only when the card is really gone. A list deletion removes a card only while it is still in that list. The REST board move that loses to a delete is a 404 instead of a 500 from cardMove. A delete that lost the race, or arrived after the card was moved away from the named board, is refused and recorded in Admin Panel / Problems as RaceBleed (authz.card-delete-race, medium, never disables the account): a stale view is not an attack, and PurgeBleed's critical record used to disable the member who deleted a card somebody had just moved. tests/claimedCardRemoval.test.cjs replays the reported race and scans server/ for any cascade before or without the card's removal; tests/playwright/specs/race-bleed.e2e.js races 12 moves against deletes and checks that a surviving card always keeps its checklist. Thanks to xingmuse and xet7 !
47 lines
2.3 KiB
JavaScript
47 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
// RaceBleed (GHSA-3vjg-3p4q-8fwh): a card's children are destroyed only for a
|
|
// card whose own removal really happened.
|
|
//
|
|
// Deleting a card used to destroy its checklists, checklist items, comments,
|
|
// attachments and subcards FIRST and remove the card itself LAST, keyed on the
|
|
// board (and list) the caller was authorised for. Nothing held the card still
|
|
// in between, so a move to another board that landed in that window left the
|
|
// card alive on a board the deleter could not even read, stripped of all its
|
|
// children - irreversibly, with both requests answering 200. Every hooked
|
|
// removal had the same shape: matb33:collection-hooks fetches the documents,
|
|
// runs Cards.before.remove (where the cascade was) and only then removes by the
|
|
// ORIGINAL selector, which a moved card no longer matches.
|
|
//
|
|
// The card document is the claim. Removing it is atomic and keyed on where the
|
|
// caller was authorised, so exactly one of "the move" and "the delete" wins:
|
|
// once it is gone a concurrent move matches nothing, and when the move won the
|
|
// removal matches nothing and nothing else is touched.
|
|
//
|
|
// Pure: callers pass the collection operations in, so the race is testable as
|
|
// arithmetic (tests/claimedCardRemoval.test.cjs).
|
|
|
|
// Remove `card` where `selector` still says it is, and only then its children.
|
|
// `removeCard(selector)` returns how many documents it removed; `cascade(card)`
|
|
// destroys the children. Returns whether the card was removed.
|
|
async function removeClaimedCard({ card, selector, removeCard, cascade }) {
|
|
if (!card || typeof card._id !== 'string' || !card._id) return false;
|
|
const removed = await removeCard({ ...(selector || {}), _id: card._id });
|
|
if (!removed) return false;
|
|
await cascade(card);
|
|
return true;
|
|
}
|
|
|
|
// For Cards.after.remove: collection-hooks calls it for every document it
|
|
// fetched before the removal, matched or not, so the cascade runs only when the
|
|
// card is really gone. `exists(id)` reports whether a card with that id is still
|
|
// stored. Returns whether the cascade ran.
|
|
async function cascadeIfRemoved({ doc, exists, cascade }) {
|
|
if (!doc || typeof doc._id !== 'string' || !doc._id) return false;
|
|
if (await exists(doc._id)) return false;
|
|
await cascade(doc);
|
|
return true;
|
|
}
|
|
|
|
module.exports = { removeClaimedCard, cascadeIfRemoved };
|