mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
A member refused write access to a list could move the whole swimlane to another board with POST /api/boards/:boardId/swimlanes/:swimlaneId/move: the route asked only for board write access, and the locked list's cards landed in lists on the other board with no exceptions, where the member could edit or delete them. Now the route refuses with 403 when a list holding the swimlane's cards refuses the caller's role, and the attempt is shown in Admin Panel / Problems as ListLockMoveBleed (authz.list-locked-move). A test fails when any server code moves a swimlane without asking the gate. Also: a card move outside a Meteor method read Meteor.userId(), which throws on the server there, so every REST swimlane move answered 500 after its first card had moved. The mover is read without throwing. GHSA-394w-8q99-q4qx. Thanks to adityasunny06help-coder and xet7 !
40 lines
1.9 KiB
JavaScript
40 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
// A card move outside a Meteor method - a REST request moving a swimlane or a
|
|
// card, a migration - must not throw on the server. Meteor.userId() throws
|
|
// there ("can only be invoked in method calls or publications"), and an
|
|
// unguarded call in the card move's position history turned every REST
|
|
// swimlane move into a 500 after the first card had already moved, leaving the
|
|
// swimlane half moved (found with GHSA-394w-8q99-q4qx).
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const src = fs.readFileSync(path.join(__dirname, '..', 'models', 'cards.js'), 'utf8');
|
|
|
|
// Every Meteor.userId() call in the given source that is not guarded: not on a
|
|
// line that also has `try {`, and not behind an `isClient` / `Meteor.userId &&`
|
|
// check on the same line.
|
|
function unguardedCalls(text) {
|
|
return text.split('\n')
|
|
.map((line, i) => ({ line, n: i + 1 }))
|
|
.filter(({ line }) => /Meteor\.userId\(\)/.test(line)
|
|
&& !/try \{/.test(line) && !/Meteor\.userId &&/.test(line) && !/isClient/.test(line));
|
|
}
|
|
|
|
test('the card move reads its user without throwing outside a method', () => {
|
|
const at = src.indexOf('let moverId = null;');
|
|
assert.ok(at > 0, 'the move keeps its guarded read of the user');
|
|
const block = src.slice(at, src.indexOf("console.warn('Failed to track card move in history:'", at));
|
|
assert.match(block, /try \{ moverId = Meteor\.userId\(\); \} catch \(e\) \{ moverId = null; \}/);
|
|
assert.match(block, /userId: moverId,/);
|
|
assert.deepStrictEqual(unguardedCalls(block), [], 'no bare Meteor.userId() left in the move\'s history block');
|
|
});
|
|
|
|
test('negative: the detector flags a bare call', () => {
|
|
assert.strictEqual(unguardedCalls("if (Meteor.isServer && Meteor.userId()) {").length, 1);
|
|
assert.strictEqual(unguardedCalls("try { id = Meteor.userId(); } catch (e) {}").length, 0);
|
|
});
|