mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -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 !
174 lines
7.4 KiB
JavaScript
174 lines
7.4 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import { runOnServer } from './runOnServer';
|
|
|
|
const CHART_KEYS = new Set([
|
|
'dashboard', 'burndown', 'burnup', 'cumulativeFlow', 'controlChart',
|
|
'cycleTime', 'flowEfficiency', 'leadTime', 'throughputHistogram', 'wipRun',
|
|
'gantt', 'time', 'pulse', 'scrumVelocity', 'scrumSprint', 'scrumDaily',
|
|
'agingWip', 'blockerAnalysis', 'monteCarlo', 'processBehavior', 'sizeCycleTime',
|
|
]);
|
|
|
|
runOnServer(function() {
|
|
const { ExporterChartPDF } = require('./server/ExporterChartPDF');
|
|
const { ExporterChartExcel } = require('./server/ExporterChartExcel');
|
|
const { WebApp } = require('meteor/webapp');
|
|
const { safeRoute } = require('/server/apiMiddleware');
|
|
const { Authentication } = require('/server/authentication');
|
|
|
|
// Record an export authorization denial to the Admin Panel security log
|
|
// (best-effort, never breaks the response). Only when the caller cannot see
|
|
// the board at all: an assigned-only member reaches the export menus and is
|
|
// refused in ordinary use, and recording that (high, blocked) disabled their
|
|
// account. See docs/Security/Remediation/WeKan.md.
|
|
function logExportDenied(user, boardId) {
|
|
(async () => {
|
|
try {
|
|
const Boards = require('/models/boards').default;
|
|
const board = await Boards.findOneAsync({ _id: boardId });
|
|
if (board && user && board.isVisibleBy(user)) return;
|
|
require('/server/lib/securityLog').record({
|
|
key: 'authz.export', action: 'blocked', source: 'export',
|
|
detail: 'chart export denied (no board visibility)',
|
|
});
|
|
} catch (e) { /* logging must never break the response */ }
|
|
})();
|
|
}
|
|
|
|
const DATE_FORMATS = ['YYYY-MM-DD', 'DD-MM-YYYY', 'MM-DD-YYYY',
|
|
'YYYY-MM-DD-date-only', 'DD-MM-YYYY-date-only', 'MM-DD-YYYY-date-only'];
|
|
const exportLocale = async (req, user) => {
|
|
let language = (user && user.profile && user.profile.language)
|
|
|| (req.query && req.query.lang) || 'en';
|
|
try {
|
|
await TAPi18n.loadLanguage(language);
|
|
} catch (error) {
|
|
language = 'en';
|
|
}
|
|
const timezone = (req.query && typeof req.query.tz === 'string' && req.query.tz.length <= 64)
|
|
? req.query.tz : '';
|
|
const requested = req.query && req.query.dateFormat;
|
|
const dateFormat = DATE_FORMATS.includes(requested)
|
|
? requested
|
|
: ((user && user.profile && user.profile.dateFormat) || 'YYYY-MM-DD');
|
|
return { language, timezone, dateFormat };
|
|
};
|
|
|
|
async function authenticate(req, res) {
|
|
const boardId = req.params.boardId;
|
|
const board = await ReactiveCache.getBoard(boardId);
|
|
if (!board) {
|
|
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Board not found');
|
|
return { board: null };
|
|
}
|
|
if (board.isPublic()) return { board, user: null };
|
|
|
|
const loginToken = req.query && req.query.authToken;
|
|
if (loginToken) {
|
|
if (loginToken.length > 10000) {
|
|
res.writeHead(400, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Invalid token');
|
|
return { board: null };
|
|
}
|
|
const user = await require('/server/lib/activeUser').activeUserByToken(loginToken, 'exportCharts', req);
|
|
if (!user) {
|
|
res.writeHead(401, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Invalid token');
|
|
return { board: null };
|
|
}
|
|
return { board, user };
|
|
}
|
|
if (!Meteor.settings.public.sandstorm) {
|
|
try {
|
|
// Any logged-in user may request a chart export; board-level access is
|
|
// enforced below by exporter.canExport() (board.isVisibleBy).
|
|
Authentication.checkLoggedIn(req.userId);
|
|
} catch (error) {
|
|
res.writeHead(error.statusCode || 403, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Unauthorized');
|
|
return { board: null };
|
|
}
|
|
}
|
|
const user = await ReactiveCache.getUser({ _id: req.userId });
|
|
return { board, user };
|
|
}
|
|
|
|
async function buildExport(exporter, res) {
|
|
try { await exporter.build(res); }
|
|
catch (error) {
|
|
if (error.error !== 'scrum-import-pending' || res.headersSent) throw error;
|
|
res.writeHead(409, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('The Scrum import is incomplete. Report exports are unavailable.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @operation exportChartPDF
|
|
* @tag Boards
|
|
* @summary Export one board report chart (Dashboard, Burndown, Burnup, CFD,
|
|
* Control Chart, Cycle/Lead Time, Flow Efficiency, Throughput, WIP Run) to PDF.
|
|
* @description Pass the loginToken as the `authToken` query param for private
|
|
* boards: `/api/boards/:boardId/charts/:chartKey/exportPDF?authToken=:token`.
|
|
* @param {string} boardId the ID of the board
|
|
* @param {string} chartKey one of dashboard, burndown, burnup, cumulativeFlow,
|
|
* controlChart, cycleTime, flowEfficiency, leadTime, throughputHistogram, wipRun,
|
|
* time
|
|
* @param {string} authToken the loginToken
|
|
*/
|
|
WebApp.handlers.get('/api/boards/:boardId/charts/:chartKey/exportPDF', safeRoute(async function (req, res) {
|
|
// Before anything else: Admin Panel can turn all export off (CrossBoardExportBleed).
|
|
if (await require('/models/lib/importExportSecurity').refuseDisabledExport(res)) return;
|
|
if (!CHART_KEYS.has(req.params.chartKey)) {
|
|
res.writeHead(400, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Unknown chart');
|
|
return;
|
|
}
|
|
const { board, user } = await authenticate(req, res);
|
|
if (!board) return;
|
|
const { language, timezone, dateFormat } = await exportLocale(req, user);
|
|
const exporter = new ExporterChartPDF(board._id, req.params.chartKey, language, timezone, dateFormat, req.query);
|
|
if (await exporter.canExport(user)) {
|
|
await buildExport(exporter, res);
|
|
} else {
|
|
logExportDenied(user, board && board._id);
|
|
res.writeHead(403, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Unauthorized');
|
|
}
|
|
}));
|
|
|
|
/**
|
|
* @operation exportChartExcel
|
|
* @tag Boards
|
|
* @summary Export one board report chart to Excel (.xlsx).
|
|
* @description Pass the loginToken as the `authToken` query param for private
|
|
* boards: `/api/boards/:boardId/charts/:chartKey/exportExcel?authToken=:token`.
|
|
* @param {string} boardId the ID of the board
|
|
* @param {string} chartKey one of dashboard, burndown, burnup, cumulativeFlow,
|
|
* controlChart, cycleTime, flowEfficiency, leadTime, throughputHistogram, wipRun,
|
|
* time
|
|
* @param {string} authToken the loginToken
|
|
*/
|
|
WebApp.handlers.get('/api/boards/:boardId/charts/:chartKey/exportExcel', safeRoute(async function (req, res) {
|
|
// Before anything else: Admin Panel can turn all export off (CrossBoardExportBleed).
|
|
if (await require('/models/lib/importExportSecurity').refuseDisabledExport(res)) return;
|
|
if (!CHART_KEYS.has(req.params.chartKey)) {
|
|
res.writeHead(400, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Unknown chart');
|
|
return;
|
|
}
|
|
const { board, user } = await authenticate(req, res);
|
|
if (!board) return;
|
|
const { language } = await exportLocale(req, user);
|
|
const exporter = new ExporterChartExcel(board._id, req.params.chartKey, language, req.query);
|
|
if (await exporter.canExport(user)) {
|
|
await buildExport(exporter, res);
|
|
} else {
|
|
logExportDenied(user, board && board._id);
|
|
res.writeHead(403, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Unauthorized');
|
|
}
|
|
}));
|
|
});
|