Skip to content

Commit

Permalink
Merge pull request #1466 from bartbutenaers/sanetize-href-target-fix
Browse files Browse the repository at this point in the history
Sanetize 'target' attr fix
  • Loading branch information
joepavitt authored Dec 4, 2024
2 parents 85a9cf1 + 536952d commit 1d1a397
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ui/src/widgets/ui-text/UIText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export default {
},
computed: {
...mapState('data', ['messages', 'properties']),
value () {
value: function () {
return this.textValue
},
label () {
// Sanetize the html to avoid XSS attacks
// Sanitize the html to avoid XSS attacks
return DOMPurify.sanitize(this.getProperty('label'))
},
layout () {
Expand Down Expand Up @@ -74,11 +74,7 @@ export default {
// make sure our v-model is updated to reflect the value from Node-RED
if (Object.prototype.hasOwnProperty.call(msg, 'payload')) {
// Sanitize the HTML to avoid XSS attacks
if (typeof msg.payload === 'string') {
this.textValue = DOMPurify.sanitize(msg.payload)
} else {
this.textValue = msg.payload
}
this.textValue = this.purify(msg.payload)
}
},
onLoad (msg) {
Expand All @@ -89,10 +85,17 @@ export default {
msg
})
if (Object.prototype.hasOwnProperty.call(msg, 'payload')) {
// Sanitize the HTML to avoid XSS attacks
this.textValue = DOMPurify.sanitize(msg.payload)
// Sanitize the HTML to avoid XSS attacks
this.textValue = this.purify(msg.payload)
}
}
},
purify (payload) {
if (typeof payload === 'string') {
return DOMPurify.sanitize(payload, { ADD_ATTR: ['target'] })
} else {
return payload
}
}
}
}
Expand Down

0 comments on commit 1d1a397

Please sign in to comment.