Files
wekan/models/lib/attachmentUploadAuth.js
T
Lauri Ojansivu 51111e1958 StampBleed and UploadBleed: documents on one's own card stamped with another board, and unauthorized attachment uploads.
StampBleed (found reviewing the patch for #6813): checklists, checklist
items and text notes carry a denormalized boardId, by which the board
publication publishes them, and items a checklistId, by which a
checklist draws them. The insert allow rules check write access on the
document's card only, and the server's insert hooks kept a boardId the
client sent. So a member of any board could insert, on their own card,
a document stamped with a private board's id - published to that
board's members - and an item with that board's checklist id, drawn in
it. 4bd6a7f088 made the server take boardId from the card; now the
forged insert is refused outright and recorded, for those three and for
a direct attachment insert with a foreign meta.boardId. WeKan's own
client never sends a mismatch.

UploadBleed: Meteor-Files' upload pipeline (_FilesCollectionStart_
attachments / Write and its HTTP twin) inserts the stored attachment
SERVER-side, so the allow rules were never asked, and the attachments'
onBeforeUpload only cleaned the file name: any DDP client, signed in or
not, could put a file on any card of any board - published to its
members with an addAttachment activity and its notifications - and the
admin's uploads-blocked switch was skipped too. The upload is
authorized on every chunk now: signed in, allowed to edit the card (or
write the board, for a background or map image), uploads not blocked,
and a card attachment's board, list and swimlane are its card's.

Both are recorded in Admin Panel / Problems (authz.card-child-stamp,
authz.attachment-upload), once per upload. tests/stampBleed.test.cjs and
tests/uploadBleed.test.cjs run the real decisions, and fail on a card
child with no insert board check or a FilesCollection without a server
upload check; upload-stamp-bleed.e2e.js attacks the running server.

Thanks to xet7 !
2026-10-27 15:38:58 +02:00

42 lines
2.5 KiB
JavaScript

'use strict';
// UploadBleed: who may upload an attachment through Meteor-Files' own upload
// pipeline (_FilesCollectionStart_attachments / Write, and its HTTP twin).
// That pipeline inserts the stored document SERVER-side, so the collection's
// allow rules (server/permissions/attachments.js) are never asked: the only
// gate is the collection's onBeforeUpload, which used to sanitize the file
// name and return true. Any DDP client, signed in or not, could put a file on
// any card of any board - published to that board's members, with an
// addAttachment activity and its notifications - and choose its meta.boardId
// freely (StampBleed). models/attachments.server.js asks this on every chunk.
//
// Pure: the caller looks up the card and the board and asks the permission
// helpers; this decides. Returns { allow, reason, key, stamp }:
// key - the security catalog key to record when it is an attempt (null
// when a legitimate user can reach the refusal, e.g. uploads off);
// stamp - for a card attachment, the card's own board, list and swimlane,
// written over whatever the client sent.
function uploadDecision({ userId, meta, card, mayEditCard, board, mayWriteBoard, uploadsBlocked }) {
const m = meta && typeof meta === 'object' ? meta : {};
if (uploadsBlocked) return { allow: false, reason: 'Uploads are turned off.', key: null };
if (!userId) return { allow: false, reason: 'Please sign in to upload.', key: 'authz.attachment-upload' };
if (typeof m.cardId === 'string' && m.cardId) {
// A card deleted while its upload started is not an attempt.
if (!card) return { allow: false, reason: 'Card not found.', key: null };
if (!mayEditCard) return { allow: false, reason: 'You cannot add attachments to this card.', key: 'authz.attachment-upload' };
if (typeof m.boardId === 'string' && m.boardId && m.boardId !== card.boardId) {
return { allow: false, reason: 'You cannot add attachments to this card.', key: 'authz.card-child-stamp' };
}
return { allow: true, stamp: { boardId: card.boardId, listId: card.listId, swimlaneId: card.swimlaneId } };
}
// A board's own image (background, map): write access on that board.
if (typeof m.boardId !== 'string' || !m.boardId || !board) {
return { allow: false, reason: 'Board not found.', key: m.boardId ? null : 'authz.attachment-upload' };
}
if (!mayWriteBoard) return { allow: false, reason: 'You cannot add images to this board.', key: 'authz.attachment-upload' };
return { allow: true, stamp: null };
}
module.exports = { uploadDecision };