Merge pull request #398 from kazuki-hanai/escape-html

Fix: Add HTML escaping to dashboard log messages
This commit is contained in:
Michael Panchenko authored and GitHub committed 2025-08-03 13:12:25 +02:00
commit 186737a3f5
1 file changed
+16
@@ -1,5 +1,6 @@
class LogMessage {
constructor(message, toolNames) {
message = this.escapeHtml(message);
const logLevel = this.determineLogLevel(message);
const highlightedMessage = this.highlightToolNames(message, toolNames);
this.$elem = $('<div>').addClass('log-' + logLevel).html(highlightedMessage + '\n');
@@ -27,6 +28,21 @@ class LogMessage {
});
return highlightedMessage;
}
escapeHtml (convertString) {
if (typeof convertString !== 'string') return convertString;
const patterns = {
'<' : '&lt;',
'>' : '&gt;',
'&' : '&amp;',
'"' : '&quot;',
'\'' : '&#x27;',
'`' : '&#x60;'
};
return convertString.replace(/[<>&"'`]/g, match => patterns[match]);
};
}
class Dashboard {