Skip to content

Commit 76ed46e

Browse files
authored
Merge pull request from GHSA-f5ww-cq3m-q3g7
Escape `</` to prevent a style element from being closed prematurely
2 parents a92f21c + 3481ac3 commit 76ed46e

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

HISTORY.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Sanitize History
22

3+
## 6.0.2 (2023-07-06)
4+
5+
### Bug Fixes
6+
7+
* CVE-2023-36823: Fixed an HTML+CSS sanitization bypass that could allow XSS
8+
(cross-site scripting). This issue affects Sanitize versions 3.0.0 through
9+
6.0.1.
10+
11+
When using Sanitize's relaxed config or a custom config that allows `<style>`
12+
elements and one or more CSS at-rules, carefully crafted input could be used
13+
to sneak arbitrary HTML through Sanitize.
14+
15+
See the following security advisory for additional details:
16+
[GHSA-f5ww-cq3m-q3g7](https://github.com/rgrove/sanitize/security/advisories/GHSA-f5ww-cq3m-q3g7)
17+
18+
Thanks to @cure53 for finding this issue.
19+
320
## 6.0.1 (2023-01-27)
421

522
### Bug Fixes

lib/sanitize/transformers/clean_css.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def call(env)
4848
if css.strip.empty?
4949
node.unlink
5050
else
51+
css.gsub!('</', '<\/')
5152
node.children.unlink
5253
node << Nokogiri::XML::Text.new(css, node.document)
5354
end

lib/sanitize/version.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
class Sanitize
4-
VERSION = '6.0.1'
2+
VERSION = '6.0.2'
53
end

test/test_malicious_css.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,17 @@
3939
it 'should not allow behaviors' do
4040
_(@s.properties(%[behavior: url(xss.htc);])).must_equal ''
4141
end
42+
43+
describe 'sanitization bypass via CSS at-rule in HTML <style> element' do
44+
before do
45+
@s = Sanitize.new(Sanitize::Config::RELAXED)
46+
end
47+
48+
it 'is not possible to prematurely end a <style> element' do
49+
assert_equal(
50+
%[<style>@media<\\/style><iframe srcdoc='<script>alert(document.domain)<\\/script>'>{}</style>],
51+
@s.fragment(%[<style>@media</sty/**/le><iframe srcdoc='<script>alert(document.domain)</script>'></style>])
52+
)
53+
end
54+
end
4255
end

0 commit comments

Comments
 (0)