Files
wekan/tests/securityRegressionCoverage.test.cjs
T
Lauri Ojansivu eb47e04657 Tests: ask whether a fixed mistake is anywhere ELSE, and close two gaps it found.
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 !
2026-08-12 15:06:45 +03:00

256 lines
14 KiB
JavaScript

'use strict';
// Every published vulnerability must have a regression test, or a recorded
// reason why it does not.
//
// WeKan publishes its fixed vulnerabilities at https://wekan.fi/hall-of-fame/ ,
// each with a name. Whether a given one still has a test guarding it was, until
// this file, unanswerable: some suites name the vulnerability they belong to,
// most do not, and the Hall of Fame lives in a different repository that CI
// never checks out. So "are the security tests enough" could only be answered by
// reading 58 pages and 300 suites by hand, which means in practice it was never
// answered at all - and a regression test that quietly stops existing is worth
// nothing, which is the failure mode tests/testsAreRegistered.test.cjs already
// caught once (two *bleed suites had drifted out of the mocha index).
//
// So the list lives HERE, in the repository that has the tests, and this guard
// keeps the two in step:
//
// * GUARDED - the vulnerability is named by at least one test file, and that
// file still exists. Naming is the whole mechanism: a test that
// does not say which published vulnerability it belongs to
// cannot be checked against the published list.
// * RECORDED - no test names it, and the reason is written down. This is the
// CHANGELOG's "TODO Later" pattern applied to tests: a gap with
// a reason is a decision, a gap without one is a surprise.
//
// The list may only move in one direction. Adding a vulnerability to RECORDED is
// allowed and expected when it is published; moving one from RECORDED to GUARDED
// is the work. The count below fails if RECORDED grows, so a new vulnerability
// cannot be published with no test and no note.
//
// Run: node tests/securityRegressionCoverage.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
const SUITE_DIRS = ['tests', 'server/lib/tests', 'client/lib/tests'];
// Files that mention a vulnerability name for bookkeeping rather than testing
// it. They must not be accepted as coverage, or this guard would pass itself.
const NOT_COVERAGE = new Set([
'securityRegressionCoverage.test.cjs', // this file
'testsAreRegistered.test.cjs', // checks registration, not behaviour
'index.js',
'index.test.js',
]);
// ─────────────────────────────────────────────────────────────────────────────
// GUARDED: vulnerability -> the suite(s) that name it.
// ─────────────────────────────────────────────────────────────────────────────
const GUARDED = {
boardbleed: ['tests/crossBoardParentCardLeak.test.cjs'],
casbleed: ['tests/securityMeifukun.test.cjs'],
checklistbleed: ['server/lib/tests/checklistbleed.security.tests.js'],
clonebleed: ['server/lib/tests/clonebleed.security.tests.js'],
commentbleed: ['tests/restCommentDeleteAcl.test.cjs'],
crashbleed: ['tests/exportTokenGuard.test.cjs'],
dnsbleed: ['server/lib/tests/dnsbleed.security.tests.js'],
exportbleed: ['tests/exportHTMLXss.test.cjs'],
followbleed: ['tests/followbleed.test.cjs'],
identitybleed: ['tests/noIdentityReplacement.test.cjs'],
// Moved up from RECORDED: the guard is repo-wide rather than per-site - every
// place that folds random bytes onto an alphabet has to reject the bytes that
// would bias it, and every file that makes a secret has to use a cryptographic
// source. That is what RandomBleed (CWE-1204) was.
randombleed: ['tests/fixedVulnerabilityClasses.test.cjs'],
impersonatebleed: ['tests/securityMeifukun.test.cjs'],
integrationbleed: ['server/lib/tests/dnsbleed.security.tests.js'],
invitebleed: ['tests/securityMeifukun.test.cjs'],
livebleed: ['tests/followbleed.test.cjs', 'tests/securityMeifukun.test.cjs'],
lockoutbleed: [
'tests/loginFailureDecision.test.cjs',
'tests/loginTimingDefense.test.cjs',
'tests/loginAttemptThrottle.test.cjs',
'tests/loginBruteForceEnumerationWiring.test.cjs',
],
metricsbleed: ['tests/securityMeifukun.test.cjs'],
mimebleed: ['server/lib/tests/fileValidationBypass.security.tests.js'],
oidcbleed: ['tests/securityMeifukun.test.cjs'],
parentbleed: ['tests/crossBoardParentCardLeak.test.cjs'],
pathbleed: ['tests/avatarVersionPathTraversal.test.cjs'],
patternbleed: ['tests/noIdentityReplacement.test.cjs'],
proxybleed: ['server/lib/tests/proxybleed.security.tests.js'],
redirectbleed: ['tests/securityLog.test.cjs', 'tests/securityMeifukun.test.cjs'],
revokebleed: ['tests/boardShareRevokeBypass.test.cjs'],
sortbleed: ['server/lib/tests/boards.security.tests.js'],
sourcebleed: ['tests/securityMeifukun.test.cjs'],
transitbleed: ['tests/transitbleed.test.cjs'],
webhookbleed: ['server/lib/tests/dnsbleed.security.tests.js'],
zipbleed: ['tests/zipbleed.test.cjs'],
// Guarded by ATTEMPT DETECTION rather than by a fix-regression test: a canary
// sits where the attack is tried, and tests/canaryCoverage.test.cjs pins that
// the canary is there, is silent, and is attributed
// (docs/Security/Remediation/WeKan.md §12). That is weaker than a test of the
// fix itself - it proves an attempt is SEEN, not that it still fails - so
// these stay candidates for a real regression test. It is stronger than
// nothing, which is what they had.
escapebleed: ['tests/canaryCoverage.test.cjs'],
filebleed: ['tests/canaryCoverage.test.cjs'],
inputbleed: ['tests/canaryCoverage.test.cjs'],
spacebleed: ['tests/canaryCoverage.test.cjs'],
};
// ─────────────────────────────────────────────────────────────────────────────
// RECORDED: published, fixed, and no test names it - with why.
//
// Most of these are older fixes from before WeKan tested its security fixes at
// all. They are NOT known to be unprotected; they are known to be unchecked,
// which is a different and more honest statement. Whoever writes one of these
// tests moves the entry up into GUARDED.
// ─────────────────────────────────────────────────────────────────────────────
const RECORDED = {
adminbleed: 'privilege escalation to Admin; needs a running instance to reproduce, no source guard written',
anchorbleed: 'GHSL-2026-035 CursorBleed; reported before the *bleed suites existed',
authbleed: 'unauthenticated getServiceConfiguration leaked the OIDC client secret; needs a DDP test',
avatarbleed: 'predates the test suites; superseded in part by tests/avatarUrlSafety.test.cjs, which does not name it',
bflableed: '48 REST endpoints missing await on the access check - wants a source sweep over every route, not one test',
brutebleed: 'user data published unconditionally; overlaps userbleed, both need a publication test',
bypassbleed: 'authentication bypass; predates the *bleed test suites, no source guard was written',
duebleed: 'Due Cards showed other users\' private board cards to an Admin; needs a publication test',
emailbleed: 'SMTP password readable behind the asterisks in Admin Panel; a UI-only fix',
excelbleed: 'un-awaited access-control guard in the Excel export route; same class as bflableed',
fieldbleed: 'JavaScript stored in a field ran when the page was reloaded; predates the *bleed test suites',
floppybleed: 'FileBleed variant; predates the *bleed test suites, no source guard was written',
framebleed: 'cross-frame scripting; a header fix with no test',
invisiblebleed: 'HTML comments were not visible in rendered content; predates the *bleed test suites',
ldapbleed: 'LDAP TLS certificate validation off by default; needs an LDAP stack to test',
megableed: 'IDOR in setCreateTranslation; needs a DDP method test',
reactionbleed: 'XSS in comment reactions; predates the *bleed test suites - note the reaction OWNERSHIP hole found in this round is a different bug and is guarded by tests/reactionOwnership.test.cjs',
readonlybleed: 'read-only members could write Custom Fields; needs a permissions test',
scannerbleed: 'CVE-2026-68560 shell injection via an upload filename in the antivirus scanner command; needs a source guard on the command path',
snowbleed: 'MigrationsBleed - a database migration fix; predates the *bleed test suites',
socialbleed: 'social media links on wekan.fi - a website fix, not a WeKan one',
splicebleed: 'incomplete multi-character sanitization stripping markup from a shown filename; tests/fileNameDisplay.test.cjs is the likely guard but does not name it',
tokenbleed: 'predates the *bleed test suites; the REST token paths are exercised by 23-rest-api-more.e2e.js, which does not name it',
userbleed: 'user data published unconditionally; overlaps brutebleed',
};
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
const readSuite = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
// Every suite file in the tree, by basename, with its text.
function allSuites() {
const out = new Map();
SUITE_DIRS.forEach(dir => {
const abs = path.join(ROOT, dir);
if (!fs.existsSync(abs)) return;
fs.readdirSync(abs).forEach(f => {
if (!f.endsWith('.cjs') && !f.endsWith('.js')) return;
out.set(path.join(dir, f), fs.readFileSync(path.join(abs, f), 'utf8'));
});
});
return out;
}
test('every GUARDED vulnerability has a suite that exists and names it', () => {
Object.entries(GUARDED).forEach(([vuln, suites]) => {
assert.ok(suites.length > 0, `${vuln} lists no suite`);
suites.forEach(rel => {
const abs = path.join(ROOT, rel);
assert.ok(fs.existsSync(abs), `${vuln}: ${rel} does not exist`);
const text = readSuite(rel).toLowerCase();
assert.ok(
text.includes(vuln),
`${rel} must NAME ${vuln} - a test that does not say which published ` +
`vulnerability it guards cannot be checked against the published list`,
);
});
});
});
test('no vulnerability is both guarded and recorded as a gap', () => {
const both = Object.keys(GUARDED).filter(v => v in RECORDED);
assert.deepStrictEqual(both, [], 'a vulnerability is either tested or it is not');
});
test('every recorded gap says WHY, in a sentence', () => {
Object.entries(RECORDED).forEach(([vuln, reason]) => {
assert.strictEqual(typeof reason, 'string', `${vuln} needs a reason`);
assert.ok(reason.length >= 25,
`${vuln}: "${reason}" is too short to be a reason somebody can act on`);
});
});
test('a recorded gap is not silently guarded after all', () => {
// If a suite starts naming a vulnerability that is listed as a gap, the entry
// belongs in GUARDED - and leaving it in RECORDED would understate coverage.
const suites = allSuites();
const wrong = [];
Object.keys(RECORDED).forEach(vuln => {
suites.forEach((text, rel) => {
if (NOT_COVERAGE.has(path.basename(rel))) return;
if (text.toLowerCase().includes(vuln)) wrong.push(`${vuln} is named by ${rel}`);
});
});
assert.deepStrictEqual(wrong, [],
'these are tested after all - move them from RECORDED to GUARDED');
});
test('the gap list may not grow', () => {
// Publishing a vulnerability with neither a test nor a note must fail here.
// Lower this number when a gap is closed; raising it is the thing this guard
// exists to make deliberate.
// 25 -> 24: randombleed moved to GUARDED when the repo-wide class guard
// (tests/fixedVulnerabilityClasses.test.cjs) started holding the rejection
// sampling that CWE-1204 was about, everywhere rather than in one file.
assert.strictEqual(Object.keys(RECORDED).length, 24,
'the number of published vulnerabilities with no regression test changed');
});
test('the whole published list is accounted for', () => {
const total = Object.keys(GUARDED).length + Object.keys(RECORDED).length;
// https://wekan.fi/hall-of-fame/ - one directory per vulnerability. Raise this
// when a new one is published, and put it in GUARDED or RECORDED at the same
// time; the two assertions together are what make "every published
// vulnerability is accounted for" a fact rather than a hope.
assert.strictEqual(total, 58, 'the Hall of Fame and this list disagree on how many there are');
});
test('the four newest advisories are guarded, not recorded', () => {
// The ones this round fixed. If any of these ever slips into RECORDED, the
// fix has lost its test.
['pathbleed', 'revokebleed', 'parentbleed', 'commentbleed'].forEach(v => {
assert.ok(v in GUARDED, `${v} must stay guarded`);
});
});
test('negative: a suite that only registers others is not counted as coverage', () => {
// server/lib/tests/index.js names checklistbleed and proxybleed in its import
// list. Importing a suite is not testing a vulnerability, and counting it
// would make this guard pass on the strength of a filename.
assert.ok(NOT_COVERAGE.has('index.js'));
assert.ok(NOT_COVERAGE.has('testsAreRegistered.test.cjs'));
Object.values(GUARDED).flat().forEach(rel => {
assert.ok(!NOT_COVERAGE.has(path.basename(rel)),
`${rel} is bookkeeping, not a regression test`);
});
});
console.log(`\n${passed} tests passed`);
console.log(
`\n ${Object.keys(GUARDED).length} of ` +
`${Object.keys(GUARDED).length + Object.keys(RECORDED).length} published ` +
`vulnerabilities have a named regression test; ` +
`${Object.keys(RECORDED).length} are recorded gaps.`,
);