mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
"Are the security tests enough to prevent what is in the Hall of Fame" was unanswerable. WeKan publishes 58 named vulnerabilities at https://wekan.fi/hall-of-fame/ ; some suites name the one they belong to, most did not, and the Hall of Fame lives in a different repository that CI never checks out. Answering it meant reading 58 pages against 300 suites by hand, which means it was never answered - and a regression test that quietly stops existing is worth nothing, the failure mode tests/testsAreRegistered.test.cjs already caught once when two *bleed suites drifted out of the mocha index. So the list lives in the repository that has the tests, and tests/securityRegressionCoverage.test.cjs keeps the two in step. Every published vulnerability is either GUARDED - named by a suite that still exists - or RECORDED, a gap with a written reason, which is the CHANGELOG's "TODO Later" pattern applied to tests. The gap count is pinned, so a vulnerability cannot be published with neither a test nor a note; a gap that turns out to be guarded after all fails too, so coverage is never understated; and a file that merely REGISTERS suites is not accepted as coverage, or the guard would pass itself. Getting there meant naming vulnerabilities in the suites that already guarded them, which is most of what this commit is: - tests/securityMeifukun.test.cjs guards eight reports and named one. Its sections are RedirectBleed, SourceBleed, LiveBleed, CasBleed, OidcBleed, MetricsBleed, ImpersonateBleed and InviteBleed - seven vulnerabilities that looked untested and were not. - tests/noIdentityReplacement.test.cjs guards IdentityBleed and PatternBleed, the same CodeQL finding twice. - ExportBleed, CrashBleed, MimeBleed and the four LockoutBleed suites now say so. - tests/crossBoardParentCardLeak.test.cjs also guards BoardBleed's cross-board move deny, and now checks it on Lists and Swimlanes too, not only Cards. The count that comes out of it: 29 of 58 published vulnerabilities have a named regression test, and 29 are recorded gaps - mostly 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, and each one now says what it would take to close it. Thanks to xet7 !
201 lines
8.4 KiB
JavaScript
201 lines
8.4 KiB
JavaScript
'use strict';
|
|
|
|
// PathBleed — GHSA-4mxf-m8pq-xc9p, "Avatar versions.path client update enables
|
|
// arbitrary file read via board export" (High, CWE-22 / CWE-73), reported by
|
|
// Alpastx. https://wekan.fi/hall-of-fame/pathbleed/
|
|
//
|
|
// Attachments blocked client-supplied `versions.*.path`; avatars did not — their
|
|
// allow rule was the single line `update: isOwner`, with no field restriction at
|
|
// all. So any authenticated user could point their own avatar's
|
|
// `versions.original.path` at, say, /etc/passwd, then export a board they are a
|
|
// member of: the exporter read that path off disk and embedded the bytes as
|
|
// base64 in `profile.avatarFile`. Arbitrary file read as the WeKan OS user.
|
|
//
|
|
// Two halves, both tested here: the WRITE is refused (the shared guards, now
|
|
// used by avatars as well as attachments) and the READ is refused (the exporter
|
|
// only reads paths that resolve inside WeKan's own storage).
|
|
//
|
|
// Run: node tests/avatarVersionPathTraversal.test.cjs
|
|
|
|
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 {
|
|
hasUnsafeClientVersionFields,
|
|
touchesVersionFields,
|
|
onlyTouchesAllowedFields,
|
|
} = require('../models/lib/fileVersionFields');
|
|
const {
|
|
isPathInside,
|
|
isPathInsideAny,
|
|
isPathInsideBase,
|
|
} = require('../models/lib/storagePathContainment');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// ---------------------------------------------------------------- the write
|
|
|
|
test('the attack payload is recognised on insert', () => {
|
|
assert.strictEqual(
|
|
hasUnsafeClientVersionFields({
|
|
versions: { original: { path: '/etc/passwd' } },
|
|
}),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test('a storage override is recognised too', () => {
|
|
assert.strictEqual(
|
|
hasUnsafeClientVersionFields({ versions: { original: { storage: 'gridfs' } } }),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test('negative: an ordinary upload is not blocked', () => {
|
|
assert.strictEqual(
|
|
hasUnsafeClientVersionFields({
|
|
name: 'me.png',
|
|
type: 'image/png',
|
|
versions: { original: { size: 1234, type: 'image/png' } },
|
|
}),
|
|
false,
|
|
);
|
|
assert.strictEqual(hasUnsafeClientVersionFields({}), false);
|
|
assert.strictEqual(hasUnsafeClientVersionFields(null), false);
|
|
assert.strictEqual(hasUnsafeClientVersionFields({ versions: 'nonsense' }), false);
|
|
});
|
|
|
|
test('the update form: any field under versions is refused', () => {
|
|
assert.strictEqual(touchesVersionFields(['versions.original.path']), true);
|
|
// The whole sub-object carries the path with it, so naming it is the same attack.
|
|
assert.strictEqual(touchesVersionFields(['versions.original']), true);
|
|
assert.strictEqual(touchesVersionFields(['versions']), true);
|
|
assert.strictEqual(touchesVersionFields(['name', 'versions.original.path']), true);
|
|
});
|
|
|
|
test('negative: renaming an avatar is still allowed', () => {
|
|
assert.strictEqual(touchesVersionFields(['name']), false);
|
|
assert.strictEqual(touchesVersionFields(['meta.boardId', 'type']), false);
|
|
assert.strictEqual(touchesVersionFields([]), false);
|
|
// A field that merely STARTS with the same letters is not the versions subtree.
|
|
assert.strictEqual(touchesVersionFields(['versionsomething']), false);
|
|
});
|
|
|
|
test('the field whitelist compares the part before the first dot', () => {
|
|
const allowed = ['name', 'size', 'type', 'extension', 'extensionWithDot', 'meta'];
|
|
assert.strictEqual(onlyTouchesAllowedFields(['meta.boardId'], allowed), true);
|
|
assert.strictEqual(onlyTouchesAllowedFields(['name', 'size'], allowed), true);
|
|
assert.strictEqual(onlyTouchesAllowedFields(['userId'], allowed), false);
|
|
assert.strictEqual(onlyTouchesAllowedFields(['versions.original.path'], allowed), false);
|
|
});
|
|
|
|
// ----------------------------------------------------------------- the read
|
|
|
|
const AVATARS = '/data/files/avatars';
|
|
const ATTACHMENTS = '/data/files/attachments';
|
|
|
|
test('a real avatar file is readable', () => {
|
|
assert.strictEqual(isPathInside(`${AVATARS}/abc123.png`, AVATARS), true);
|
|
assert.strictEqual(isPathInsideAny(`${AVATARS}/abc123.png`, [AVATARS, ATTACHMENTS]), true);
|
|
});
|
|
|
|
test('the payload path is NOT readable', () => {
|
|
assert.strictEqual(isPathInside('/etc/passwd', AVATARS), false);
|
|
assert.strictEqual(isPathInsideAny('/etc/passwd', [AVATARS, ATTACHMENTS]), false);
|
|
});
|
|
|
|
test('..-escapes are resolved before comparing, not string-matched', () => {
|
|
assert.strictEqual(isPathInside(`${AVATARS}/../../../etc/passwd`, AVATARS), false);
|
|
assert.strictEqual(isPathInside(`${AVATARS}/../attachments/x.png`, AVATARS), false);
|
|
});
|
|
|
|
test('a sibling directory with the root as a prefix is not inside it', () => {
|
|
assert.strictEqual(isPathInside('/data/files/avatars-evil/x.png', AVATARS), false);
|
|
});
|
|
|
|
test('the storage root itself is not a file to read', () => {
|
|
assert.strictEqual(isPathInside(AVATARS, AVATARS), false);
|
|
// ...though as a BASE it contains itself, which is what the download path
|
|
// has always meant by isPathInside(base, target).
|
|
assert.strictEqual(isPathInsideBase(AVATARS, AVATARS), true);
|
|
});
|
|
|
|
test('negative: empty and non-string paths are refused, never accepted', () => {
|
|
assert.strictEqual(isPathInside('', AVATARS), false);
|
|
assert.strictEqual(isPathInside(null, AVATARS), false);
|
|
assert.strictEqual(isPathInside(undefined, AVATARS), false);
|
|
assert.strictEqual(isPathInside(`${AVATARS}/x.png`, ''), false);
|
|
assert.strictEqual(isPathInsideAny(`${AVATARS}/x.png`, null), false);
|
|
assert.strictEqual(isPathInsideAny(`${AVATARS}/x.png`, []), false);
|
|
});
|
|
|
|
// -------------------------------------------------------------- the sources
|
|
|
|
test('the avatar allow rule no longer says just `update: isOwner`', () => {
|
|
const avatars = read('server/permissions/avatars.js');
|
|
assert.ok(
|
|
!/^\s*update:\s*isOwner\s*,/m.test(avatars),
|
|
'the unrestricted `update: isOwner` is what the advisory exploited',
|
|
);
|
|
assert.ok(/touchesVersionFields\(fields\)/.test(avatars), 'update checks the versions subtree');
|
|
assert.ok(/hasUnsafeClientVersionFields\(doc\)/.test(avatars), 'insert checks the payload');
|
|
assert.ok(/onlyTouchesAllowedFields\(/.test(avatars), 'update has a field whitelist');
|
|
assert.ok(/isOwner\(userId, doc\)/.test(avatars), 'and being the owner is still required');
|
|
});
|
|
|
|
test('both permission files import the guards from ONE module', () => {
|
|
const avatars = read('server/permissions/avatars.js');
|
|
const attachments = read('server/permissions/attachments.js');
|
|
const importRe = /from '\/models\/lib\/fileVersionFields'/;
|
|
assert.ok(importRe.test(avatars), 'avatars import the shared guards');
|
|
assert.ok(importRe.test(attachments), 'attachments import the shared guards');
|
|
// The duplicate that let the two drift apart is gone.
|
|
assert.ok(
|
|
!/function hasUnsafeClientVersionFields/.test(attachments),
|
|
'attachments must not keep a private copy of the rule',
|
|
);
|
|
});
|
|
|
|
test('the exporter checks containment before reading a stored path', () => {
|
|
const exporter = read('models/exporter.js');
|
|
assert.ok(/function isReadableStoredFilePath/.test(exporter));
|
|
// The one place bytes are read, and both avatar call sites.
|
|
const guards = exporter.match(/isReadableStoredFilePath\(/g) || [];
|
|
assert.ok(guards.length >= 4, `expected the guard at every read site, found ${guards.length}`);
|
|
assert.ok(
|
|
/const storedPath = doc\?\.versions\?\.original\?\.path;[\s\S]{0,400}?if \(!isReadableStoredFilePath\(storedPath\)\)/.test(exporter),
|
|
'getBase64Data refuses an uncontained path before opening a read stream',
|
|
);
|
|
});
|
|
|
|
test('negative: no unguarded read of a stored version path remains in the exporter', () => {
|
|
const exporter = read('models/exporter.js');
|
|
assert.ok(
|
|
!/createReadStream\(doc\.versions\.original\.path\)/.test(exporter),
|
|
'the stream must be opened on the CHECKED path variable, not on the raw field',
|
|
);
|
|
const reads = exporter.match(/fs\.readFileSync\(p\)/g) || [];
|
|
assert.strictEqual(reads.length, 1, 'one readFileSync, and it is inside the checked branch');
|
|
assert.ok(/if \(p && isReadableStoredFilePath\(p\)\) \{/.test(exporter));
|
|
});
|
|
|
|
test('the download path uses the same containment module, not its own copy', () => {
|
|
const strategy = read('models/lib/fileStoreStrategy.js');
|
|
assert.ok(/require\('\.\/storagePathContainment'\)/.test(strategy));
|
|
assert.ok(
|
|
!/^function isPathInside\(/m.test(strategy),
|
|
'the private duplicate is gone — one rule, one place',
|
|
);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|