sanitize review input

This commit is contained in:
2025-12-25 11:20:38 +03:30
parent 9f7c695ed1
commit b18f9b0222
4 changed files with 214 additions and 5 deletions
+20
View File
@@ -0,0 +1,20 @@
import sanitizeHtml from 'sanitize-html';
/**
* Sanitizes user input to prevent XSS attacks and remove malicious content
* Allows only safe text content, removing all HTML tags and scripts
* @param input - The string to sanitize
* @returns Sanitized string with all HTML tags and scripts removed
*/
export function sanitizeText(input: string | undefined | null): string | undefined | null {
if (!input) {
return input;
}
return sanitizeHtml(input, {
allowedTags: [], // No HTML tags allowed
allowedAttributes: {}, // No attributes allowed
allowedSchemes: [], // No URL schemes allowed
}).trim();
}