/** * HTML entity encoding map for XSS prevention */ const HTML_ENTITY_MAP: Record = { '<': '<', '>': '>', '&': '&', '"': '"', "'": ''', } /** * Escape HTML entities in a string value to prevent XSS attacks. * * Converts dangerous characters to their HTML entity equivalents: * - < becomes < * - > becomes > * - & becomes & * - " becomes " * - ' becomes ' * * @param value - The string value to sanitize * @returns The sanitized string with HTML entities escaped */ export function escapeHtmlEntities(value: string): string { return value.replace(/[<>&"']/g, char => HTML_ENTITY_MAP[char]) }