Files
wekan/models/exportExcelCard.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

179 lines
7.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Meteor } from 'meteor/meteor';
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { runOnServer } from './runOnServer';
import ImpersonatedUsers from '/models/impersonatedUsers';
runOnServer(function() {
const { ExporterExcelCard, ALL_FIELDS } = require('./server/ExporterExcelCard');
const { WebApp } = require('meteor/webapp');
const { safeRoute } = require('/server/apiMiddleware');
const { Authentication } = require('/server/authentication');
/**
* @operation exportExcelCard
* @tag Cards
*
* @summary Export a single card to Excel (.xlsx), formatted for DIN A4 Portrait printing.
*
* @description If user is already logged-in, pass loginToken as param
* "authToken": '/api/boards/:boardId/lists/:listId/cards/:cardId/exportExcel?authToken=:token'
*
* Optional query param "fields" is a comma-separated list of sections to include.
* Valid values: people, board-info, dates, description, checklists, subtasks, comments
* Omitting "fields" includes all sections.
*
* @param {string} boardId the ID of the board
* @param {string} listId the ID of the list
* @param {string} cardId the ID of the card to export
* @param {string} authToken the loginToken
* @param {string} fields comma-separated list of sections to include
*/
WebApp.handlers.get(
'/api/boards/:boardId/lists/:listId/cards/:cardId/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;
const boardId = req.params.boardId;
const paramListId = req.params.listId;
const paramCardId = req.params.cardId;
let user = null;
let impersonateDone = false;
let adminId = null;
const board = await ReactiveCache.getBoard(boardId);
if (!board) {
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('Board not found');
return;
}
// GHSA-6p5m-f9p2-wqm5: the card has to BELONG to the board being
// authorised. Every check below is about `board` - isPublic() on one
// branch, canExport() on the other - and both were deciding access to one
// object while the export read a different one, named by a path parameter
// the caller also controls. Bound here, at the routing layer, as well as in
// the exporter's own query: the two identifiers arrive together, so this is
// where their relationship is cheapest to state, and it holds for the
// public branch too, which skips authentication entirely.
//
// 404, not 403: whether a given card id exists at all is not something an
// unauthorised caller should learn from the difference.
const containedCard = await ReactiveCache.getCard({
_id: paramCardId,
boardId,
listId: paramListId,
});
if (!containedCard) {
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('Card not found');
return;
}
// Public boards skip authentication
if (board.isPublic()) {
const fieldsParam = req.query.fields;
const fields = fieldsParam
? fieldsParam.split(',').map(f => f.trim()).filter(f => ALL_FIELDS.includes(f))
: null;
let publicLanguage = (req.query && req.query.lang) || 'en';
try {
await TAPi18n.loadLanguage(publicLanguage);
} catch (_) {
publicLanguage = 'en';
}
const exporter = new ExporterExcelCard(
boardId, paramListId, paramCardId, publicLanguage, fields,
);
await exporter.build(res);
return;
}
// Authenticate for private boards
const loginToken = req.query.authToken;
if (loginToken) {
if (loginToken.length > 10000) {
res.writeHead(400, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('Invalid token');
return;
}
user = await require('/server/lib/activeUser').activeUserByToken(loginToken, 'exportExcelCard', req);
if (!user) {
res.writeHead(401, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('Invalid token');
return;
}
adminId = user._id.toString();
impersonateDone = await ReactiveCache.getImpersonatedUser({ adminId });
} else if (!Meteor.settings.public.sandstorm) {
try {
await Authentication.checkUserId(req.userId);
} catch (error) {
res.writeHead(error.statusCode || 403, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('Unauthorized');
return;
}
user = await ReactiveCache.getUser({
_id: req.userId,
isAdmin: true,
});
}
// A saved profile language is authoritative. The browser language sent
// in ?lang= is used only when the account has no saved language.
let userLanguage =
(user && user.profile && user.profile.language) ||
(req.query && req.query.lang) ||
'en';
// Ensure the chosen language bundle is loaded into i18next.
try {
await TAPi18n.loadLanguage(userLanguage);
} catch (_) {
// Unknown / unsupported language – fall back to English silently.
userLanguage = 'en';
}
// #6586: the date format the OPENED CARD is showing, sent by the export
// link - for a reader who is not logged in it lives in localStorage, which
// this lookup cannot reach. The profile is the fallback, and only the
// three formats formatDateByUserPreference understands are accepted.
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 requestedFormat = req.query && req.query.dateFormat;
const dateFormat = DATE_FORMATS.includes(requestedFormat)
? requestedFormat
: ((user && user.profile && user.profile.dateFormat) || 'YYYY-MM-DD');
// #6586: the reader's IANA zone, sent by the export link. Without it the
// dates come out in the server's zone, which is the "-2h wrong for
// Europe/Berlin" the PDF export was reported for and this export shared.
const timezone = (req.query && typeof req.query.tz === 'string' && req.query.tz.length <= 64)
? req.query.tz
: '';
// Parse optional ?fields=people,dates,... query param
const fieldsParam = req.query.fields;
const fields = fieldsParam
? fieldsParam.split(',').map(f => f.trim()).filter(f => ALL_FIELDS.includes(f))
: null;
const exporter = new ExporterExcelCard(boardId, paramListId, paramCardId, userLanguage, fields, dateFormat, timezone);
if ((await exporter.canExport(user))) {
if (impersonateDone) {
await ImpersonatedUsers.insertAsync({
adminId,
boardId,
reason: 'exportExcelCard',
});
}
await exporter.build(res);
} else {
res.writeHead(403, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(TAPi18n.__('user-can-not-export-card-to-excel'));
}
}),
);
});