mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
secureTransfer recorded every throw as a high "blocked" event naming the user, and that disables the account. sanitize-html 2.18.0 threw RangeError on nested <iframe>, so a card planted with the payload locked out the next member who exported the board; any library fault would do the same. The transfer boundary now marks its own refusals (TransferBoundaryError: a cycle, a non-plain object, a size limit), and models/lib/transferFailure.cjs records only those as blocked - high, and medium for a size limit as before. Anything else is ImportExportFailure: detected, still naming whose import or export it was, and never blocking an account. tests/transferFailure.test.cjs drives real boundary refusals and a sanitizer that throws through blockOnSecurityEvent's own decision; with the old secureTransfer it fails. It also fails if the boundary throws a plain Error or anything but secureTransfer calls it. Thanks to xet7 !
49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// What server/lib/secureTransfer.js records when an import or export throws.
|
|
//
|
|
// Only the transfer boundary's own refusals (models/lib/importExportBoundary.js
|
|
// marks them name 'TransferBoundaryError') are an ATTEMPT, and are recorded as
|
|
// blocked: a cycle or a non-plain object is not something an export produces,
|
|
// so it is high, and a size limit - which a large real board reaches too - is
|
|
// medium. Anything else is the code failing, not the user trying something:
|
|
// sanitize-html 2.18.0 threw RangeError on nested <iframe>, and recording that
|
|
// as a high "blocked" event disabled the account of whoever exported a board
|
|
// someone else had planted the payload in. It is recorded as detected, so an
|
|
// administrator still sees it, and never blocks an account.
|
|
|
|
function isTransferBoundaryError(error) {
|
|
return Boolean(error) && error.name === 'TransferBoundaryError';
|
|
}
|
|
|
|
function transferFailureEvent(error, context = {}) {
|
|
const base = {
|
|
category: 'Import/export validation',
|
|
source: context.source || `${context.direction || 'import'}:unknown`,
|
|
userId: context.userId,
|
|
username: context.username,
|
|
ip: context.ip,
|
|
};
|
|
if (isTransferBoundaryError(error)) {
|
|
return {
|
|
...base,
|
|
bleed: 'ImportExportValidation',
|
|
severity: error.kind === 'limit' ? 'medium' : 'high',
|
|
action: 'blocked',
|
|
detail: error.message,
|
|
};
|
|
}
|
|
const name = (error && error.name) || 'Error';
|
|
const message = (error && error.message) || String(error);
|
|
return {
|
|
...base,
|
|
bleed: 'ImportExportFailure',
|
|
severity: 'medium',
|
|
action: 'detected',
|
|
blocksAccount: false,
|
|
detail: `${name}: ${message}`.slice(0, 200),
|
|
};
|
|
}
|
|
|
|
module.exports = { isTransferBoundaryError, transferFailureEvent };
|