Files
wekan/tests/chartExportRoutesAuth.test.cjs
T
Lauri Ojansivu 9d323f2aaf Stop disabling legitimate users: Problems records only attempts, or never block, where ordinary use reaches them.
A blocked record of high or critical severity that names a userId disables
that account. Records on paths ordinary users reach therefore took accounts
away from legitimate users:
- authz.card-member, when a client wrote back assignees still listing a removed
  member - now recorded only for ids that were never on the board;
- History restore after the user was demoted - no longer recorded, as the
  HistoryScopeBleed deliberate omission already says;
- export by an assigned-only member, who reaches the export menus - recorded
  only when the caller cannot see the board;
- a large legitimate import hitting a size limit - recorded at medium (cycles
  and non-plain objects stay high), and the record can no longer throw;
- ssrf.attachment (a Trello board's link to an internal host), ssrf.redirect (an
  identity provider's avatar) and authz.upload-path (a cached older client) -
  still recorded, but blocksAccount: false;
- a REST client writing back a card with the parent it already had - only a
  changed parent is checked. That PUT now also answers 404 for a card that is
  not on the named board and list instead of acting on the id alone.

tests/problemsFalseBlocks.test.cjs drives the blocking decision and the real
assignee filter, and pins each condition; four tests that pinned the old calls
follow them. MegaBleed moves to guarded (its Translation sibling test).

Thanks to xet7 !
2026-10-02 10:44:08 +03:00

81 lines
3.3 KiB
JavaScript

'use strict';
// The chart PDF/Excel export routes (models/exportCharts.js) exist and follow
// the same auth pattern as every other export route in this codebase - safe
// against unhandled rejections (safeRoute) and gated on board visibility, not
// left open just because they are new. See models/export.js's exportZip route
// for the pattern this pins.
//
// Run: node tests/chartExportRoutesAuth.test.cjs
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); }
console.log('chartExportRoutesAuth:');
const routes = read('models/exportCharts.js');
test('both chart export routes are registered', () => {
assert.match(routes, /\/api\/boards\/:boardId\/charts\/:chartKey\/exportPDF/);
assert.match(routes, /\/api\/boards\/:boardId\/charts\/:chartKey\/exportExcel/);
});
test('both routes are wrapped in safeRoute', () => {
const pdfRoute = routes.split("'/api/boards/:boardId/charts/:chartKey/exportPDF'")[1].slice(0, 40);
const excelRoute = routes.split("'/api/boards/:boardId/charts/:chartKey/exportExcel'")[1].slice(0, 40);
assert.match(pdfRoute, /safeRoute\(/);
assert.match(excelRoute, /safeRoute\(/);
});
test('an unlisted chartKey is rejected before any board data is loaded', () => {
assert.match(routes, /CHART_KEYS\.has\(req\.params\.chartKey\)/g);
});
test('access is gated on board visibility (canExport -> isVisibleBy) and denial is logged', () => {
assert.match(routes, /exporter\.canExport\(user\)/);
// Records only when the caller cannot see the board (an assigned-only
// member is refused in ordinary use; 2026-10-02).
assert.match(routes, /logExportDenied\(user, board && board\._id\)/);
});
test('a private board without a valid authToken still requires a logged-in user', () => {
assert.match(routes, /Authentication\.checkLoggedIn\(req\.userId\)/);
});
const pdfExporter = read('models/server/ExporterChartPDF.js');
const excelExporter = read('models/server/ExporterChartExcel.js');
test('ExporterChartPDF.canExport uses the shared visibility and assigned-card policy', () => {
// Authorization now also restricts assigned-only exports; requiring the old
// inline visibility check would discard that narrower shared policy.
assert.match(pdfExporter, /return canExportBoardData\(board, user, this\._chartKey\)/);
assert.match(read('models/lib/exportAccess.js'), /board\.isVisibleBy\(user\)/);
});
test('ExporterChartExcel.canExport uses the shared visibility and assigned-card policy', () => {
assert.match(excelExporter, /return canExportBoardData\(board, user, this\._chartKey\)/);
});
test('the chart PDF exporter reuses the shared pdfDocument/buildUnicodePdf renderer', () => {
assert.match(pdfExporter, /from '\/models\/lib\/pdfDocument'/);
assert.match(pdfExporter, /buildUnicodePdf/);
});
test('the chart Excel exporter reuses the shared createWorkbook helper', () => {
assert.match(excelExporter, /from '\.\/createWorkbook'/);
});
test('the new export module is loaded by the server bundle', () => {
const imports = read('server/imports.js');
assert.match(imports, /import '\/models\/exportCharts';/);
});
console.log(`chartExportRoutesAuth: ${passed} passed`);