Files
wekan/server/lib/secureTransfer.js
T
Lauri Ojansivu 9d323f2aaf Stop disabling legitimate users: Problems records only attempts, or never block, where ordinary use reaches them.
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 !
2026-10-02 10:44:08 +03:00

54 lines
2.2 KiB
JavaScript

import { sanitizeTransferValue } from '/models/lib/importExportBoundary';
import { sanitizeInput } from '/server/lib/inputSanitizer';
// Server wrapper around the pure structural boundary. This is deliberately the
// only place that couples transfer validation to server HTML sanitization and Admin Problems,
// so every adapter records blocked and sanitized attempts consistently.
export function secureTransfer(value, context = {}) {
try {
const result = sanitizeTransferValue(value, {
direction: context.direction || 'import',
sanitizeHtml: sanitizeInput,
maxDepth: context.maxDepth,
maxNodes: context.maxNodes,
maxArray: context.maxArray,
maxString: context.maxString,
maxBinaryString: context.maxBinaryString,
});
if (result.warnings.length) {
require('/server/lib/securityLog').record({
category: 'Import/export validation',
bleed: 'ImportExportSanitization',
severity: 'warning',
action: 'sanitized',
source: context.source || `${context.direction || 'import'}:unknown`,
userId: context.userId,
username: context.username,
ip: context.ip,
detail: `${result.warnings.length} unsafe value(s): ${result.warnings.slice(0, 5).map(w => `${w.path} ${w.reason}`).join('; ')}`,
});
}
return result.value;
} catch (error) {
// A size limit (too many objects, too deep, a string or array too long) is
// reached by a legitimate large board too, so it is recorded at medium -
// high with the importer's userId disabled their account. A cycle or a
// non-plain object is not something an export produces: still high.
const limitOnly = /limit exceeded/.test(String(error && error.message));
try { require('/server/lib/securityLog').record({
category: 'Import/export validation',
bleed: 'ImportExportValidation',
severity: limitOnly ? 'medium' : 'high',
action: 'blocked',
source: context.source || `${context.direction || 'import'}:unknown`,
userId: context.userId,
username: context.username,
ip: context.ip,
detail: error && error.message,
}); } catch (e) { /* logging must never break the guard */ }
throw error;
}
}
export default secureTransfer;