mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
AssignedBleed follow-up, GHSA-r4gm-mjj9-g3x8. An assigned-only member (isNormalAssignedOnly, isCommentAssignedOnly, isReadAssignedOnly, and custom roles through those flags) sees only the cards assigned to them. The Board Email View checked board.isVisibleBy() alone, so it published the title, description and email metadata of every card in a list or label, counted them, and searched them. It now merges assignedOnlyCardScope into its folder and search selector for the page and the count, and a reply on another card is refused. An audit of every path that returns or changes a card found the same shape - "a member of the board, so every card of it" - elsewhere, all fixed here: - reads: the board publication's ancestor cards, linked source cards with their subtasks and dependency targets, and comment reactions; All Boards tile counts; a board's activities from linked boards; the Chat view and the All Boards feed, which also let card MEMBERS through (assignees is the rule); My Attachments' card; GET /api/user/cards; position history of a card; the cross-board subtask picker; Scrum rollover counts; and the notification publications, which kept sending the full documents of cards named in old notifications - also to members removed from the board; - writes on a card the member cannot see: the canonical canEditCardOrLinkedCard / editableCardIds (every Cards.allow update, checklists, items, attachments, text notes, custom fields, the shared description, card methods) now ask the card - the role's `write` is a board answer, and the card is read when a caller passed it without assignees; DDP and REST comments, button rules on a card, checklist moves, issue state, watching, the card-opened webhook, moveBoardObjects, moveSwimlane and attachment moves; - REST writes: checkBoardWriteAccess refuses assigned-only members, as checkBoardAccess already does for reads - those routes act on any card, list or swimlane by id. The GHSA-f396 canary still fires for a role without the write capability. A refusal no view would produce is recorded under AssignedBleed in Admin Panel -> Problems (authz.assigned, medium: never disables); opening a view, searching and REST calls are narrowed or refused without a record. tests/boardRoleViews.test.cjs runs the Email View selector, pins every path above, and fails when any server file that serves card data has no role rule and no stated exemption; the "assignee or card member" rule is rejected anywhere in server/ and models/. server/lib/tests/editableCardIds adds an assigned-only case for both edit checks (meteor test; not run here). Seven guards that pinned the old lines now pin the new ones. Thanks to crypto-nidh, binary-lover and xet7 !
99 lines
7.6 KiB
JavaScript
99 lines
7.6 KiB
JavaScript
'use strict';
|
|
// Hall of Fame regression coverage: CommentBoundaryBleed.
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { commentCardMatchesBoard, recordCommentBoundaryDenial } = require('../models/lib/commentCardBoundary');
|
|
const { hasPrivateCommentWrite } = require('../models/lib/commentPrivateFields');
|
|
const root = path.join(__dirname, '..');
|
|
const read = file => fs.readFileSync(path.join(root, file), 'utf8');
|
|
test('comment boundary accepts the real card board and rejects foreign or missing cards', () => {
|
|
const card = { _id: 'cardB', boardId: 'B' };
|
|
assert.equal(commentCardMatchesBoard(card, 'cardB', 'B'), true);
|
|
for (const args of [[card, 'cardB', 'A'], [card, 'other', 'B'], [null, 'cardB', 'A'], [card, {}, 'B']]) {
|
|
assert.equal(commentCardMatchesBoard(...args), false);
|
|
}
|
|
assert.doesNotThrow(() => recordCommentBoundaryDenial('test'), 'missing logger cannot break denial');
|
|
});
|
|
test('REST attack returns 404 before any insert, while legitimate comments still reach validation', async () => {
|
|
const source = read('server/models/cardComments.js');
|
|
const at = source.indexOf("WebApp.handlers.post('/api/boards/:boardId/cards/:cardId/comments'");
|
|
const start = source.indexOf(' const paramBoardId', at);
|
|
const end = source.indexOf(' // Validate the required', start);
|
|
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
|
|
// GHSA-r4gm-mjj9-g3x8: the card rule is the real one (boardCardScope).
|
|
const { assignedOnlyAllowsCard } = require('../models/lib/boardCardScope');
|
|
const run = new AsyncFunction('req', 'res', 'Authentication', 'ReactiveCache', 'allowIsBoardMemberCommentOnly', 'commentCardMatchesBoard', 'recordCommentBoundaryDenial', 'sendJsonResult', 'canCommentInList', 'assignedOnlyAllowsCard', source.slice(start, end) + '\nreturn "validated-boundary";');
|
|
for (const foreign of [false, true]) {
|
|
const logs = [], responses = [];
|
|
const result = await run({ params: { boardId: 'A', cardId: 'card' }, userId: 'u' }, {},
|
|
{ checkLoggedIn() {}, checkBoardExists() {}, async checkAdminOrCondition() {} },
|
|
{ getBoard: async () => ({}), getCard: async query => ({ _id: query._id, boardId: foreign ? 'B' : query.boardId }) },
|
|
() => true, commentCardMatchesBoard, source => logs.push(source), (res, data) => responses.push(data),
|
|
// #4527: the card's list may allow or refuse commenting; here it allows.
|
|
async () => true, assignedOnlyAllowsCard);
|
|
assert.equal(result, foreign ? undefined : 'validated-boundary');
|
|
assert.equal(logs.length, foreign ? 1 : 0);
|
|
if (foreign) assert.equal(responses[0].code, 404);
|
|
}
|
|
});
|
|
test('DDP insertion and rebinding cannot bypass the boundary', async () => {
|
|
const source = read('server/permissions/cardComments.js');
|
|
const at = source.indexOf('CardComments.deny({');
|
|
let deny;
|
|
// GHSA-r4gm-mjj9-g3x8: an assigned-only member comments only on their cards.
|
|
const { assignedOnlyAllowsCard } = require('../models/lib/boardCardScope');
|
|
const boards = { findOneAsync: async () => ({ _id: 'B', members: [
|
|
{ userId: 'u', isActive: true }, { userId: 'limited', isActive: true, isCommentAssignedOnly: true }] }) };
|
|
new Function('CardComments', 'Cards', 'commentCardMatchesBoard', 'recordCommentBoundaryDenial', 'hasPrivateCommentWrite', 'recordCommentPrivateDenial', 'Boards', 'assignedOnlyAllowsCard', source.slice(at, source.indexOf('CardComments.allow({', at)))(
|
|
{ deny: value => { deny = value; } }, { findOneAsync: async id => ({ _id: id, boardId: 'B', assignees: id === 'own' ? ['limited'] : [] }) }, commentCardMatchesBoard, () => {}, hasPrivateCommentWrite, () => {},
|
|
boards, assignedOnlyAllowsCard);
|
|
assert.equal(await deny.insert('u', { cardId: 'c', boardId: 'A' }), true);
|
|
assert.equal(await deny.insert('u', { cardId: 'c', boardId: 'B' }), false);
|
|
assert.equal(await deny.insert('limited', { cardId: 'c', boardId: 'B' }), true, 'not their card');
|
|
assert.equal(await deny.insert('limited', { cardId: 'own', boardId: 'B' }), false, 'their own card');
|
|
assert.equal(deny.update('u', {}, ['cardId']), true);
|
|
assert.equal(deny.update('u', {}, ['boardId']), true);
|
|
assert.equal(deny.update('u', {}, ['text']), false);
|
|
assert.equal(await deny.insert('u', { cardId: 'c', boardId: 'B', webhookResponseRevision: 'forged' }), true);
|
|
assert.equal(deny.update('u', {}, ['text'], { $rename: { text: 'webhookResponseRevision' } }), true);
|
|
});
|
|
test('negative: every externally supplied REST comment insert is preceded by the card boundary', () => {
|
|
const walk = dir => fs.readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
|
|
const file = path.join(dir, entry.name);
|
|
return entry.isDirectory() ? walk(file) : file.endsWith('.js') ? [file] : [];
|
|
});
|
|
const paths = walk(path.join(root, 'server')).filter(file => /CardComments\.(?:direct\.)?insertAsync\(/.test(fs.readFileSync(file, 'utf8')));
|
|
assert.deepEqual(paths.map(file => path.relative(root, file)).sort(),
|
|
['server/bots.js', 'server/emailToCard.js', 'server/lib/listSyncIssueDetails.js', 'server/models/cardComments.js', 'server/routes/inboundEmail.js',
|
|
'server/rulesHelper.js']);
|
|
// A reply or an answer to a bot is a comment on the run's own card, by a
|
|
// board admin who may comment in that list, with the card's own board id.
|
|
const bots = read('server/bots.js');
|
|
assert.match(bots, /if \(!card \|\| !\(await canCommentInList\(userId, board, card\.listId\)\)\) throw new Meteor\.Error\('not-authorized'\);\s*const commentId = await CardComments\.insertAsync\(\{ text, boardId: card\.boardId, cardId: card\._id, userId \}\);/);
|
|
// A rule's "add comment" writes on the card the rule ran for, with that
|
|
// card's own board id, as a person who may comment there.
|
|
const rulesHelper = read('server/rulesHelper.js');
|
|
assert.match(rulesHelper, /const board = await ReactiveCache\.getBoard\(card\.boardId\);[\s\S]{0,120}memberCan\(board, authorId, 'comment'\)[\s\S]{0,40}CardComments\.insertAsync\(\{ text: text\.slice\(0, 65536\), boardId: card\.boardId, cardId: card\._id,/);
|
|
// List sync's issue comments go only onto cards found ON the synced list's
|
|
// own board and list, and are written with that board's id - the tracker
|
|
// never names a card.
|
|
const issueDetails = read('server/lib/listSyncIssueDetails.js');
|
|
assert.match(issueDetails, /Cards\.find\(\{\s*boardId: list\.boardId, listId: list\._id, syncSourceKey: sourceKey,/);
|
|
assert.match(issueDetails, /CardComments\.insertAsync\(\{\s*boardId: list\.boardId, cardId: card\._id,/);
|
|
// #794: an emailed reply is a comment on a card found ON the board of the
|
|
// address it was sent to, by a member with write access there - the card is
|
|
// never named by the sender.
|
|
const emailToCard = read('server/emailToCard.js');
|
|
assert.match(emailToCard, /Cards\.findOneAsync\(\{ boardId: board\._id, archived: false, 'email\.threadIds'/);
|
|
assert.match(emailToCard, /allowIsBoardMemberWithWriteAccess\(user\._id, board\)/);
|
|
assert.match(read('server/emailView.js'), /ReactiveCache\.getCard\(\{ _id: input\.cardId, boardId: board\._id \}\)/);
|
|
const source = read('server/models/cardComments.js');
|
|
const at = source.indexOf("WebApp.handlers.post('/api/boards/:boardId/cards/:cardId/comments'");
|
|
assert.ok(source.indexOf('commentCardMatchesBoard(card, paramCardId, paramBoardId)', at) < source.indexOf('CardComments.direct.insertAsync(', at));
|
|
// Inbound email derives boardId from the authenticated/authorized card,
|
|
// rather than accepting an independent board id from an HTTP parameter.
|
|
assert.match(read('server/routes/inboundEmail.js'), /boardId:\s*card\.boardId/);
|
|
});
|