sanitize 6.1.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{HISTORY.md → CHANGELOG.md} +90 -14
- data/LICENSE +3 -1
- data/README.md +130 -240
- data/lib/sanitize/config/basic.rb +15 -15
- data/lib/sanitize/config/default.rb +45 -45
- data/lib/sanitize/config/relaxed.rb +136 -32
- data/lib/sanitize/config/restricted.rb +2 -2
- data/lib/sanitize/config.rb +11 -15
- data/lib/sanitize/css.rb +410 -283
- data/lib/sanitize/transformers/clean_cdata.rb +9 -9
- data/lib/sanitize/transformers/clean_comment.rb +44 -8
- data/lib/sanitize/transformers/clean_css.rb +59 -55
- data/lib/sanitize/transformers/clean_doctype.rb +17 -13
- data/lib/sanitize/transformers/clean_element.rb +284 -231
- data/lib/sanitize/version.rb +3 -1
- data/lib/sanitize.rb +38 -39
- metadata +17 -56
- data/test/common.rb +0 -3
- data/test/test_clean_comment.rb +0 -47
- data/test/test_clean_css.rb +0 -67
- data/test/test_clean_doctype.rb +0 -71
- data/test/test_clean_element.rb +0 -552
- data/test/test_config.rb +0 -65
- data/test/test_malicious_css.rb +0 -55
- data/test/test_malicious_html.rb +0 -339
- data/test/test_parser.rb +0 -75
- data/test/test_sanitize.rb +0 -197
- data/test/test_sanitize_css.rb +0 -424
- data/test/test_transformers.rb +0 -230
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9dcbdd9a00a2f80ddded816eb9b52215365ae34ec23e99f0d31b2a2b11757b49
|
|
4
|
+
data.tar.gz: 38be6ac4c8215e558b4b1f4c8ae2eb570f6225a6473964b52ffbcb49c2806779
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d802d1606fa2a8cb2056125d26092ef056146252c38ff55a086776c35eda10b70c63882f7b473656f4ea5cf18dfc9864e1e2bc6d257b204a1072568a5a65d440
|
|
7
|
+
data.tar.gz: 0f64bb78dd9c4b2dca863530c02a08559c36ed9ec761c0d3f3b1d81fef3b1eefe39e7632d0354eaf75b49b5e755c0e0191f92b6fb6a669255fd48bde2df332d7
|
data/{HISTORY.md → CHANGELOG.md}
RENAMED
|
@@ -1,4 +1,82 @@
|
|
|
1
|
-
# Sanitize
|
|
1
|
+
# Sanitize Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to Sanitize are documented in this file. The format (since version 7.0.0) is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
|
+
|
|
5
|
+
## 7.0.2 (2026-11-02)
|
|
6
|
+
|
|
7
|
+
### Security
|
|
8
|
+
|
|
9
|
+
- MathML and SVG elements whose `<math>` or `<svg>` ancestor has been removed are now also removed (keeping their contents, subject to `:remove_contents`), even if they're allowed by the config or have been allowlisted by a transformer. Previously, if Sanitize removed a `<math>` or `<svg>` element but kept its contents, its descendants were kept even though they'd been parsed as foreign elements, and browsers would reparse them as HTML elements. Since some elements are parsed very differently in foreign content than in HTML, this could allow arbitrary HTML to be injected. For example, the contents of a `<textarea>`, `<title>`, `<xmp>`, `<noembed>`, or `<noframes>` element inside a MathML or SVG element are parsed as markup rather than text, so an attribute value, comment, or raw text element inside it like `<svg><textarea><!--</textarea><img src=x onerror=alert(1)>-->` could close the element early once it was reparsed as HTML. Similarly, browsers that use legacy `<select>` parsing rules would parse the contents of a raw text element inside a `<select>` element like `<math><select><mi><xmp><input><img src=x onerror=alert(1)></xmp>` as markup. This only affected custom configs that don't remove the contents of `<math>` or `<svg>` elements and allow one of the affected elements. Sanitize's default and built-in configs aren't affected. Thanks to Mike Dalessio (@flavorjones) for reporting this issue. (GHSA-599p-54q3-ff89)
|
|
10
|
+
|
|
11
|
+
- Elements and comments inside text content elements such as `<textarea>`, `<title>`, `<xmp>`, `<noembed>`, and `<noframes>` are now always removed, even if they're allowed by the config or have been allowlisted by a transformer. Only their text is kept, subject to `:remove_contents`. This provides defense in depth against the issue above. (GHSA-599p-54q3-ff89)
|
|
12
|
+
|
|
13
|
+
- Sanitize now requires Nokogiri 1.19.7 or higher. Nokogiri versions since 1.19.5 escape `<` and `>` in serialized attribute values to match browser behavior, which provides defense in depth against the issue above. (GHSA-599p-54q3-ff89)
|
|
14
|
+
|
|
15
|
+
- Elements inside `<select>`, `<option>`, and `<optgroup>` elements that browsers using legacy `<select>` parsing rules wouldn't allow there are now always removed (keeping their contents, subject to `:remove_contents`), even if they're allowed by the config or have been allowlisted by a transformer. Previously, if Sanitize removed a `<template>` element inside a `<select>` element but kept its contents, any raw text element inside the `<template>` element would end up inside the `<select>` element. Browsers that use legacy `<select>` parsing rules ignore the start tags of raw text elements inside a `<select>` element and parse their contents as markup, so input like `<select><template><xmp><input><img src=x onerror=alert(1)></xmp>` could be used to inject arbitrary HTML. This only affected custom configs that allow `<select>` and at least one raw text element such as `<style>`, `<xmp>`, `<noembed>`, `<noframes>`, or `<plaintext>`. Sanitize's default and built-in configs aren't affected. (GHSA-mg79-gw37-jxx7)
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Ruby 3.2.0 is now the oldest supported Ruby version, since Nokogiri 1.19.x requires Ruby 3.2.0 or higher. Ruby 3.1 reached end of life in March 2025.
|
|
20
|
+
|
|
21
|
+
## 7.0.1 (2026-10-21)
|
|
22
|
+
|
|
23
|
+
### Security
|
|
24
|
+
|
|
25
|
+
- CSS properties that contain a `{}` block anywhere in their value are now removed. Browsers that support [CSS nesting](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_nesting) reparse an invalid declaration containing a `{}` block as a nested style rule, so a value like `color:hover{position:fixed}` could previously be used to smuggle disallowed properties and URLs past Sanitize in a stylesheet or `<style>` element. (GHSA-wgw9-qhqg-8hv5)
|
|
26
|
+
|
|
27
|
+
- The contents of at-rules such as `@media` and `@supports` that appear in a list of declarations (inside a style rule, inside an at-rule like `@font-face`, or in CSS sanitized with `Sanitize::CSS.properties`) are now sanitized as declarations rather than as rules, matching how browsers that support CSS nesting parse them. Previously, a stylesheet like `p{@media all{position:fixed;a{}}}` could be used to smuggle disallowed properties and URLs past Sanitize, since Sanitize treated `position:fixed;a` as a style rule's selector. The same was true of CSS sanitized with `Sanitize::CSS.properties` if the result was later embedded in a style rule. Style rules nested inside these at-rules are now removed, just as style rules nested directly inside other style rules already were. (GHSA-wgw9-qhqg-8hv5)
|
|
28
|
+
|
|
29
|
+
- CSS properties, style rules, and at-rules that contain blocks or functions nested more deeply than Crass's maximum nesting depth (25 levels by default) are now removed. (GHSA-wgw9-qhqg-8hv5)
|
|
30
|
+
|
|
31
|
+
- Hardened CSS sanitization against tokenizer differentials involving bad URLs. CSS properties that contain a bad URL anywhere inside a simple block (such as `[...]` or `(...)`) are now removed, as are style rules whose selectors contain a bad URL and at-rules whose preludes contain a bad URL. URLs inside simple blocks are now also validated against the configured protocol allowlist. Previously, a bug in Crass (fixed in Crass 1.0.8) could be exploited to smuggle CSS declarations, rules, or at-rules past Sanitize by hiding them in a bad URL in one of these locations.
|
|
32
|
+
|
|
33
|
+
- CSS style rules whose selectors contain a semicolon are now removed, as a defense in depth measure. A semicolon is never valid in a selector, but when a style rule appears where a browser that supports CSS nesting expects declarations, the browser treats everything before the semicolon as a declaration. This could be used to smuggle disallowed properties past `Sanitize::CSS.tree!` when it was given a list of declarations rather than a list of rules (though this isn't something Sanitize itself does).
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- Removed an unused `require "cgi"` that caused a warning on Ruby 4.0, since the CGI library is no longer part of Ruby's standard library.
|
|
38
|
+
|
|
39
|
+
## 7.0.0 (2024-12-29)
|
|
40
|
+
|
|
41
|
+
Sanitize has no breaking API changes in this release, but the major version number has been incremented because we've dropped support for end-of-life versions of Ruby. As long as you're using Ruby 3.1.0 or later, this should be a painless upgrade!
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- Added over 100 new CSS properties to the relaxed config, representing all properties that are listed with a status of "Working Draft" or better in the latest [W3C "All Properties" list](https://www.w3.org/Style/CSS/all-properties.en.html).
|
|
46
|
+
|
|
47
|
+
- Added the `@container` CSS at-rule to the relaxed config.
|
|
48
|
+
|
|
49
|
+
- Added the `-webkit-text-fill-color` CSS property to the relaxed config. [@radar - #244](https://github.com/rgrove/sanitize/pull/244)
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
|
|
53
|
+
- Ruby 3.1.0 is now the oldest supported Ruby version.
|
|
54
|
+
|
|
55
|
+
- Sanitize now requires Nokogiri 1.16.8 or higher.
|
|
56
|
+
|
|
57
|
+
## 6.1.3 (2024-08-14)
|
|
58
|
+
|
|
59
|
+
### Bug Fixes
|
|
60
|
+
|
|
61
|
+
* The CSS URL protocol allowlist is now enforced on the nonstandard `-webkit-image-set` CSS function. [@ltk - #242][242]
|
|
62
|
+
|
|
63
|
+
[242]:https://github.com/rgrove/sanitize/pull/242
|
|
64
|
+
|
|
65
|
+
## 6.1.2 (2024-07-27)
|
|
66
|
+
|
|
67
|
+
### Bug Fixes
|
|
68
|
+
|
|
69
|
+
* The CSS URL protocol allowlist is now properly enforced in [CSS Images Module Level 4](https://drafts.csswg.org/css-images-4/) `image` and `image-set` functions. [@ltk - #240][240]
|
|
70
|
+
|
|
71
|
+
[240]:https://github.com/rgrove/sanitize/pull/240
|
|
72
|
+
|
|
73
|
+
## 6.1.1 (2024-06-12)
|
|
74
|
+
|
|
75
|
+
### Bug Fixes
|
|
76
|
+
|
|
77
|
+
* Proactively fixed a compatibility issue with libxml >= 2.13.0 (which will be used in an upcoming version of Nokogiri) that caused HTML doctype sanitization to fail. [@flavorjones - #238][238]
|
|
78
|
+
|
|
79
|
+
[238]:https://github.com/rgrove/sanitize/pull/238
|
|
2
80
|
|
|
3
81
|
## 6.1.0 (2023-09-14)
|
|
4
82
|
|
|
@@ -255,8 +333,6 @@ review the changes below carefully.
|
|
|
255
333
|
Many thanks to the Shopify Application Security Team for responsibly reporting
|
|
256
334
|
this issue.
|
|
257
335
|
|
|
258
|
-
[176]:https://github.com/rgrove/sanitize/issues/176
|
|
259
|
-
|
|
260
336
|
## 4.6.2 (2018-03-19)
|
|
261
337
|
|
|
262
338
|
* Reduced string allocations to optimize memory usage. [@janklimo - #175][175]
|
|
@@ -594,7 +670,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
|
|
|
594
670
|
## 2.0.4 (2013-06-12)
|
|
595
671
|
|
|
596
672
|
* Added `Sanitize.clean_document`, which sanitizes a full HTML document rather
|
|
597
|
-
than just a fragment. [Ben Anderson]
|
|
673
|
+
than just a fragment. \[Ben Anderson]
|
|
598
674
|
|
|
599
675
|
* Nokogiri dependency bumped to 1.6.x.
|
|
600
676
|
|
|
@@ -617,7 +693,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
|
|
|
617
693
|
## 2.0.1 (2011-03-16)
|
|
618
694
|
|
|
619
695
|
* Updated the protocol regex to anchor at the beginning of the string rather
|
|
620
|
-
than the beginning of a line. [Eaden McKee]
|
|
696
|
+
than the beginning of a line. \[Eaden McKee]
|
|
621
697
|
|
|
622
698
|
|
|
623
699
|
## 2.0.0 (2011-01-15)
|
|
@@ -663,7 +739,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
|
|
|
663
739
|
remove the contents of all non-allowlisted elements in addition to the
|
|
664
740
|
elements themselves. If set to an array of element names, Sanitize will
|
|
665
741
|
remove the contents of only those elements (when filtered), and leave the
|
|
666
|
-
contents of other filtered elements. [Thanks to Rafael Souza for the array
|
|
742
|
+
contents of other filtered elements. \[Thanks to Rafael Souza for the array
|
|
667
743
|
option]
|
|
668
744
|
|
|
669
745
|
* Added an `:output_encoding` config setting to allow the character encoding
|
|
@@ -688,27 +764,27 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
|
|
|
688
764
|
* Added `Sanitize.clean_node!`, which sanitizes a `Nokogiri::XML::Node` and
|
|
689
765
|
all its children.
|
|
690
766
|
|
|
691
|
-
* Added elements `<h1>` through `<h6>` to the Relaxed allowlist. [Suggested by
|
|
767
|
+
* Added elements `<h1>` through `<h6>` to the Relaxed allowlist. \[Suggested by
|
|
692
768
|
David Reese]
|
|
693
769
|
|
|
694
770
|
|
|
695
771
|
## 1.1.0 (2009-10-11)
|
|
696
772
|
|
|
697
|
-
* Migrated from Hpricot to Nokogiri. Requires libxml2 >= 2.7.2 [Adam Hooper]
|
|
773
|
+
* Migrated from Hpricot to Nokogiri. Requires libxml2 >= 2.7.2 \[Adam Hooper]
|
|
698
774
|
|
|
699
775
|
* Added an `:output` config setting to allow the output format to be
|
|
700
776
|
specified. Supported formats are `:xhtml` (the default) and `:html` (which
|
|
701
777
|
outputs HTML4).
|
|
702
778
|
|
|
703
779
|
* Changed protocol regex to ensure Sanitize doesn't kill URLs with colons in
|
|
704
|
-
path segments. [Peter Cooper]
|
|
780
|
+
path segments. \[Peter Cooper]
|
|
705
781
|
|
|
706
782
|
|
|
707
783
|
## 1.0.8 (2009-04-23)
|
|
708
784
|
|
|
709
785
|
* Added a workaround for an Hpricot bug that prevents attribute names from
|
|
710
786
|
being downcased in recent versions of Hpricot. This was exploitable to
|
|
711
|
-
prevent non-allowlisted protocols from being cleaned. [Reported by Ben
|
|
787
|
+
prevent non-allowlisted protocols from being cleaned. \[Reported by Ben
|
|
712
788
|
Wanicur]
|
|
713
789
|
|
|
714
790
|
|
|
@@ -717,7 +793,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
|
|
|
717
793
|
* Requires Hpricot 0.8.1+, which is finally compatible with Ruby 1.9.1.
|
|
718
794
|
|
|
719
795
|
* Fixed a bug that caused named character entities containing digits (like
|
|
720
|
-
`²`) to be escaped when they shouldn't have been. [Reported by
|
|
796
|
+
`²`) to be escaped when they shouldn't have been. \[Reported by
|
|
721
797
|
Sebastian Steinmetz]
|
|
722
798
|
|
|
723
799
|
|
|
@@ -732,14 +808,14 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
|
|
|
732
808
|
problems in IE6.
|
|
733
809
|
|
|
734
810
|
* You can now specify the symbol `:all` in place of an element name in the
|
|
735
|
-
attributes config hash to allow certain attributes on all elements. [Thanks
|
|
811
|
+
attributes config hash to allow certain attributes on all elements. \[Thanks
|
|
736
812
|
to Mutwin Kraus]
|
|
737
813
|
|
|
738
814
|
|
|
739
815
|
## 1.0.5 (2009-02-05)
|
|
740
816
|
|
|
741
817
|
* Fixed a bug introduced in version 1.0.3 that prevented non-allowlisted
|
|
742
|
-
protocols from being cleaned when relative URLs were allowed. [Reported by
|
|
818
|
+
protocols from being cleaned when relative URLs were allowed. \[Reported by
|
|
743
819
|
Dev Purkayastha]
|
|
744
820
|
|
|
745
821
|
* Fixed "undefined method `parent='" exceptions caused by parser changes in
|
|
@@ -750,7 +826,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
|
|
|
750
826
|
|
|
751
827
|
* Fixed a bug that made it possible to sneak a non-allowlisted element through
|
|
752
828
|
by repeating it several times in a row. All versions of Sanitize prior to
|
|
753
|
-
1.0.4 are vulnerable. [Reported by Cristobal]
|
|
829
|
+
1.0.4 are vulnerable. \[Reported by Cristobal]
|
|
754
830
|
|
|
755
831
|
|
|
756
832
|
## 1.0.3 (2009-01-15)
|
data/LICENSE
CHANGED