Files
wekan/tests/problemsFalseBlocks.test.cjs
T
Lauri Ojansivu 567f99227b A failed import or export disables an account only when it was an attempt.
secureTransfer recorded every throw as a high "blocked" event naming the
user, and that disables the account. sanitize-html 2.18.0 threw
RangeError on nested <iframe>, so a card planted with the payload locked
out the next member who exported the board; any library fault would do
the same. The transfer boundary now marks its own refusals
(TransferBoundaryError: a cycle, a non-plain object, a size limit), and
models/lib/transferFailure.cjs records only those as blocked - high, and
medium for a size limit as before. Anything else is ImportExportFailure:
detected, still naming whose import or export it was, and never blocking
an account.

tests/transferFailure.test.cjs drives real boundary refusals and a
sanitizer that throws through blockOnSecurityEvent's own decision; with
the old secureTransfer it fails. It also fails if the boundary throws a
plain Error or anything but secureTransfer calls it.

Thanks to xet7 !
2026-10-22 04:56:40 +03:00

80 lines
4.5 KiB
JavaScript

'use strict';
// Admin Panel -> Problems is also an enforcement point: a 'blocked' record of
// high or critical severity that names a userId DISABLES that account
// (server/lib/blockOnSecurityEvent.js). An audit (2026-10-02) found records on
// paths ordinary users reach, so legitimate users lost their accounts:
// - authz.card-member: a client writing back a card's assignees that still
// list a removed member;
// - History restore after the user was demoted (HistoryScopeBleed is a
// deliberate omission);
// - export by an assigned-only member, who reaches the export menus;
// - a large but legitimate import hitting a size limit;
// - a Trello import whose board links to an internal host (ssrf.attachment),
// an identity provider serving avatars from one (ssrf.redirect), a cached
// older client sending an upload file id (authz.upload-path);
// - a REST client writing a card back with the parent it already had.
// Each now records only the attempt, or does not block. This pins all of them.
// Run: node tests/problemsFalseBlocks.test.cjs
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ROOT = path.join(__dirname, '..');
const read = file => fs.readFileSync(path.join(ROOT, file), 'utf8');
function shouldBlock() {
const catalog = {};
// eslint-disable-next-line no-new-func
new Function('exports', `${read('models/lib/securityCategories.js').replace(/^export \{[^}]*\};?\s*$/m, '')}\nexports.categoryFor = categoryFor;`)(catalog);
const src = read('server/lib/blockOnSecurityEvent.js').replace(/^import [^\n]*\n/gm, '')
.replace(/^const \{ categoryFor \} = require[^\n]*\n/m, '').replace(/^export /gm, '');
const lib = {};
// eslint-disable-next-line no-new-func
new Function('exports', 'Meteor', 'categoryFor', `${src}\nexports.shouldBlockAccount = shouldBlockAccount;`)(lib, {}, catalog.categoryFor);
return lib.shouldBlockAccount;
}
test('keys reached by innocent users never disable an account', () => {
const block = shouldBlock();
for (const key of ['ssrf.attachment', 'ssrf.redirect', 'authz.upload-path', 'brute.lockout']) {
assert.equal(block({ key, action: 'blocked', userId: 'u' }), false, key);
}
// A real attempt key still does (negative).
assert.equal(block({ key: 'authz.repoint', action: 'blocked', userId: 'u' }), true);
});
test('a former member in a card\'s assignees is dropped without a record; a stranger is recorded', async () => {
const src = read('server/models/cards.js');
const start = src.indexOf('async function assignableOnBoard(');
const fn = src.slice(start, src.indexOf('\n}\n', start) + 2);
const records = [];
const context = vm.createContext({ canAssignCardMember: (board, id) => board.members.some(m => m.userId === id && m.isActive),
require: () => ({ record: r => records.push(r) }), Array });
vm.runInContext(`${fn}\nthis.assignableOnBoard = assignableOnBoard;`, context);
const board = { _id: 'b', members: [{ userId: 'active', isActive: true }, { userId: 'former', isActive: false }] };
assert.deepEqual([...await context.assignableOnBoard(board, ['active', 'former'])], ['active']);
assert.equal(records.length, 0, 'a removed member written back is not an attempt');
assert.deepEqual([...await context.assignableOnBoard(board, ['active', 'stranger'])], ['active']);
assert.equal(records.length, 1);
assert.match(records[0].detail, /stranger/);
});
test('history restore, exports, imports and unchanged parents record only attempts', () => {
assert.match(read('server/lib/historyReadScope.js'), /canEditCardOrLinkedCard\(userId, card, board, \{ recordDenial: false \}\)/);
for (const file of ['models/export.js', 'models/exportCharts.js']) {
assert.match(read(file), /if \(board && user && board\.isVisibleBy\(user\)\) return;/, file);
}
// A size limit is medium and a fault of the code is never an attempt; the
// decision moved to models/lib/transferFailure.cjs (tests/transferFailure.test.cjs).
const transfer = read('server/lib/secureTransfer.js');
assert.match(transfer, /record\(transferFailureEvent\(error, context\)\)/);
assert.match(read('models/lib/transferFailure.cjs'), /severity: error\.kind === 'limit' \? 'medium' : 'high',/);
const cards = read('server/models/cards.js');
assert.match(cards, /if \(req\.body\.parentId !== beforeEdit\.parentId\) \{\s*await assertParentCardIsVisible/);
assert.match(cards, /if \(!beforeEdit\) \{\s*sendJsonResult\(res, \{ code: 404/);
});