mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-15 12:14:52 +00:00
Fix: Add HTML escaping to dashboard log messages
Escape special HTML characters in log messages to prevent XSS vulnerabilities and ensure proper display of code snippets containing HTML tags.
This commit is contained in:
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 = {
|
||||
'<' : '<',
|
||||
'>' : '>',
|
||||
'&' : '&',
|
||||
'"' : '"',
|
||||
'\'' : ''',
|
||||
'`' : '`'
|
||||
};
|
||||
|
||||
return convertString.replace(/[<>&"'`]/g, match => patterns[match]);
|
||||
};
|
||||
}
|
||||
|
||||
class Dashboard {
|
||||
|
||||
Reference in new issue
Block a user