Skip to content

Commit

Permalink
Task-56304 : XSS issue in chat
Browse files Browse the repository at this point in the history
Before this fix, when sending a message with a mention, there is an XSS issue
This commit encode html entities in the message before adding markup related to the mention so that, the malicious html is not evaluated
  • Loading branch information
rdenarie committed Apr 15, 2022
1 parent e351e3a commit 26bf307
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export default {
checkMention(message) {
message = $('<div />').html(message).text();
message = message.replace(/\s\s+/g, ' ');
message = this.encodeHTMLEntities(message);
for (let i = 0; i < this.participants.length; i++) {
if (message.includes(`@${this.participants[i].fullname}`) ){
this.mentionedUsers.push(this.participants[i].name);
Expand All @@ -352,6 +353,11 @@ export default {
this.mentionedUsers = [];
return message;
},
encodeHTMLEntities(text) {
const textArea = document.createElement('p');
textArea.innerText = text;
return textArea.innerHTML;
},
paste(e) {
// consider the first item (can be easily extended for multiple items)
const item = e.clipboardData.items[0];
Expand All @@ -367,11 +373,11 @@ export default {
// cancel paste
e.preventDefault();
// get text representation of clipboard
this.text = (e.originalEvent || e).clipboardData.getData('text/plain');
this.text = this.encodeHTMLEntities((e.originalEvent || e).clipboardData.getData('text/plain'));
// insert text manually
$(this.$refs.messageComposerArea).insertAtCaret(this.text);
}
},
}
};
</script>
</script>

0 comments on commit 26bf307

Please sign in to comment.