Files
wekan/tests/unawaitedAccessCheck.test.cjs
T
Lauri Ojansivu ebcd02be6f Hall of Fame regression audit: every fixed vulnerability still fixed, siblings of six of them closed.
Every Hall of Fame vulnerability without a test naming it (24 names, 30
advisories) was checked against the current source. No fix had been
reverted. Looking for the same mistake elsewhere found siblings:

- FloppyBleed: the fs-path-heal upgrade step joined an attachment's
  stored name into candidate paths as-is; a record a client inserted
  named ../../../etc/passwd made the next upgrade copy that file into
  storage - an arbitrary file read. Only the name's last component is
  used now; the bulk move limits a legacy name's extension the same way.
- FilePathBleed (GHSA-g6vm-7757-pr88): the insert guard looked only
  inside versions; with versions left out ostrio:files falls back to a
  top-level path, which removing the record deletes and validation
  reads. A client's top-level path is refused for attachments and
  avatars, recorded by the existing canaries.
- MoveStorageBleed: validateAttachment, which deletes a file failing the
  current upload rules, was open to anybody who could see the board, a
  public one included. Only who may change the file, or a site admin,
  validates now; a refusal is recorded (authz.attachment-validate).
- HookUrlBleed / IntegrationBleed: the REST reads of a board's
  integrations gave the webhook URL - whose path is its secret - to
  every member reading the board; non-admins get what the publication
  gives them.
- AttachmentMigrationBleed: four migration methods answered any
  logged-in user about any board, deleteDuplicateEmptyLists.getStatus
  with a private board's list titles; they require a visible board and
  record refusals (authz.migration-board).
- LegacyAttachBleed (GHSA-xcxp-hx9w-q5q9) and MimeStorageBleed
  (GHSA-rv5g-5p4g-3v89): the legacy route judged a name dangerous only
  for .svg, the response policy missed x-javascript, ecmascript, xsl and
  +xml types, and the sniffers missed <tag/onx= handlers.

OIDCBleed refusals are now recorded in Admin Panel / Problems too. New
suites name the vulnerabilities they guard, existing ones name the
advisories they already covered, and tests/securityRegressionCoverage
counts 128 of 137 published vulnerabilities with a named test (was 125).

Thanks to xet7 !
2026-10-27 16:28:12 +02:00

96 lines
4.6 KiB
JavaScript

'use strict';
// Guard: BFLABleed (2026-05-19, reported by Fredrik Dietrichson) and ExcelBleed
// (CVE-2026-68559, GHSA-mwq8-ccpm-r533).
// Run: node tests/unawaitedAccessCheck.test.cjs
//
// Both were the same mistake. An access check that is an `async` function
// returns a Promise, and a Promise is truthy and never throws where it is
// called: `Authentication.checkBoardAccess(userId, boardId);` without `await`
// let the handler run on for anyone, and its rejection went nowhere. BFLABleed
// was 48 REST endpoints written that way, which let an authenticated non-member
// read and write any board; ExcelBleed was the Excel export route's check.
//
// The test reads the access checks' definitions, so a check that becomes async
// later is covered without editing this file, and requires every call to one of
// them - anywhere in the server tree - to be awaited or returned.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
const read = file => fs.readFileSync(path.join(ROOT, file), 'utf8');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
function sourceFiles() {
const out = [];
const walk = dir => {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
if (['node_modules', 'tests'].includes(entry.name) || entry.name.startsWith('_build') || entry.name.startsWith('.')) continue;
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full);
else if (/\.(c|m)?js$/.test(entry.name)) out.push(full);
}
};
for (const dir of ['server', 'models', 'packages', 'imports']) walk(path.join(ROOT, dir));
return out;
}
const withoutComments = text => text.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '').replace(/([^:])\/\/.*$/gm, '$1');
// The async Authentication checks, read from their definitions.
const authentication = read('server/authentication.js');
const ASYNC_CHECKS = [...authentication.matchAll(/^\s*async (check\w+)\s*\(/gm)].map(m => m[1]);
test('the access checks that must be awaited are the async ones', () => {
for (const name of ['checkUserId', 'checkAdminOrCondition', 'checkBoardAccess', 'checkBoardWriteAccess', 'checkBoardAdmin']) {
assert.ok(ASYNC_CHECKS.includes(name), `${name} is an async check`);
}
// A synchronous check stays callable without await; it throws in place.
assert.ok(!ASYNC_CHECKS.includes('checkLoggedIn'));
});
// Every call of `<receiver>.<method>(`: awaited, returned, or the definition itself.
function unawaitedCalls(pattern) {
const found = [];
for (const file of sourceFiles()) {
const lines = withoutComments(fs.readFileSync(file, 'utf8')).split('\n');
lines.forEach((line, i) => {
for (const m of line.matchAll(pattern)) {
const before = line.slice(0, m.index);
if (/\b(await|return)\s+(\(\s*)?(!\s*)?[\w.\s]*$/.test(before) || /\basync\s+$/.test(before)) continue;
found.push(`${path.relative(ROOT, file)}:${i + 1}: ${line.trim()}`);
}
});
}
return found;
}
test('BFLABleed: every async Authentication check is awaited, everywhere (negative)', () => {
const pattern = new RegExp(`\\bAuthentication\\.(${ASYNC_CHECKS.join('|')})\\(`, 'g');
let calls = 0;
for (const file of sourceFiles()) calls += (fs.readFileSync(file, 'utf8').match(pattern) || []).length;
assert.ok(calls > 100, `expected the REST routes' checks, found ${calls}`);
assert.deepStrictEqual(unawaitedCalls(pattern), [],
'an un-awaited async access check lets the handler run for anyone');
});
test('ExcelBleed: every exporter\'s canExport() is awaited, everywhere (negative)', () => {
const definitions = sourceFiles().filter(file => /async canExport\(/.test(fs.readFileSync(file, 'utf8')));
assert.ok(definitions.length >= 5, 'the exporters define canExport as async');
assert.deepStrictEqual(unawaitedCalls(/\.canExport\(/g), [],
'an un-awaited canExport() is a truthy Promise: the export runs for anyone');
// The Excel export route itself, where ExcelBleed was.
assert.match(read('models/exportExcel.js'), /if \(\(await exporterExcel\.canExport\(user\)\)\)/);
});
test('the scan recognises the vulnerable shape (self-check)', () => {
const tmp = 'const r = Authentication.checkBoardAccess(req.userId, id);\nif (exporter.canExport(user)) {}\n';
const pattern = /\bAuthentication\.(checkBoardAccess)\(|\.canExport\(/g;
const hits = [...tmp.matchAll(pattern)].filter(m => !/\b(await|return)\s+(\(\s*)?(!\s*)?[\w.\s]*$/.test(tmp.slice(tmp.lastIndexOf('\n', m.index) + 1, m.index)));
assert.strictEqual(hits.length, 2);
});
console.log(`\nunawaitedAccessCheck: ${passed} tests passed`);