mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -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 !
63 lines
2.6 KiB
JavaScript
63 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
// Pure, Meteor-free helper: detect the operators that make a MongoDB selector
|
|
// EXECUTE JAVASCRIPT on the database, anywhere in a selector tree. Used by the
|
|
// windowed card publication (server/publications/cardsWindow.js) and by
|
|
// server/lib/selectorGuard.js to refuse a client-supplied selector that carries
|
|
// one, since that selector is run against the database.
|
|
// Unit-tested in tests/mongoSelectorSafety.test.cjs.
|
|
//
|
|
// WhereBleed was `$where`, and for a long time `$where` was the only way a find()
|
|
// could run code. It is not any more, and this helper only knew the old one
|
|
// (found by tests/fixedVulnerabilityClasses.test.cjs, which asks whether a fixed
|
|
// mistake exists anywhere else):
|
|
//
|
|
// $where the original: a JavaScript predicate per document
|
|
// $expr + $function MongoDB 4.4+ allows an aggregation expression inside a
|
|
// FIND filter, and $function runs a JavaScript body with
|
|
// arguments - the same capability, reachable through the same
|
|
// client-supplied selector
|
|
// $accumulator the same, for a grouping stage, and equally a code body
|
|
//
|
|
// So the test is "does this selector carry executable JavaScript", not "does it
|
|
// say $where". The name hasWhere stays because that is what every caller asks for
|
|
// and what the vulnerability is called; hasServerSideJs is the honest alias.
|
|
//
|
|
// It is deliberately not a whitelist of allowed operators: a selector is data
|
|
// from a client, and the property being checked here is one specific, catastrophic
|
|
// capability. Field-level authorisation is a different guard
|
|
// (server/lib/selectorGuard.js) and stays there.
|
|
|
|
// Operators whose value is a JavaScript body the database will run.
|
|
const SERVER_SIDE_JS_OPERATORS = new Set([
|
|
'$where',
|
|
'$function',
|
|
'$accumulator',
|
|
]);
|
|
|
|
function hasServerSideJs(obj, seen) {
|
|
if (!obj || typeof obj !== 'object') return false;
|
|
// A selector arrives as JSON over DDP, but a cycle costs nothing to survive and
|
|
// an infinite recursion in a security check is a denial of service of its own.
|
|
const visited = seen || new Set();
|
|
if (visited.has(obj)) return false;
|
|
visited.add(obj);
|
|
|
|
if (Array.isArray(obj)) {
|
|
for (const item of obj) {
|
|
if (hasServerSideJs(item, visited)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
for (const key of Object.keys(obj)) {
|
|
if (SERVER_SIDE_JS_OPERATORS.has(key)) return true;
|
|
if (hasServerSideJs(obj[key], visited)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// The name the callers and the advisory use.
|
|
const hasWhere = hasServerSideJs;
|
|
|
|
module.exports = { hasWhere, hasServerSideJs, SERVER_SIDE_JS_OPERATORS };
|