diff --git a/src/components/OpenwbPageMessages.vue b/src/components/OpenwbPageMessages.vue index 48c46c3f..232b55a8 100644 --- a/src/components/OpenwbPageMessages.vue +++ b/src/components/OpenwbPageMessages.vue @@ -52,7 +52,7 @@ @dismiss="dismissMessage" @hide="hideMessage" > - + @@ -179,6 +179,32 @@ export default { this.hiddenMessages.push(event.topic); } }, + /** + * Sanitize HTML message to allow only safe tags like links and line breaks + */ + sanitizeMessage(message) { + if (!message) return ''; + + // Escape all HTML first + const escaped = message + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + + // Then allow specific safe tags back + return escaped + // Allow
tags + .replace(/<br\s*\/?>/gi, '
') + // Allow tags with href and target attributes + .replace(/<a\s+href="([^&"]+)"(?:\s+target="([^&"]+)")?>([^&]+)<\/a>/gi, + '$3') + // Allow and tags + .replace(/<(strong|b)>([^&]+)<\/(strong|b)>/gi, '<$1>$2') + // Allow and tags + .replace(/<(em|i)>([^&]+)<\/(em|i)>/gi, '<$1>$2'); + }, }, };