mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
GHSA-4734-8vrg-8j3w. A board admin can refuse a role write access in one list (#4527, list.roleExceptions). The card and comment REST routes and the DDP checklist writes applied that refusal; the six checklist and checklist-item REST routes asked only the board, so a member the list refused still created, renamed, ticked and deleted its cards' checklists and items with an API token. They now call assertListNotRefused with the card's list, as the card routes do, and answer 403. The refusal is recorded in Admin Panel -> Problems as ListLockBleed (authz.list-locked, medium: recorded, never disables the account): no screen offers such a write, so it is the lock being stepped round. The card routes' refusals are recorded through the same gate. tests/listPermissions.test.cjs scans every REST write route of the tree that names a card and fails on one that does not ask the list - not only the per-list card routes it checked before - naming the three that follow their own rule (a comment's edit and deletion, dependency lines, a bot run's report), and checks the refusal is recorded. It fails on the old routes. tests/playwright/specs/list-lock-checklists.e2e.js refuses all six writes in a locked list with 403, leaves the checklist and item untouched, records the attempt, and still lets the same member write in an open list and the board admin in the locked one. Thanks to tsurutanmen and xet7 !
297 lines
11 KiB
JavaScript
297 lines
11 KiB
JavaScript
import { parseDueAt } from '/server/lib/checklistDeadlines';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { WebApp } from 'meteor/webapp';
|
|
import { Authentication } from '/server/authentication';
|
|
import { sendJsonResult } from '/server/apiMiddleware';
|
|
import { assertListNotRefused } from '/server/lib/listPermissionGate';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import ChecklistItems, {
|
|
itemCreation,
|
|
itemRemover,
|
|
publishCheckActivity,
|
|
publishChekListCompleted,
|
|
publishChekListUncompleted,
|
|
} from '/models/checklistItems';
|
|
import Activities from '/models/activities';
|
|
import { ensureIndex } from '/server/lib/mongoStartup';
|
|
import { backfillBoardIdFromCard } from '/server/lib/denormalizeBoardId';
|
|
const { deferSyncItemRecording, deferSyncChecklistRecording } = require('/server/lib/syncRecordingScope');
|
|
|
|
// --- Denormalized boardId (see models/checklistItems.js schema) -------------
|
|
// Set boardId from the card on insert, and re-sync it whenever the item is
|
|
// moved to another card (its move helper sets a new cardId), so the board
|
|
// publication can filter checklist items with a single reactive cursor on
|
|
// boardId and still see items on newly added cards. Server-authoritative.
|
|
// #6813: ALWAYS from the card, not only when missing - a client's own boardId
|
|
// would otherwise stay, and a document on its own card could carry another
|
|
// board's id (published to that board, and mistaken for being on it).
|
|
ChecklistItems.before.insert(async (userId, doc) => {
|
|
if (doc.cardId) {
|
|
const card = await ReactiveCache.getCard(doc.cardId);
|
|
if (card) {
|
|
doc.boardId = card.boardId;
|
|
}
|
|
}
|
|
});
|
|
|
|
ChecklistItems.before.update(async (userId, doc, fieldNames, modifier) => {
|
|
const newCardId = modifier && modifier.$set && modifier.$set.cardId;
|
|
if (newCardId && newCardId !== doc.cardId) {
|
|
const card = await ReactiveCache.getCard(newCardId);
|
|
if (card) {
|
|
modifier.$set.boardId = card.boardId;
|
|
}
|
|
}
|
|
});
|
|
|
|
Meteor.startup(async () => {
|
|
await ensureIndex(ChecklistItems, { modifiedAt: -1 });
|
|
await ensureIndex(ChecklistItems, { updatedAt: 1, deleted: 1 });
|
|
await ensureIndex(ChecklistItems, { checklistId: 1 });
|
|
await ensureIndex(ChecklistItems, { cardId: 1 });
|
|
await ensureIndex(ChecklistItems, { boardId: 1 });
|
|
// Backfill existing rows in the background (memory-safe, idempotent).
|
|
Meteor.defer(() => {
|
|
backfillBoardIdFromCard(ChecklistItems, { label: 'checklistItems' });
|
|
});
|
|
});
|
|
|
|
// A durable rule checklist action writes these from its saved plan
|
|
// (server/lib/syncRuleChecklistCommand.js), never both.
|
|
ChecklistItems.after.update(async (userId, doc, fieldNames) => {
|
|
if (deferSyncItemRecording('itemCheck', doc)) return;
|
|
await publishCheckActivity(userId, doc);
|
|
await publishChekListCompleted(userId, doc, fieldNames);
|
|
});
|
|
|
|
ChecklistItems.before.update(async (userId, doc, fieldNames) => {
|
|
if (deferSyncItemRecording('itemUncomplete', doc)) return;
|
|
await publishChekListUncompleted(userId, doc, fieldNames);
|
|
});
|
|
|
|
ChecklistItems.after.insert(async (userId, doc) => {
|
|
// A durable rule addChecklistWithItems writes this activity from its plan.
|
|
if (deferSyncChecklistRecording('checklistItemActivity', doc)) return;
|
|
await itemCreation(userId, doc);
|
|
});
|
|
|
|
ChecklistItems.before.remove(async (userId, doc) => {
|
|
try {
|
|
await itemRemover(userId, doc);
|
|
// When a whole list/card is deleted, the parent card may already be gone
|
|
// by the time its checklist items are removed (cascade delete). Skip the
|
|
// activity then instead of dereferencing an undefined card, which would
|
|
// throw an unhandled rejection and crash SyncedCron.
|
|
const card = await ReactiveCache.getCard(doc.cardId);
|
|
if (!card) {
|
|
console.warn('[ChecklistItems.before.remove] Card not found for cardId:', doc.cardId, '— skipping removedChecklistItem activity.');
|
|
return;
|
|
}
|
|
await Activities.insertAsync({
|
|
userId,
|
|
activityType: 'removedChecklistItem',
|
|
cardId: doc.cardId,
|
|
boardId: card.boardId,
|
|
checklistId: doc.checklistId,
|
|
checklistItemId: doc._id,
|
|
checklistItemName: doc.title,
|
|
listId: card.listId,
|
|
swimlaneId: card.swimlaneId,
|
|
});
|
|
} catch (e) {
|
|
console.error('[ChecklistItems.before.remove] Error while processing checklist item deletion for doc._id:', doc._id, e);
|
|
}
|
|
});
|
|
|
|
WebApp.handlers.get(
|
|
'/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items/:itemId',
|
|
async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramCardId = req.params.cardId;
|
|
const paramChecklistId = req.params.checklistId;
|
|
const paramItemId = req.params.itemId;
|
|
await Authentication.checkBoardAccess(req.userId, paramBoardId);
|
|
const checklistItem = await ReactiveCache.getChecklistItem(paramItemId);
|
|
if (checklistItem && checklistItem.cardId === paramCardId && checklistItem.checklistId === paramChecklistId) {
|
|
const card = await ReactiveCache.getCard(checklistItem.cardId);
|
|
if (card && card.boardId === paramBoardId) {
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: checklistItem,
|
|
});
|
|
} else {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
}
|
|
} else {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
WebApp.handlers.post(
|
|
'/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items',
|
|
async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramChecklistId = req.params.checklistId;
|
|
const paramCardId = req.params.cardId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
const checklist = await ReactiveCache.getChecklist({
|
|
_id: paramChecklistId,
|
|
cardId: paramCardId,
|
|
});
|
|
if (checklist) {
|
|
const card = await ReactiveCache.getCard(paramCardId);
|
|
if (card && card.boardId === paramBoardId) {
|
|
// ListLockBleed (GHSA-4734-8vrg-8j3w): the list's refusal holds over REST too (#4527).
|
|
await assertListNotRefused(req.userId, await ReactiveCache.getBoard(paramBoardId), card.listId, 'write', 'rest:checklist-item');
|
|
// Append, like the UI does. Every item created over REST used to be given
|
|
// `sort: 0`, so a checklist filled through the API came out in an order
|
|
// nobody chose - and every item after the first shared the first one's
|
|
// position. An explicit `sort` in the body still wins, for a caller that
|
|
// is rebuilding a checklist in a known order (#6544).
|
|
let sort = Number(req.body.sort);
|
|
if (!Number.isFinite(sort)) {
|
|
const last = await ReactiveCache.getChecklistItems(
|
|
{ checklistId: paramChecklistId },
|
|
{ sort: { sort: -1 }, limit: 1 },
|
|
);
|
|
sort = last && last.length && Number.isFinite(last[0].sort) ? last[0].sort + 1 : 0;
|
|
}
|
|
|
|
const deadline = parseDueAt(req.body);
|
|
if (deadline.error) {
|
|
sendJsonResult(res, { code: 400, data: { error: deadline.error } });
|
|
return;
|
|
}
|
|
const id = await ChecklistItems.insertAsync({
|
|
cardId: paramCardId,
|
|
checklistId: paramChecklistId,
|
|
title: req.body.title,
|
|
...(deadline.dueAt ? { dueAt: deadline.dueAt } : {}),
|
|
isFinished: false,
|
|
sort,
|
|
});
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: {
|
|
_id: id,
|
|
},
|
|
});
|
|
} else {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
}
|
|
} else {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
WebApp.handlers.put(
|
|
'/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items/:itemId',
|
|
async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramCardId = req.params.cardId;
|
|
const paramChecklistId = req.params.checklistId;
|
|
const paramItemId = req.params.itemId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
|
|
const checklistItem = await ReactiveCache.getChecklistItem(paramItemId);
|
|
if (!checklistItem || checklistItem.cardId !== paramCardId || checklistItem.checklistId !== paramChecklistId) {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
return;
|
|
}
|
|
const card = await ReactiveCache.getCard(checklistItem.cardId);
|
|
if (!card || card.boardId !== paramBoardId) {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
return;
|
|
}
|
|
// ListLockBleed (GHSA-4734-8vrg-8j3w): the list's refusal holds over REST too (#4527).
|
|
await assertListNotRefused(req.userId, await ReactiveCache.getBoard(paramBoardId), card.listId, 'write', 'rest:checklist-item');
|
|
|
|
const deadline = parseDueAt(req.body);
|
|
if (deadline.error) {
|
|
sendJsonResult(res, { code: 400, data: { error: deadline.error } });
|
|
return;
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(deadline, 'dueAt')) {
|
|
await ChecklistItems.direct.updateAsync({ _id: paramItemId },
|
|
deadline.dueAt === null ? { $unset: { dueAt: '' } } : { $set: { dueAt: deadline.dueAt } });
|
|
}
|
|
function isTrue(data) {
|
|
try {
|
|
return data.toLowerCase() === 'true';
|
|
} catch (error) {
|
|
return data;
|
|
}
|
|
}
|
|
|
|
if (req.body.hasOwnProperty('isFinished')) {
|
|
await ChecklistItems.direct.updateAsync(
|
|
{ _id: paramItemId },
|
|
{ $set: { isFinished: isTrue(req.body.isFinished) } },
|
|
);
|
|
}
|
|
if (req.body.hasOwnProperty('title')) {
|
|
await ChecklistItems.direct.updateAsync(
|
|
{ _id: paramItemId },
|
|
{ $set: { title: req.body.title } },
|
|
);
|
|
}
|
|
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: {
|
|
_id: paramItemId,
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
WebApp.handlers.delete(
|
|
'/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items/:itemId',
|
|
async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramCardId = req.params.cardId;
|
|
const paramChecklistId = req.params.checklistId;
|
|
const paramItemId = req.params.itemId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
|
|
const checklistItem = await ReactiveCache.getChecklistItem(paramItemId);
|
|
if (!checklistItem || checklistItem.cardId !== paramCardId || checklistItem.checklistId !== paramChecklistId) {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
return;
|
|
}
|
|
const card = await ReactiveCache.getCard(checklistItem.cardId);
|
|
if (!card || card.boardId !== paramBoardId) {
|
|
sendJsonResult(res, {
|
|
code: 404,
|
|
});
|
|
return;
|
|
}
|
|
// ListLockBleed (GHSA-4734-8vrg-8j3w): the list's refusal holds over REST too (#4527).
|
|
await assertListNotRefused(req.userId, await ReactiveCache.getBoard(paramBoardId), card.listId, 'write', 'rest:checklist-item');
|
|
|
|
await ChecklistItems.direct.removeAsync({ _id: paramItemId });
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: {
|
|
_id: paramItemId,
|
|
},
|
|
});
|
|
},
|
|
);
|