mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 15:45:01 -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 !
153 lines
8.0 KiB
JavaScript
153 lines
8.0 KiB
JavaScript
'use strict';
|
|
|
|
// The two WeKan bugs Admin Panel / Problems / Database problems was reporting
|
|
// (commit 30e8e38f6, v10.80). The page had been doing its job for a week and both
|
|
// rows sat there marked "unknown / unclassified".
|
|
// Run: node tests/databaseProblemsFixes.test.cjs
|
|
//
|
|
// That fix shipped without a test, which is what this repairs. Both bugs are the
|
|
// same shape - WeKan calling the database in a way that cannot work, and the admin
|
|
// seeing the wreckage rather than the cause - and both are cheap to pin:
|
|
//
|
|
// 1. Board.ensureDefaultSwimlaneId() called the SYNCHRONOUS Swimlanes.upsert().
|
|
// Meteor 3 removed it on the server, so every card or swimlane move that
|
|
// reached the default-swimlane self-heal threw
|
|
// Error: update is not available on the server. Please use updateAsync()
|
|
// four times in a week, out of moveSwimlane.
|
|
//
|
|
// 2. List.move() inserted a list with `title: this.title`. With no title, the
|
|
// schema refuses the insert - and collection2's own error formatter then
|
|
// reads a property of the undefined field, so the admin got
|
|
// ValidationError: Failed validation
|
|
// Cannot read properties of undefined (reading 'title')
|
|
// naming neither the list nor the problem.
|
|
//
|
|
// The classifier rules matter as much as the fixes: a row nobody can act on is a
|
|
// row nobody acts on, which is how both of these went a week unnoticed.
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const repoRoot = path.resolve(__dirname, '..');
|
|
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
|
|
const boards = read('models/boards.js');
|
|
const lists = read('models/lists.js');
|
|
const { classifyDatabaseError } = require('../models/lib/databaseErrors.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
console.log('databaseProblemsFixes:');
|
|
|
|
// ── 1. the synchronous upsert on the server ─────────────────────────────────
|
|
function bodyOf(source, name) {
|
|
// The DEFINITION, which starts a line - `this.ensureDefaultSwimlaneId()` is a
|
|
// call, and reading its "body" would be reading the caller's.
|
|
const definition = new RegExp(`^\\s*(async\\s+)?${name}\\s*\\(`, 'm');
|
|
const found = definition.exec(source);
|
|
assert.ok(found, `${name} is gone from the model`);
|
|
const at = found.index;
|
|
const open = source.indexOf('{', at);
|
|
let depth = 0;
|
|
for (let i = open; i < source.length; i += 1) {
|
|
if (source[i] === '{') depth += 1;
|
|
else if (source[i] === '}') { depth -= 1; if (depth === 0) return source.slice(at, i + 1); }
|
|
}
|
|
throw new Error(`could not read the body of ${name}`);
|
|
}
|
|
|
|
test('the default-swimlane self-heal uses the async upsert, which is the only one there is', () => {
|
|
const body = bodyOf(boards, 'ensureDefaultSwimlaneId');
|
|
assert.ok(/Swimlanes\.upsertAsync\(/.test(body),
|
|
'Meteor 3 removed the synchronous upsert on the server; calling it threw out of '
|
|
+ 'every move that reached this self-heal');
|
|
assert.ok(!/Swimlanes\.upsert\(/.test(body.replace(/upsertAsync\(/g, '')),
|
|
'and the synchronous one must not come back');
|
|
});
|
|
|
|
test('the synchronous getter does not await, and cannot throw at its caller', () => {
|
|
// It is a getter: it cannot await, and a rejected promise nobody is holding
|
|
// would take the process down instead of the operation.
|
|
const body = bodyOf(boards, 'ensureDefaultSwimlaneId');
|
|
assert.ok(!/await /.test(body), 'a synchronous getter cannot await');
|
|
assert.ok(/catch\(\(\) => \{\}\)|catch\(\s*\(\)\s*=>/.test(body),
|
|
'the promise it starts has to have its rejection handled, or a self-heal '
|
|
+ 'failure becomes an unhandled rejection');
|
|
assert.ok(/try \{/.test(body) && /catch \(e\)/.test(body),
|
|
'and a throw from the call itself must not escape a getter that every board '
|
|
+ 'read goes through');
|
|
assert.ok(/return ReactiveCache\.getSwimlane/.test(body),
|
|
'it returns what is in the cache - which callers already had to handle, '
|
|
+ 'because it was undefined before the self-heal existed at all');
|
|
});
|
|
|
|
test('a caller that needs the swimlane in the same tick has an async twin', () => {
|
|
const async = bodyOf(boards, 'ensureDefaultSwimlaneIdAsync');
|
|
assert.ok(/await Swimlanes\.upsertAsync\(/.test(async),
|
|
'the awaited version is what makes the non-awaited one acceptable');
|
|
});
|
|
|
|
// ── 2. moving a list that has no title ──────────────────────────────────────
|
|
test('moving a list with no title says so instead of crashing in the validator', () => {
|
|
const body = bodyOf(lists, 'move');
|
|
assert.ok(/This list has no title, so it cannot be moved to another board/.test(body),
|
|
'the message has to name the list and the problem - the crash named neither');
|
|
const check = body.indexOf('has no title');
|
|
const insert = body.search(/insertAsync|insert\(/);
|
|
assert.ok(check !== -1 && (insert === -1 || check < insert),
|
|
'and it has to be checked BEFORE the insert, or collection2 formats the error '
|
|
+ 'first and throws on the undefined field');
|
|
});
|
|
|
|
test('the console.log lines that printed a title nobody reads are gone (negative)', () => {
|
|
// Comments out: the fix left a note SAYING the two console.log lines are gone,
|
|
// and a note about a mistake must not read as the mistake.
|
|
const body = bodyOf(lists, 'move')
|
|
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
.split('\n').filter(l => !/^\s*\/\//.test(l)).join('\n');
|
|
assert.ok(!/console\.log/.test(body),
|
|
'they logged the title to a log nobody reads and did not stop the crash');
|
|
});
|
|
|
|
// ── 3. neither reads as "unknown" in the Admin Panel again ──────────────────
|
|
test('both errors classify, as WeKan bugs rather than the admin\'s problem', () => {
|
|
const sync = classifyDatabaseError(
|
|
'Error: update is not available on the server. Please use updateAsync() instead',
|
|
'mongodb');
|
|
assert.ok(sync && sync.id === 'meteor3-sync-api', 'the Meteor 3 sync call classifies');
|
|
assert.strictEqual(sync.kind, 'bug', 'there is nothing for an admin to configure');
|
|
assert.ok(/github\.com\/wekan\/wekan\/issues/.test(sync.whatToDo),
|
|
'so the advice is to upgrade and report, not to change a setting');
|
|
|
|
const validation = classifyDatabaseError(
|
|
"ValidationError: Failed validation\nCannot read properties of undefined (reading 'title')",
|
|
'sqlite');
|
|
assert.ok(validation && validation.id === 'schema-validation', 'the validation crash classifies');
|
|
assert.strictEqual(validation.severity, 'warning');
|
|
});
|
|
|
|
test('the rules match on every database WeKan runs on', () => {
|
|
// The same WeKan bug reaches an admin whether they run MongoDB or FerretDB on
|
|
// any of its backends; a rule that only matched MongoDB would leave the
|
|
// FerretDB users with the "unknown / unclassified" row this fixed.
|
|
for (const db of ['mongodb', 'sqlite', 'postgresql', 'mysql', 'mariadb', 'hana']) {
|
|
const hit = classifyDatabaseError('insert is not available on the server. Please use insertAsync() instead', db);
|
|
assert.ok(hit && hit.id === 'meteor3-sync-api', `not classified on ${db}`);
|
|
}
|
|
});
|
|
|
|
test('an ordinary database error is not swallowed by the new rules (negative)', () => {
|
|
// The rules are deliberately specific: a connection failure is the database's
|
|
// problem and must keep its own classification and its own advice.
|
|
const other = classifyDatabaseError('MongoNetworkError: connection 4 to 127.0.0.1:27019 closed', 'mongodb');
|
|
assert.ok(!other || other.id !== 'meteor3-sync-api',
|
|
'a network error is not a Meteor 3 API misuse');
|
|
const nothing = classifyDatabaseError('', 'mongodb');
|
|
assert.ok(!nothing || typeof nothing === 'object', 'empty input must not throw');
|
|
assert.doesNotThrow(() => classifyDatabaseError(null, 'mongodb'));
|
|
assert.doesNotThrow(() => classifyDatabaseError('update is not available on the server. Please use updateAsync() instead', 'not-a-database'));
|
|
});
|
|
|
|
console.log(`\ndatabaseProblemsFixes: ${passed} tests passed`);
|