Skip to content

Commit

Permalink
Remove dompurify
Browse files Browse the repository at this point in the history
To avoid issues with integrating DOMPurify we'll remove it from
the 1.3 branch. Instead update the HTMLSanitizer to remove the
embed and math elements to fix the reported XSS attacks.
  • Loading branch information
djmb committed Dec 11, 2024
1 parent f7f9405 commit 55ed093
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 604 deletions.
1 change: 0 additions & 1 deletion .blade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ load_paths:
- test/vendor
- assets
- polyfills
- vendor
- src

logical_paths:
Expand Down
1 change: 0 additions & 1 deletion assets/trix-core.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#= require trix/banner
#= require trix/index
#= require vendor
1 change: 0 additions & 1 deletion assets/trix.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#= require trix/banner
#= require polyfills
#= require trix/index
#= require vendor
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"assets",
"bin",
"polyfills",
"vendor",
"src",
"test",
"*.md",
Expand Down
20 changes: 7 additions & 13 deletions dist/trix-core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/trix.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@charset "UTF-8";
/*
Trix 1.3.2
Trix 1.3.4
Copyright © 2024 Basecamp, LLC
http://trix-editor.org/*/
trix-editor {
Expand Down
22 changes: 8 additions & 14 deletions dist/trix.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
"url": "https://github.com/basecamp/trix/issues"
},
"homepage": "https://trix-editor.org/",
"dependencies": {
"dompurify": "^3.2.3"
},
"devDependencies": {
"@babel/core": "^7.17.8",
"@babel/preset-env": "^7.26.0",
"svgo": "^0.6.1"
}
}
1 change: 0 additions & 1 deletion src/trix/inspector/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#= require ./control_element
#= require_tree ./templates
#= require_tree ./views
#= require_tree ./vendor

Trix.Inspector =
views: []
Expand Down
3 changes: 1 addition & 2 deletions src/trix/models/html_sanitizer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Trix.HTMLSanitizer extends Trix.BasicObject
DEFAULT_ALLOWED_ATTRIBUTES = "style href src width height class".split(" ")
DEFAULT_FORBIDDEN_PROTOCOLS = "javascript:".split(" ")
DEFAULT_FORBIDDEN_ELEMENTS = "script iframe noscript".split(" ")
DEFAULT_FORBIDDEN_ELEMENTS = "script iframe form noscript embed math".split(" ")

@setHTML = (element, html) ->
sanitizer = new this html
Expand All @@ -25,7 +25,6 @@ class Trix.HTMLSanitizer extends Trix.BasicObject
sanitize: ->
@sanitizeElements()
@normalizeListElementNesting()
DOMPurify.sanitize @body, ADD_ATTR: ["language"], RETURN_DOM: true

getHTML: ->
@body.innerHTML
Expand Down
1 change: 0 additions & 1 deletion test/.blade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ load_paths:
- vendor
- ../assets
- ../polyfills
- ../vendor
- ../src

build:
Expand Down
4 changes: 2 additions & 2 deletions test/src/system/pasting_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ testGroup "Pasting", template: "editor_empty", ->
window.unsanitized = []
pasteData =
"text/plain": "x",
"text/html": "copy<div data-trix-attachment=\"{&quot;contentType&quot;:&quot;text/html5&quot;,&quot;content&quot;:&quot;&lt;math&gt;&lt;mtext&gt;&lt;table&gt;&lt;mglyph&gt;&lt;style&gt;&lt;img src=x onerror=alert()&gt;&lt;/style&gt;XSS POC&quot;}\"></div>me"
"text/html": "copy<div data-trix-attachment=\"{&quot;contentType&quot;:&quot;text/html5&quot;,&quot;content&quot;:&quot;&lt;math&gt;&lt;mtext&gt;&lt;table&gt;&lt;mglyph&gt;&lt;style&gt;&lt;img src=x onerror=window.unsanitized.push(1)&gt;&lt;/style&gt;XSS POC&quot;}\"></div>me"

pasteContent pasteData, ->
after 20, ->
Expand All @@ -93,7 +93,7 @@ testGroup "Pasting", template: "editor_empty", ->
window.unsanitized = []
pasteData =
"text/plain": "x",
"text/html": "copy<div data-trix-attachment=\"{&quot;contentType&quot;:&quot;text/html5&quot;,&quot;content&quot;:&quot;&lt;embed src='javascript:alert(1)'&gt;XSS POC&quot;}\"></div>me"
"text/html": "copy<div data-trix-attachment=\"{&quot;contentType&quot;:&quot;text/html5&quot;,&quot;content&quot;:&quot;&lt;embed src='window.unsanitized.push(1)'&gt;XSS POC&quot;}\"></div>me"

pasteContent pasteData, ->
after 20, ->
Expand Down
3 changes: 0 additions & 3 deletions vendor/dompurify-banner/index.coffee.erb

This file was deleted.

4 changes: 0 additions & 4 deletions vendor/dompurify-banner/index.txt.erb

This file was deleted.

553 changes: 0 additions & 553 deletions vendor/dompurify.js

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/vendor.coffee

This file was deleted.

0 comments on commit 55ed093

Please sign in to comment.