Files
wekan/models/lib/boardCopyProperties.js
T
Lauri Ojansivu 94931c7ab6 Refuse board-copy properties that could replace the source board's identity.
copyBoard assigned every caller-supplied property onto the source board
object, including _id. board.copy() loads the source lists, cards and
children by this._id, so an admin of any board could pass a private
board's _id and receive a full copy of a board they cannot see - the
board-level form of CopyIdentityBleed. Only title, sort, type,
withoutCards and copyOptions are accepted now, each type-checked, and they
are applied to a separate object, so the cached source board is never
changed. Any other field is refused before anything is read and recorded
as CopyIdentityBleed in Admin Panel -> Problems; a wrong type on a
supported field is an ordinary input error without an attack record. The
REST copy route takes only a string title, on a separate object.

A unit test covers the contract, and a source scan fails if caller input is
assigned onto the source board or the source board object is copied again.
The browser spec reproduces the disclosure and checks the refusal, the
Problems record, that malformed input blocks nobody, and that supported
copies still work.

Thanks to xet7 !
2026-09-29 15:12:12 +03:00

46 lines
2.0 KiB
JavaScript

'use strict';
// What a board-copy caller may change on the copy: its title, sort position,
// board type (a template may become a board) and whether cards are copied.
// Everything else - above all _id, which board.copy() uses to load the source
// lists, cards and children - belongs to the authorized source board. Mirrors
// models/lib/cardCopyOverrides.js (CopyIdentityBleed).
const CHECKS = {
title: value => typeof value === 'string',
sort: value => typeof value === 'number' && Number.isFinite(value),
type: value => value === 'board' || value === 'template-board',
withoutCards: value => typeof value === 'boolean',
// Validated separately by normalizeBoardCopyOptions.
copyOptions: () => true,
};
function boardCopyProperties(values) {
if (!values || typeof values !== 'object' || Array.isArray(values) ||
Object.getPrototypeOf(values) !== Object.prototype) {
const error = new Error('Invalid board copy properties');
error.securityAttempt = false;
throw error;
}
const unknown = Object.keys(values).filter(key => !Object.prototype.hasOwnProperty.call(CHECKS, key));
const malformed = Object.keys(values).filter(key => CHECKS[key] && values[key] !== undefined && !CHECKS[key](values[key]));
if (unknown.length || malformed.length) {
const error = new Error('Invalid board copy properties');
// Only fields outside the contract are an attempt; a wrong type on a
// supported field is an ordinary input error.
error.securityAttempt = unknown.length > 0;
throw error;
}
const clean = {};
for (const key of Object.keys(values)) if (values[key] !== undefined) clean[key] = values[key];
return clean;
}
// The board to copy, with the caller's supported changes applied to a
// separate object: the cached source board, and its _id, stay untouched.
function boardWithCopyProperties(board, values) {
const { withoutCards, copyOptions, ...fields } = values;
return Object.assign(Object.create(Object.getPrototypeOf(board)), board, fields);
}
module.exports = { boardCopyProperties, boardWithCopyProperties };