fcsc_ipi_backend/app/utils/sanitize.js
2025-12-08 17:52:44 +05:30

21 lines
528 B
JavaScript

const sanitize = require("sanitize-html");
exports.sanitizeHtml = (html = "") => {
return sanitize(html, {
allowedTags: sanitize.defaults.allowedTags.concat(["img"]),
allowedAttributes: {
"*": ["style", "class"],
img: ["src", "alt"]
},
disallowedTagsMode: "discard"
});
};
exports.sanitizeForLog = (value) => {
if (typeof value !== "string") return value;
return value
.replace(/[\r\n]+/g, " ")
.replace(/\t+/g, " ")
.replace(/[^\x20-\x7E]+/g, " ");
};