Files
wekan/tests/restSecurityAdvisories.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

169 lines
7.8 KiB
JavaScript

'use strict';
// Regression coverage for ChecklistWriteBleed (GHSA-5r4m-5xx6-96jf),
// CommentWriteBleed (GHSA-qf5c-63jx-mpv4), RoleBleed (GHSA-cp24-5m9m-wm97),
// OwnerBleed (GHSA-6jvj-85q3-6q2m), TokenAuditBleed
// (GHSA-5r57-9vj7-c64f) and ErrorBleed (GHSA-h59p-76c3-8345).
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const route = (source, start, end) => {
const from = source.indexOf(start);
const to = source.indexOf(end, from + start.length);
assert.notStrictEqual(from, -1, `route start not found: ${start}`);
assert.notStrictEqual(to, -1, `route end not found after: ${start}`);
return source.slice(from, to);
};
const cards = read('server/models/cards.js');
const checklists = read('server/models/checklists.js');
const items = read('server/models/checklistItems.js');
const comments = read('server/models/cardComments.js');
const boards = read('server/models/boards.js');
const users = read('server/models/users.js');
for (const section of [
route(cards,
"WebApp.handlers.post('/api/boards/:boardId/lists/:listId/cards'",
"WebApp.handlers.post(\n '/api/boards/:boardId/lists/:listId/cards/bulk'"),
route(cards,
"WebApp.handlers.post(\n '/api/boards/:boardId/lists/:listId/cards/bulk'",
"WebApp.handlers.get('/api/boards/:boardId/cards_count'"),
]) {
assert.match(section, /allowIsBoardMemberWithWriteAccess/);
assert.doesNotMatch(section, /allowIsBoardMemberCommentOnly/);
}
for (const section of [
route(checklists,
"WebApp.handlers.post(\n '/api/boards/:boardId/cards/:cardId/checklists'",
"WebApp.handlers.delete(\n '/api/boards/:boardId/cards/:cardId/checklists/:checklistId'"),
route(checklists,
"WebApp.handlers.delete(\n '/api/boards/:boardId/cards/:cardId/checklists/:checklistId'",
'\n);\n'),
route(items,
"WebApp.handlers.post(\n '/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items'",
"WebApp.handlers.put(\n '/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items/:itemId'"),
route(items,
"WebApp.handlers.put(\n '/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items/:itemId'",
"WebApp.handlers.delete(\n '/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items/:itemId'"),
route(items,
"WebApp.handlers.delete(\n '/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items/:itemId'",
'\n);\n'),
]) {
assert.match(section, /await Authentication\.checkBoardWriteAccess/);
assert.doesNotMatch(section, /Authentication\.checkBoardAccess/);
}
const commentCreate = route(
comments,
"WebApp.handlers.post('/api/boards/:boardId/cards/:cardId/comments'",
"WebApp.handlers.put(\n '/api/boards/:boardId/cards/:cardId/comments/:commentId'",
);
assert.match(commentCreate, /allowIsBoardMemberCommentOnly/);
assert.doesNotMatch(commentCreate, /Authentication\.checkBoardAccess/);
// The comment EDIT route (added after CommentBleed, GHSA-pqr4-rxgp-hv2m): it
// requires board membership AND runs the same author-or-admin object check
// restCommentDeleteAcl.test.cjs pins for DELETE - membership alone is not
// enough to edit somebody else's comment either.
const commentEdit = route(
comments,
"WebApp.handlers.put(\n '/api/boards/:boardId/cards/:cardId/comments/:commentId'",
"WebApp.handlers.delete(\n '/api/boards/:boardId/cards/:cardId/comments/:commentId'",
);
assert.match(commentEdit, /Authentication\.checkBoardAccess/);
assert.match(commentEdit, /assertCanMutateComment/);
const boardCreate = route(
boards,
"WebApp.handlers.post('/api/boards'",
'/**\n * @operation import_board',
);
assert.match(boardCreate, /userId: req\.userId/);
assert.doesNotMatch(boardCreate, /req\.body\.owner/);
// OwnerBleed: neither the members list nor a role flag comes from the body.
assert.doesNotMatch(boardCreate, /req\.body\.(members|isAdmin|isActive|isNoComments|isCommentOnly|isWorker|userId)\b/);
const userCreate = route(
users,
"WebApp.handlers.post('/api/users/'",
"WebApp.handlers.delete('/api/users/:userId'",
);
assert.match(userCreate, /const id = await Accounts\.createUser/);
assert.doesNotMatch(userCreate, /code: 200, data: error/);
const tokenCreate = route(
users,
"WebApp.handlers.post('/api/createtoken/:userId'",
"WebApp.handlers.post('/api/deletetoken'",
);
assert.match(tokenCreate, /A reason is required/);
assert.match(tokenCreate, /await ImpersonatedUsers\.insertAsync/);
// c3caf87a1 replaced Accounts._insertLoginToken with insertActiveLoginToken
// (server/lib/activeUser.js), which refuses to mint a token for a disabled
// account in the same update that pushes it. The audit-first order is what
// this guard is about, so it now looks for the new call - and both needles
// must be FOUND, because a missing one (indexOf -1) would otherwise make the
// ordering check pass or fail for the wrong reason.
const auditAt = tokenCreate.indexOf('ImpersonatedUsers.insertAsync');
const tokenAt = tokenCreate.indexOf(
"require('/server/lib/activeUser').insertActiveLoginToken(",
);
assert.ok(auditAt >= 0, 'the impersonation audit record is written');
assert.ok(tokenAt >= 0, 'the impersonation token goes through insertActiveLoginToken');
assert.ok(
auditAt < tokenAt,
'the audit record must be written before the impersonation token',
);
// Negative: no raw insert that would skip the disabled-account check.
assert.doesNotMatch(tokenCreate, /Accounts\._insertLoginToken\(/);
for (const source of [boards, users]) {
assert.doesNotMatch(source, /sendJsonResult\(res, \{ code: 200, data: error \}\)/);
assert.doesNotMatch(source, /data: \{ error: error\.(?:reason|message)/);
}
console.log(' ok - REST security advisory authorization and response guards');
// OwnerBleed, DDP sibling (2026-10-02): a client board insert could carry its
// own members list, naming somebody else as admin. Refused, and recorded.
{
const perms = read('server/permissions/boards.js');
const deny = perms.slice(perms.indexOf('Boards.deny({'), perms.indexOf('Boards.allow({'));
assert.match(deny, /async insert\(userId, doc\) \{[\s\S]*?doc\.members\.some\(member => !member \|\| member\.userId !== userId\)[\s\S]*?key: 'authz\.board-owner'[\s\S]*?return true;/);
assert.match(read('models/lib/securityCategories.js'), /'authz\.board-owner':\s*\{[^}]*bleed: 'OwnerBleed'/);
console.log(' ok - OwnerBleed DDP sibling: client board inserts name only their creator');
}
// ErrorBleed, siblings (2026-10-02): lists, cards counts, org, team, settings,
// attachment storage settings, rules and dependencies answered a refused
// request with HTTP 200 - or the raw error object - instead of the shared
// publicErrorData(). Now nowhere in the server does.
{
const walk = dir => fs.readdirSync(path.join(__dirname, '..', dir), { withFileTypes: true }).flatMap(e => {
if (e.name === 'tests' || e.name.startsWith('_build') || e.name === 'node_modules') return [];
const rel = `${dir}/${e.name}`;
return e.isDirectory() ? walk(rel) : (rel.endsWith('.js') ? [rel] : []);
});
const offenders = ['server', 'models'].flatMap(walk)
.filter(file => /sendJsonResult\(res, \{[^}]*?\bdata:\s*(error|err|e)\b/.test(read(file)));
assert.deepStrictEqual(offenders, [], 'a REST error answers through publicErrorData()');
console.log(' ok - ErrorBleed siblings: no REST handler answers with a raw error');
}
// Authentication helpers fail closed (2026-10-02): `admin === undefined` let a
// null from the cache pass as an admin, and `userId === undefined` let a null
// user id through checkUserId.
{
const auth = read('server/authentication.js');
assert.doesNotMatch(auth, /admin === undefined/);
assert.match(auth, /async checkUserId\(userId\) \{\s*if \(!userId\) \{/);
assert.match(auth, /checkLoggedIn\(userId\) \{\s*if \(!userId\) \{/);
assert.doesNotMatch(auth, /userId === undefined/);
console.log(' ok - authentication helpers refuse a null admin or user id');
}