mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
Every entry in https://wekan.fi/hall-of-fame/ has a suite pinning the place it was found. None of them could answer the other half of the question: is the same MISTAKE somewhere else - in WeKan, or in the FerretDB fork WeKan ships as its default database? A per-site regression test knows one file, and the next occurrence is written months later by somebody who never read the advisory. tests/fixedVulnerabilityClasses.test.cjs asks it as a CLASS, over the whole tree and over .tools/FerretDB when the clone is there (and saying it skipped those checks when it is not, rather than passing quietly): ZipBleed an archive entry naming its own destination path, without a containment check - and only for real archive readers, since a readdir entry name is one component and can escape nothing WhereBleed a client-supplied selector carrying operators that execute JavaScript TransitBleed rejectUnauthorized: false, NODE_TLS_REJECT_UNAUTHORIZED, and Go's InsecureSkipVerify in the FerretDB fork SourceBleed eval() / new Function() on the server MimeBleed an SVG served inline by a route that neither sanitizes it nor forces a download RandomBleed a secret from Math.random(), and random bytes folded onto an alphabet with a bare % - CWE-1204 modulo bias Comments and string literals are stripped before matching, or the advisory notes explaining a fix would trip the check enforcing it. Allowed occurrences are listed with the reason they are allowed. Each check was confirmed to FAIL on the mistake by writing one into the tree and watching it fire; both probes were removed. It found one straight away. models/lib/mongoSelectorSafety.js rejected `$where` and nothing else - but `$where` stopped being the only way a FIND filter runs JavaScript in MongoDB 4.4, which takes an aggregation expression inside a find filter, and `$expr: { $function: { body, args, lang } }` there runs a JavaScript body through the same client-supplied selector. `$accumulator` is the same again. Both are rejected now, the helper is named for what it tests (hasServerSideJs, with hasWhere as the alias every caller and the advisory use), and a cyclic selector cannot spin it - an infinite recursion inside a security check is a denial of service of its own. tests/mongoSelectorSafety.test.cjs gains those, plus the negatives that keep it usable: a field literally called `function`, and `$expr` doing ordinary comparison, are both fine. randombleed moves from RECORDED to GUARDED in tests/securityRegressionCoverage. test.cjs, and its gap count from 25 to 24: the rejection sampling CWE-1204 was about is now held everywhere rather than in one file. And one release entry had shipped with no test at all - the only one since v10.80 that is not a translation update. tests/databaseProblemsFixes.test.cjs covers it: the default-swimlane self-heal calling the synchronous upsert Meteor 3 removed (and the getter that starts the async one without awaiting it, which must handle its own rejection or a self-heal failure takes the process with it), List.move() inserting a list with no title and getting an error from the error formatter rather than from the validator, and the two classifier rules that stop either reading as "unknown / unclassified" in Admin Panel / Problems - on every database WeKan runs on, and without swallowing an ordinary network error. Coverage checked, not assumed: all 60 published vulnerabilities are named by a suite, and every one of those suites carries negative assertions as well as positive ones. New suites need no registration - build.sh's test run calls tests/run-node-suites.cjs, which DISCOVERS every tests/*.test.cjs - so all three files here are in the "Run WeKan's own tests" options already. Verified by running the new suites and the whole node suite (380 suites, 0 failed). Thanks to xet7 !
117 lines
4.4 KiB
JavaScript
117 lines
4.4 KiB
JavaScript
'use strict';
|
|
|
|
// Plain-Node unit test (no Meteor) for the windowed-card publication's selector
|
|
// safety check. Run: node tests/mongoSelectorSafety.test.cjs
|
|
//
|
|
// The lazy card-loading feature (CARDS_LOADING=lazy) lets the client pass the
|
|
// exact selector it renders with to the `boardCardsWindow` publication, which
|
|
// runs it against the database. hasWhere() must refuse any selector carrying a
|
|
// `$where` clause (server-side JS execution) at ANY depth, while never flagging
|
|
// an ordinary field/operator selector.
|
|
|
|
const assert = require('assert');
|
|
const { hasWhere } = require('../models/lib/mongoSelectorSafety');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// --- NEGATIVE (safe selectors → hasWhere returns false) ---------------------
|
|
test('empty selector is safe', () => {
|
|
assert.strictEqual(hasWhere({}), false);
|
|
});
|
|
test('plain field selector is safe', () => {
|
|
assert.strictEqual(hasWhere({ listId: 'l1', archived: false }), false);
|
|
});
|
|
test('operators and $in arrays are safe', () => {
|
|
assert.strictEqual(
|
|
hasWhere({ swimlaneId: { $in: ['s1', null, ''] }, boardId: 'b1' }),
|
|
false,
|
|
);
|
|
});
|
|
test('nested $and / $or are safe', () => {
|
|
assert.strictEqual(
|
|
hasWhere({ $and: [{ listId: 'l1' }, { $or: [{ a: 1 }, { b: 2 }] }] }),
|
|
false,
|
|
);
|
|
});
|
|
test('a field literally named where (no $) is safe', () => {
|
|
assert.strictEqual(hasWhere({ where: 'somewhere', location: { where: 'x' } }), false);
|
|
});
|
|
test('null / non-object inputs are safe', () => {
|
|
assert.strictEqual(hasWhere(null), false);
|
|
assert.strictEqual(hasWhere(undefined), false);
|
|
assert.strictEqual(hasWhere('string'), false);
|
|
assert.strictEqual(hasWhere(42), false);
|
|
});
|
|
|
|
// --- POSITIVE (malicious selectors → hasWhere returns true) -----------------
|
|
test('top-level $where is rejected', () => {
|
|
assert.strictEqual(hasWhere({ $where: 'this.x == 1' }), true);
|
|
});
|
|
test('$where as a function value is rejected', () => {
|
|
assert.strictEqual(hasWhere({ $where: function () { return true; } }), true);
|
|
});
|
|
test('$where nested inside $and is rejected', () => {
|
|
assert.strictEqual(
|
|
hasWhere({ $and: [{ listId: 'l1' }, { $where: 'sleep(9999)' }] }),
|
|
true,
|
|
);
|
|
});
|
|
test('$where deep inside an array element is rejected', () => {
|
|
assert.strictEqual(
|
|
hasWhere({ $or: [{ a: 1 }, { b: { $in: [{ $where: 'x' }] } }] }),
|
|
true,
|
|
);
|
|
});
|
|
test('$where inside $elemMatch is rejected', () => {
|
|
assert.strictEqual(
|
|
hasWhere({ members: { $elemMatch: { $where: 'evil' } } }),
|
|
true,
|
|
);
|
|
});
|
|
|
|
// #6588-class follow-up, found by tests/fixedVulnerabilityClasses.test.cjs asking
|
|
// whether a fixed mistake exists anywhere else: $where was never the only way a
|
|
// FIND filter can run JavaScript. MongoDB 4.4+ takes an aggregation expression in
|
|
// a find filter, and $function there runs a JavaScript body with arguments - the
|
|
// same capability through the same client-supplied selector.
|
|
test('$expr + $function is rejected - the modern spelling of $where', () => {
|
|
assert.strictEqual(
|
|
hasWhere({ $expr: { $function: { body: 'function(){ return true }', args: [], lang: 'js' } } }),
|
|
true,
|
|
);
|
|
});
|
|
test('$accumulator is rejected too', () => {
|
|
assert.strictEqual(hasWhere({ x: { $accumulator: { init: 'function(){}', lang: 'js' } } }), true);
|
|
});
|
|
test('$function nested in an array element is rejected', () => {
|
|
assert.strictEqual(
|
|
hasWhere({ $or: [{ a: 1 }, { $expr: { $eq: [{ $function: { body: 'x' } }, 1] } }] }),
|
|
true,
|
|
);
|
|
});
|
|
test('a field literally named function or accumulator is safe (negative)', () => {
|
|
// No $, no execution: these are ordinary field names a board could really use.
|
|
assert.strictEqual(hasWhere({ function: 'value', accumulator: 2 }), false);
|
|
assert.strictEqual(hasWhere({ meta: { function: { body: 'not an operator' } } }), false);
|
|
});
|
|
test('$expr WITHOUT a code operator is still safe (negative)', () => {
|
|
// $expr on its own is ordinary comparison, and refusing it would break honest
|
|
// queries - what is refused is the code body inside it.
|
|
assert.strictEqual(hasWhere({ $expr: { $gt: ['$spent', '$budget'] } }), false);
|
|
});
|
|
test('a selector that refers to itself does not hang the check (negative)', () => {
|
|
const cyclic = { a: 1 };
|
|
cyclic.self = cyclic;
|
|
assert.strictEqual(hasWhere(cyclic), false);
|
|
const cyclicEvil = { $and: [{ $where: 'x' }] };
|
|
cyclicEvil.self = cyclicEvil;
|
|
assert.strictEqual(hasWhere(cyclicEvil), true);
|
|
});
|
|
|
|
console.log(`\nmongoSelectorSafety: ${passed} tests passed`);
|