mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
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 !
170 lines
7.1 KiB
JavaScript
170 lines
7.1 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) {
|
|
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) {
|
|
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');
|
|
}
|
|
}));
|
|
});
|