Skip to content

Commit

Permalink
Merge pull request #1218 from basecamp/refactor-xss-fix
Browse files Browse the repository at this point in the history
Refactor link XSS patch
  • Loading branch information
intrip authored Dec 20, 2024
2 parents 180c8d3 + c707f41 commit c4f0d6f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/trix/controllers/toolbar_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,20 @@ export default class ToolbarController extends BasicObject {
const attributeName = getAttributeName(dialogElement)
const input = getInputForDialog(dialogElement, attributeName)

input.willValidate && input.setCustomValidity("")
if (input.willValidate && !input.checkValidity() || !this.safeAttribute(input)) {
input.setCustomValidity("Invalid value")
input.setAttribute("data-trix-validate", "")
input.classList.add("trix-validate")
return input.focus()
} else {
this.delegate?.toolbarDidUpdateAttribute(attributeName, input.value)
return this.hideDialog()
if (input.willValidate) {
input.setCustomValidity("")
if (!input.checkValidity() || !this.isSafeAttribute(input)) {
input.setCustomValidity("Invalid value")
input.setAttribute("data-trix-validate", "")
input.classList.add("trix-validate")
return input.focus()
}
}
this.delegate?.toolbarDidUpdateAttribute(attributeName, input.value)
return this.hideDialog()
}

safeAttribute(input) {
isSafeAttribute(input) {
if (input.hasAttribute("data-trix-validate-href")) {
return DOMPurify.isValidAttribute("a", "href", input.value)
} else {
Expand Down

0 comments on commit c4f0d6f

Please sign in to comment.