Skip to content

Commit

Permalink
24.08.1 hotfix: sanitize chat input [WTEL-5195]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Oct 1, 2024
1 parent 0921435 commit fd3e2f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
45 changes: 38 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omnichannel-widget",
"version": "24.08.0",
"version": "24.08.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -18,7 +18,9 @@
"axios": "^0.27.2",
"core-js": "^3.6.5",
"deepmerge": "^4.2.2",
"dompurify": "^3.1.7",
"emoji-picker-element": "^1.11.3",
"he": "^1.2.0",
"insert-text-at-cursor": "^0.3.0",
"jssip": "^3.10.0",
"linkifyjs": "^3.0.0-beta.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<script>
import linkifyHtml from 'linkifyjs/html';
import dompurify from 'dompurify';
import he from 'he';
export default {
name: 'message-text',
Expand All @@ -18,7 +20,7 @@ export default {
},
computed: {
parsedText() {
return linkifyHtml(this.text, {
return linkifyHtml(he.encode(dompurify.sanitize(this.text)), {
target: '_blank',
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
:placeholder="$t('chat.inputPlaceholder')"
:value="draft"
class="wt-omni-widget-chat-input__textarea"
@input="setDraft($event.target.value)"
@keypress.enter.prevent="handleEnter"
@input="handleInput($event.target.value)"
@keypress.enter="handleEnter"
></textarea>
</div>
<chat-footer-actions
Expand All @@ -22,6 +22,7 @@

<script>
import autosize from 'autosize';
import dompurify from 'dompurify';
import insertTextAtCursor from 'insert-text-at-cursor';
import { mapActions, mapState } from 'vuex';
import ChatFooterActions from './chat-footer-actions.vue';
Expand Down Expand Up @@ -49,10 +50,13 @@ export default {
return dispatch(`${this.namespace}/SET_DRAFT`, payload);
},
}),
handleInput(value) {
const purifiedValue = dompurify.sanitize(value);
this.setDraft(purifiedValue);
},
handleEnter(event) {
if (event.shiftKey || event.ctrlKey) {
this.setDraft(this.draft.concat('\n'));
} else {
if (!event.shiftKey && !event.ctrlKey) {
event.preventDefault();
this.sendDraft(event);
}
},
Expand Down

0 comments on commit fd3e2f9

Please sign in to comment.