Files
wekan/models/server/ExporterChartExcel.js
T
Lauri Ojansivu be6727607c CrossBoardExportBleed: a checklist scope stays on its board, and every export obeys Disable all export and Anonymize export users.
GHSA-8885-xrq4-j47h, reported by ccsimplyspolit, both findings confirmed
in the current code:

1. GET /api/boards/<board>/export?checklistId=<id> (and exportZip)
   selected the scoped checklist and its items by id alone. A checklist
   of another board - a private one too - was streamed with every item
   and its creator, whose profile the anonymization map did not cover.
   Both selectors are now bound to the exported board's cards, and a
   checklist of another board is recorded in Admin Panel / Problems
   (authz.export-checklist-scope).

2. The streaming CSV/TSV export asked neither Disable all export nor
   Anonymize export users. Neither did, it turned out, Excel (board,
   card, all boards), PDF (board and card), the chart exports, the
   calendar feed or the external formats: only the WeKan JSON, ZIP and
   Trello exports did, though the setting promises that "the server
   rejects any export request" and names CSV and Excel.
   - refuseDisabledExport() answers 403 before anything is written, and
     all 13 HTTP export routes call it first; assertExportEnabled() still
     guards the builders. Both record the attempt (authz.export-disabled,
     never blocking the account: a page opened before the switch still
     shows the menus).
   - anonymizeExportIdentities() anonymizes what one exporter writes -
     users, @mentions, requested-by / assigned-by, comments - with the map
     build() uses, board members included. The CSV/TSV stream, Excel,
     PDF, chart exports (forExport: the chart views keep names), the
     calendar feed and every external format call it.

tests/crossBoardExportBleed.test.cjs drives the gate and the anonymizer
and scans the tree: no scoped checklist selected by id alone, no export
route without the gate, no exporter naming people without anonymizing.
All 7 fail on the code before. The new spec
security-cross-board-export.e2e.js replays the reporter's requests and
checks every export route while export is disabled and the CSV and
Kanboard exports while anonymizing; it passes with export-access and
scrum-export-anonymization against a rebuilt bundle.

Thanks to ccsimplyspolit and xet7 !
2026-11-01 14:00:19 +02:00

121 lines
5.0 KiB
JavaScript

import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { createWorkbook } from './createWorkbook';
import { attachmentDisposition, exportFilename } from '/models/lib/exportFilename';
import { loadBoardChartData } from '/server/lib/boardChartData';
import { loadScrumChartData } from '/server/lib/scrumChartData';
const { chartExportRows } = require('/models/lib/chartExportRows');
// A board report chart as an .xlsx sheet - same createWorkbook() the board/
// card Excel exports use (models/server/ExporterExcelBoard.js), a bold header
// row, one row of data per line.
class ExporterChartExcel {
constructor(boardId, chartKey, userLanguage, options = {}) {
this._boardId = boardId;
this.options = options;
this._chartKey = chartKey;
this.userLanguage = userLanguage || 'en';
}
__(key, fallback) {
try {
const translated = TAPi18n.__(key, '', this.userLanguage);
if (translated && translated !== key) return translated;
} catch (error) { /* a missing bundle is not a reason to fail an export */ }
return fallback;
}
async canExport(user) {
this._customFieldViewerId = user?._id;
await require('/server/lib/adminOnlyCustomFields').assertFieldExport(this._boardId, this._customFieldViewerId);
this.userId = user?._id || null;
const board = await ReactiveCache.getBoard(this._boardId);
const { canExportBoardData } = require('/models/lib/exportAccess');
return canExportBoardData(board, user, this._chartKey);
}
async build(res) {
await require('/server/lib/adminOnlyCustomFields').assertFieldExport(this._boardId, this._customFieldViewerId);
const board = await ReactiveCache.getBoard(this._boardId);
if (!board) {
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('Board not found');
return;
}
const data = ['scrumVelocity', 'scrumSprint', 'scrumDaily'].includes(this._chartKey)
? await loadScrumChartData(this.userId, this._boardId, this._chartKey, this.options)
: await loadBoardChartData(this._boardId, this._chartKey, { ...this.options, forExport: true });
const { title, headers, rows, notices = [] } = chartExportRows(
this._chartKey, data || {}, (key, fallback) => this.__(key, fallback));
const details = require('/models/lib/flowAnalyticsRows').flowDetailRows(
this._chartKey, data || {}, (key, fallback) => this.__(key, fallback));
if (details.rows.length) rows.push([], details.headers, ...details.rows);
const workbook = createWorkbook();
workbook.creator = board.title;
workbook.created = new Date();
workbook.modified = new Date();
const sheetName = title.replace(/[\\/?*[\]:]/g, ' ').slice(0, 31) || 'Chart';
const ws = workbook.addWorksheet(sheetName, {
pageSetup: { paperSize: 9, orientation: 'landscape', fitToPage: true, fitToWidth: 1 },
});
ws.columns = (headers.length ? headers : ['']).map(() => ({ width: 20 }));
ws.mergeCells(1, 1, 1, Math.max(headers.length, 1));
const titleCell = ws.getCell(1, 1);
titleCell.value = `${board.title} - ${title}`;
titleCell.font = { size: 16, bold: true };
ws.getRow(1).height = 30;
if (headers.length) {
const headerRow = ws.getRow(2);
headers.forEach((header, index) => {
const cell = headerRow.getCell(index + 1);
cell.value = header;
cell.font = { bold: true };
cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFD9D9D9' } };
cell.border = {
top: { style: 'thin' }, left: { style: 'thin' },
bottom: { style: 'thin' }, right: { style: 'thin' },
};
});
headerRow.commit();
}
rows.forEach((row, rowIndex) => {
const sheetRow = ws.getRow(3 + rowIndex);
row.forEach((cell, cellIndex) => {
const sheetCell = sheetRow.getCell(cellIndex + 1);
if (cell instanceof Date) {
// A real date cell, not an ISO text string: Excel/LibreOffice then
// show it in the sheet's date format, sort it as a date and accept
// it in date arithmetic. (Before this it was cell.toISOString(),
// which rendered as "2026-09-23T09:00:00.000Z" text.)
sheetCell.value = cell;
sheetCell.numFmt = 'yyyy-mm-dd hh:mm';
} else {
sheetCell.value = cell;
}
});
sheetRow.commit();
});
if (notices.length) {
const notes = workbook.addWorksheet('Notes');
notes.columns = [{ width: 100 }];
notices.forEach(notice => { const row = notes.addRow([notice]); row.alignment = { wrapText: true }; });
}
if (typeof ws.commit === 'function') ws.commit();
res.writeHead(200, {
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition': attachmentDisposition(exportFilename(
this._chartKey, key => this.__(key, key), board.title, 'xlsx')),
});
await workbook.xlsx.write(res);
res.end();
}
}
export { ExporterChartExcel };