Skip to content

Commit 1d1a397

Browse files
authored
Merge pull request #1466 from bartbutenaers/sanetize-href-target-fix
Sanetize 'target' attr fix
2 parents 85a9cf1 + 536952d commit 1d1a397

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ui/src/widgets/ui-text/UIText.vue

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export default {
2626
},
2727
computed: {
2828
...mapState('data', ['messages', 'properties']),
29-
value () {
29+
value: function () {
3030
return this.textValue
3131
},
3232
label () {
33-
// Sanetize the html to avoid XSS attacks
33+
// Sanitize the html to avoid XSS attacks
3434
return DOMPurify.sanitize(this.getProperty('label'))
3535
},
3636
layout () {
@@ -74,11 +74,7 @@ export default {
7474
// make sure our v-model is updated to reflect the value from Node-RED
7575
if (Object.prototype.hasOwnProperty.call(msg, 'payload')) {
7676
// Sanitize the HTML to avoid XSS attacks
77-
if (typeof msg.payload === 'string') {
78-
this.textValue = DOMPurify.sanitize(msg.payload)
79-
} else {
80-
this.textValue = msg.payload
81-
}
77+
this.textValue = this.purify(msg.payload)
8278
}
8379
},
8480
onLoad (msg) {
@@ -89,10 +85,17 @@ export default {
8985
msg
9086
})
9187
if (Object.prototype.hasOwnProperty.call(msg, 'payload')) {
92-
// Sanitize the HTML to avoid XSS attacks
93-
this.textValue = DOMPurify.sanitize(msg.payload)
88+
// Sanitize the HTML to avoid XSS attacks
89+
this.textValue = this.purify(msg.payload)
9490
}
9591
}
92+
},
93+
purify (payload) {
94+
if (typeof payload === 'string') {
95+
return DOMPurify.sanitize(payload, { ADD_ATTR: ['target'] })
96+
} else {
97+
return payload
98+
}
9699
}
97100
}
98101
}

0 commit comments

Comments
 (0)