mirror of
https://github.com/screentinker/screentinker.git
synced 2026-05-15 07:32:23 -06:00
ScreenTinker - open source digital signage management software. MIT License, all features included, no license gates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26 lines
673 B
JavaScript
26 lines
673 B
JavaScript
// Simple XSS sanitizer for user input strings
|
|
function sanitizeString(str) {
|
|
if (typeof str !== 'string') return str;
|
|
return str
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''');
|
|
}
|
|
|
|
// Middleware: sanitize common body fields
|
|
function sanitizeBody(req, res, next) {
|
|
if (req.body) {
|
|
const fieldsToSanitize = ['name', 'title', 'filename'];
|
|
for (const field of fieldsToSanitize) {
|
|
if (typeof req.body[field] === 'string') {
|
|
req.body[field] = sanitizeString(req.body[field]);
|
|
}
|
|
}
|
|
}
|
|
next();
|
|
}
|
|
|
|
module.exports = { sanitizeString, sanitizeBody };
|