mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
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 !
113 lines
5.0 KiB
JavaScript
113 lines
5.0 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import { formatDateByUserPreference } from '/imports/lib/dateUtils';
|
|
import { line, tableRow, wrapTextBlock, buildPdfBuffer } from '/models/lib/pdfDocument';
|
|
import { buildUnicodePdf } from '/models/server/buildUnicodePdf';
|
|
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');
|
|
|
|
async function unicodeFonts() {
|
|
return {
|
|
main: await Assets.getBinaryAsync('fonts/unifont/unifont-17.0.05.otf'),
|
|
upper: await Assets.getBinaryAsync('fonts/unifont/unifont_upper-17.0.05.otf'),
|
|
};
|
|
}
|
|
|
|
// A board report chart, drawn as a table - same page setup and font as the
|
|
// board/card PDF exports (models/server/ExporterCardPDF.js's
|
|
// buildUnicodePdf/buildPdfBuffer), just a title bar plus a header row and data
|
|
// rows instead of a card's sections.
|
|
class ExporterChartPDF {
|
|
constructor(boardId, chartKey, userLanguage, timezone, dateFormat, options = {}) {
|
|
this._boardId = boardId;
|
|
this.options = options;
|
|
this._chartKey = chartKey;
|
|
this.userLanguage = userLanguage || 'en';
|
|
this.timezone = timezone || '';
|
|
this.dateFormat = dateFormat || 'YYYY-MM-DD';
|
|
}
|
|
|
|
__(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;
|
|
}
|
|
|
|
date(value) {
|
|
if (!value) return '-';
|
|
const date = value instanceof Date ? value : new Date(value);
|
|
if (Number.isNaN(date.getTime())) return String(value);
|
|
const formatted = formatDateByUserPreference(date, this.dateFormat, true, this.timezone || 'UTC');
|
|
return formatted || '-';
|
|
}
|
|
|
|
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);
|
|
|
|
// One tableRow per header/data row: fixed column widths, one line each,
|
|
// so a long card title clips instead of pushing its dates off the line.
|
|
const lines = [line(`${board.title} - ${title}`, true), ''];
|
|
for (const notice of notices) lines.push(...wrapTextBlock(notice).map(text => line(text)), '');
|
|
if (['scrumVelocity', 'scrumSprint', 'scrumDaily'].includes(this._chartKey)) {
|
|
// A sprint has many metrics. Full-width wrapped labels retain context
|
|
// that a narrow multi-column PDF table would clip away.
|
|
for (const row of rows) {
|
|
headers.forEach((header, index) => {
|
|
const value = row[index] instanceof Date ? this.date(row[index]) : String(row[index] ?? '');
|
|
lines.push(...wrapTextBlock(`${header}: ${value}`).map(text => line(text, index === 0)));
|
|
});
|
|
lines.push('');
|
|
}
|
|
} else {
|
|
if (headers.length) lines.push(tableRow(headers, { header: true }));
|
|
rows.forEach(row => lines.push(tableRow(row.map(cell =>
|
|
cell instanceof Date ? this.date(cell) : String(cell ?? '')))));
|
|
}
|
|
if (!rows.length) lines.push(line(this.__('no-data', 'No data')));
|
|
|
|
let pdf;
|
|
try {
|
|
pdf = await buildUnicodePdf(lines, await unicodeFonts());
|
|
} catch (error) {
|
|
console.error(`ExporterChartPDF: Unicode PDF failed, using base-font fallback: ${error.message}`);
|
|
pdf = buildPdfBuffer(lines);
|
|
}
|
|
res.writeHead(200, {
|
|
'Content-Type': 'application/pdf',
|
|
'Content-Disposition': attachmentDisposition(exportFilename(
|
|
this._chartKey, key => this.__(key, key), board.title, 'pdf')),
|
|
'Content-Length': pdf.length,
|
|
});
|
|
res.end(pdf);
|
|
}
|
|
}
|
|
|
|
export { ExporterChartPDF };
|