mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
49 lines
1.8 KiB
JavaScript
49 lines
1.8 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 DOMPurify 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) {
|
|
require('/server/lib/securityLog').record({
|
|
category: 'Import/export validation',
|
|
bleed: 'ImportExportValidation',
|
|
severity: 'high',
|
|
action: 'blocked',
|
|
source: context.source || `${context.direction || 'import'}:unknown`,
|
|
userId: context.userId,
|
|
username: context.username,
|
|
ip: context.ip,
|
|
detail: error && error.message,
|
|
});
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export default secureTransfer;
|