sanitize 4.6.6 → 5.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sanitize might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5672f967be01303dd78eba5c0a1ab45729d15b604e2f2cbb6108c69864ad5f6
4
- data.tar.gz: 8ff91d1efafb67205b6ba07697d2c9f920e34df5e59f357433e54a6f9f0cca76
3
+ metadata.gz: e67616d2378cfe4e0ea979d76d206630a9edc4ed6d31f97e6801f6022a0ea08b
4
+ data.tar.gz: 8bce2fda8409782d0b25e143eb36912bc32183eff3314033f54e74560c9988d5
5
5
  SHA512:
6
- metadata.gz: '0981c67f49e789e6ccb6becb2a5407ac3db48b96823f48bef3a284fcc8b2fe539545ec0db8f0449dc5db5039d35a7a193970e3d72c076f99152c001d87be8659'
7
- data.tar.gz: 25af08d3f6524b70aaee67cab17a5e8568697be138954f1ff1e1bc8da591df5ccb405bc1212c24daeb81a3b2c4e659e56e60bdc76938b9a10e096449ba38b657
6
+ metadata.gz: e37c472801a5082c6019fd58f1d47c90c68c4a64a2cba7fc6149ac0c8d9a4c1f3c8c0baa3b659ba8f8bf384a5c6e3a95b30d15553aa3d5bcbc0f5a2dd7aa70fd
7
+ data.tar.gz: cb6db6ed39956a2f02e024d3745908a4c8b9bccf7f7fc3beebbfd2072a3a73948cc8320a1cb4622563ef2a158bcd73d75607adb94b4ce6e924efbabc7fe6a216
data/HISTORY.md CHANGED
@@ -1,5 +1,125 @@
1
1
  # Sanitize History
2
2
 
3
+ ## 5.2.2 (2021-01-06)
4
+
5
+ ### Bug Fixes
6
+
7
+ * Fixed a deprecation warning in Ruby 2.7+ when using keyword arguments in a
8
+ custom transformer. [@mscrivo - #206][206]
9
+
10
+ [206]:https://github.com/rgrove/sanitize/pull/206
11
+
12
+ ## 5.2.1 (2020-06-16)
13
+
14
+ ### Bug Fixes
15
+
16
+ * Fixed an HTML sanitization bypass that could allow XSS. This issue affects
17
+ Sanitize versions 3.0.0 through 5.2.0.
18
+
19
+ When HTML was sanitized using the "relaxed" config or a custom config that
20
+ allows certain elements, some content in a `<math>` or `<svg>` element may not
21
+ have beeen sanitized correctly even if `math` and `svg` were not in the
22
+ allowlist. This could allow carefully crafted input to sneak arbitrary HTML
23
+ through Sanitize, potentially enabling an XSS (cross-site scripting) attack.
24
+
25
+ You are likely to be vulnerable to this issue if you use Sanitize's relaxed
26
+ config or a custom config that allows one or more of the following HTML
27
+ elements:
28
+
29
+ - `iframe`
30
+ - `math`
31
+ - `noembed`
32
+ - `noframes`
33
+ - `noscript`
34
+ - `plaintext`
35
+ - `script`
36
+ - `style`
37
+ - `svg`
38
+ - `xmp`
39
+
40
+ See the security advisory for more details, including a workaround if you're
41
+ not able to upgrade: [GHSA-p4x4-rw2p-8j8m]
42
+
43
+ Many thanks to Michał Bentkowski of Securitum for reporting this issue and
44
+ helping to verify the fix.
45
+
46
+ [GHSA-p4x4-rw2p-8j8m]:https://github.com/rgrove/sanitize/security/advisories/GHSA-p4x4-rw2p-8j8m
47
+
48
+ ## 5.2.0 (2020-06-06)
49
+
50
+ ### Changes
51
+
52
+ * The term "whitelist" has been replaced with "allowlist" throughout Sanitize's
53
+ source and documentation.
54
+
55
+ While the etymology of "whitelist" may not be explicitly racist in origin or
56
+ intent, there are inherent racial connotations in the implication that white
57
+ is good and black (as in "blacklist") is not.
58
+
59
+ This is a change I should have made long ago, and I apologize for not making
60
+ it sooner.
61
+
62
+ * In transformer input, the `:is_whitelisted` and `:node_whitelist` keys are now
63
+ deprecated. New `:is_allowlisted` and `:node_allowlist` keys have been added.
64
+ The old keys will continue to work in order to avoid breaking existing code,
65
+ but they are no longer documented and may be removed in a future semver major
66
+ release.
67
+
68
+ ## 5.1.0 (2019-09-07)
69
+
70
+ ### Features
71
+
72
+ * Added a `:parser_options` config hash, which makes it possible to pass custom
73
+ parsing options to Nokogumbo. [@austin-wang - #194][194]
74
+
75
+ ### Bug Fixes
76
+
77
+ * Non-characters and non-whitespace control characters are now stripped from
78
+ HTML input before parsing to comply with the HTML Standard's [preprocessing
79
+ guidelines][html-preprocessing]. Prior to this Sanitize had adhered to [older
80
+ W3C guidelines][unicode-xml] that have since been withdrawn. [#179][179]
81
+
82
+ [179]:https://github.com/rgrove/sanitize/issues/179
83
+ [194]:https://github.com/rgrove/sanitize/pull/194
84
+ [html-preprocessing]:https://html.spec.whatwg.org/multipage/parsing.html#preprocessing-the-input-stream
85
+ [unicode-xml]:https://www.w3.org/TR/unicode-xml/
86
+
87
+ ## 5.0.0 (2018-10-14)
88
+
89
+ For most users, upgrading from 4.x shouldn't require any changes. However, the
90
+ minimum required Ruby version has changed, and Sanitize 5.x's HTML output may
91
+ differ in some small ways from 4.x's output. If this matters to you, please
92
+ review the changes below carefully.
93
+
94
+ ### Potentially Breaking Changes
95
+
96
+ * Ruby 2.3.0 is now the oldest officially supported Ruby version. Sanitize may
97
+ work in older 2.x Rubies, but they aren't actively tested. Sanitize definitely
98
+ no longer works in Ruby 1.9.x.
99
+
100
+ * Upgraded to Nokogumbo 2.x, which fixes various bugs and adds
101
+ standard-compliant HTML serialization. [@stevecheckoway - #189][189]
102
+
103
+ * Children of the following elements are now removed by default when these
104
+ elements are removed, rather than being preserved and escaped:
105
+
106
+ - `iframe`
107
+ - `noembed`
108
+ - `noframes`
109
+ - `noscript`
110
+ - `script`
111
+ - `style`
112
+
113
+ * Children of allowlisted `iframe` elements are now always removed. In modern
114
+ HTML, `iframe` elements should never have children. In HTML 4 and earlier
115
+ `iframe` elements were allowed to contain fallback content for legacy
116
+ browsers, but it's been almost two decades since that was useful.
117
+
118
+ * Fixed a bug that caused `:remove_contents` to behave as if it were set to
119
+ `true` when it was actually an Array.
120
+
121
+ [189]:https://github.com/rgrove/sanitize/pull/189
122
+
3
123
  ## 4.6.6 (2018-07-23)
4
124
 
5
125
  * Improved performance and memory usage by optimizing `Sanitize#transform_node!`
@@ -29,7 +149,7 @@
29
149
 
30
150
  When Sanitize <= 4.6.2 is used in combination with libxml2 >= 2.9.2, a
31
151
  specially crafted HTML fragment can cause libxml2 to generate improperly
32
- escaped output, allowing non-whitelisted attributes to be used on whitelisted
152
+ escaped output, allowing non-allowlisted attributes to be used on allowlisted
33
153
  elements.
34
154
 
35
155
  Sanitize now performs additional escaping on affected attributes to prevent
@@ -73,7 +193,7 @@
73
193
 
74
194
  ## 4.4.0 (2016-09-29)
75
195
 
76
- * Added `srcset` to the attribute whitelist for `img` elements in the relaxed
196
+ * Added `srcset` to the attribute allowlist for `img` elements in the relaxed
77
197
  config. [@ejtttje - #156][156]
78
198
 
79
199
  [156]:https://github.com/rgrove/sanitize/pull/156
@@ -194,7 +314,7 @@
194
314
  ## 3.0.4 (2014-12-12)
195
315
 
196
316
  * Fixed: Harmless whitespace preceding a URL protocol (such as " http://")
197
- caused the URL to be removed even when the protocol was whitelisted.
317
+ caused the URL to be removed even when the protocol was allowlisted.
198
318
  [@benubois - #126][126]
199
319
 
200
320
  [126]:https://github.com/rgrove/sanitize/pull/126
@@ -203,7 +323,7 @@
203
323
  ## 3.0.3 (2014-10-29)
204
324
 
205
325
  * Fixed: Some CSS selectors weren't parsed correctly inside the body of a
206
- `@media` block, causing them to be removed even when whitelist rules should
326
+ `@media` block, causing them to be removed even when allowlist rules should
207
327
  have allowed them to remain. [#121][121]
208
328
 
209
329
  [121]:https://github.com/rgrove/sanitize/issues/121
@@ -268,7 +388,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
268
388
  * The `clean_node!` method was renamed to `node!`.
269
389
 
270
390
  * The `document` method now raises a `Sanitize::Error` if the `<html>` element
271
- isn't whitelisted, rather than a `RuntimeError`. This error is also now raised
391
+ isn't allowlisted, rather than a `RuntimeError`. This error is also now raised
272
392
  regardless of the `:remove_contents` config setting.
273
393
 
274
394
  * The `:output` config has been removed. Output is now always HTML, not XHTML.
@@ -279,7 +399,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
279
399
 
280
400
  * Added advanced CSS sanitization support using [Crass][crass], which is fully
281
401
  compliant with the CSS Syntax Module Level 3 parsing spec. The contents of
282
- whitelisted `<style>` elements and `style` attributes in HTML will be
402
+ allowlisted `<style>` elements and `style` attributes in HTML will be
283
403
  sanitized as CSS, or you can use the `Sanitize::CSS` class to manually
284
404
  sanitize CSS stylesheets or properties.
285
405
 
@@ -324,9 +444,29 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
324
444
  [n1008]:https://github.com/sparklemotion/nokogiri/issues/1008
325
445
 
326
446
 
447
+ ## 2.1.1 (2018-09-30)
448
+
449
+ * [CVE-2018-3740][176]: Fixed an HTML injection vulnerability that could allow
450
+ XSS (backported from Sanitize 4.6.3). [@dometto - #188][188]
451
+
452
+ When Sanitize <= 2.1.0 is used in combination with libxml2 >= 2.9.2, a
453
+ specially crafted HTML fragment can cause libxml2 to generate improperly
454
+ escaped output, allowing non-allowlisted attributes to be used on allowlisted
455
+ elements.
456
+
457
+ Sanitize now performs additional escaping on affected attributes to prevent
458
+ this.
459
+
460
+ Many thanks to the Shopify Application Security Team for responsibly reporting
461
+ this issue.
462
+
463
+ [176]:https://github.com/rgrove/sanitize/issues/176
464
+ [188]:https://github.com/rgrove/sanitize/pull/188
465
+
466
+
327
467
  ## 2.1.0 (2014-01-13)
328
468
 
329
- * Added support for whitelisting arbitrary HTML5 `data-*` attributes. Use the
469
+ * Added support for allowlisting arbitrary HTML5 `data-*` attributes. Use the
330
470
  symbol `:data` instead of an attribute name in the `:attributes` config to
331
471
  indicate that arbitrary data attributes should be allowed on an element.
332
472
 
@@ -407,12 +547,12 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
407
547
  the default depth-first mode.
408
548
 
409
549
  * Added the `abbr`, `dfn`, `kbd`, `mark`, `s`, `samp`, `time`, and `var`
410
- elements to the whitelists for the basic and relaxed configs.
550
+ elements to the allowlists for the basic and relaxed configs.
411
551
 
412
552
  * Added the `bdo`, `del`, `figcaption`, `figure`, `hgroup`, `ins`, `rp`, `rt`,
413
- `ruby`, and `wbr` elements to the whitelist for the relaxed config.
553
+ `ruby`, and `wbr` elements to the allowlist for the relaxed config.
414
554
 
415
- * The `dir`, `lang`, and `title` attributes are now whitelisted for all
555
+ * The `dir`, `lang`, and `title` attributes are now allowlisted for all
416
556
  elements in the relaxed config.
417
557
 
418
558
  * Bumped minimum Nokogiri version to 1.4.4 to avoid a bug in 1.4.2+
@@ -423,7 +563,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
423
563
  ## 1.2.1 (2010-04-20)
424
564
 
425
565
  * Added a `:remove_contents` config setting. If set to `true`, Sanitize will
426
- remove the contents of all non-whitelisted elements in addition to the
566
+ remove the contents of all non-allowlisted elements in addition to the
427
567
  elements themselves. If set to an array of element names, Sanitize will
428
568
  remove the contents of only those elements (when filtered), and leave the
429
569
  contents of other filtered elements. [Thanks to Rafael Souza for the array
@@ -451,7 +591,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
451
591
  * Added `Sanitize.clean_node!`, which sanitizes a `Nokogiri::XML::Node` and
452
592
  all its children.
453
593
 
454
- * Added elements `<h1>` through `<h6>` to the Relaxed whitelist. [Suggested by
594
+ * Added elements `<h1>` through `<h6>` to the Relaxed allowlist. [Suggested by
455
595
  David Reese]
456
596
 
457
597
 
@@ -471,7 +611,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
471
611
 
472
612
  * Added a workaround for an Hpricot bug that prevents attribute names from
473
613
  being downcased in recent versions of Hpricot. This was exploitable to
474
- prevent non-whitelisted protocols from being cleaned. [Reported by Ben
614
+ prevent non-allowlisted protocols from being cleaned. [Reported by Ben
475
615
  Wanicur]
476
616
 
477
617
 
@@ -501,7 +641,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
501
641
 
502
642
  ## 1.0.5 (2009-02-05)
503
643
 
504
- * Fixed a bug introduced in version 1.0.3 that prevented non-whitelisted
644
+ * Fixed a bug introduced in version 1.0.3 that prevented non-allowlisted
505
645
  protocols from being cleaned when relative URLs were allowed. [Reported by
506
646
  Dev Purkayastha]
507
647
 
@@ -511,7 +651,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
511
651
 
512
652
  ## 1.0.4 (2009-01-16)
513
653
 
514
- * Fixed a bug that made it possible to sneak a non-whitelisted element through
654
+ * Fixed a bug that made it possible to sneak a non-allowlisted element through
515
655
  by repeating it several times in a row. All versions of Sanitize prior to
516
656
  1.0.4 are vulnerable. [Reported by Cristobal]
517
657
 
@@ -519,7 +659,7 @@ Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
519
659
  ## 1.0.3 (2009-01-15)
520
660
 
521
661
  * Fixed a bug whereby incomplete Unicode or hex entities could be used to
522
- prevent non-whitelisted protocols from being cleaned. Since IE6 and Opera
662
+ prevent non-allowlisted protocols from being cleaned. Since IE6 and Opera
523
663
  still decode the incomplete entities, users of those browsers may be
524
664
  vulnerable to malicious script injection on websites using versions of
525
665
  Sanitize prior to 1.0.3.
data/README.md CHANGED
@@ -1,20 +1,19 @@
1
1
  Sanitize
2
2
  ========
3
3
 
4
- Sanitize is a whitelist-based HTML and CSS sanitizer. Given a list of acceptable
5
- elements, attributes, and CSS properties, Sanitize will remove all unacceptable
6
- HTML and/or CSS from a string.
4
+ Sanitize is an allowlist-based HTML and CSS sanitizer. It removes all HTML
5
+ and/or CSS from a string except the elements, attributes, and properties you
6
+ choose to allow.
7
7
 
8
8
  Using a simple configuration syntax, you can tell Sanitize to allow certain HTML
9
9
  elements, certain attributes within those elements, and even certain URL
10
- protocols within attributes that contain URLs. You can also whitelist CSS
11
- properties, @ rules, and URL protocols you wish to allow in elements or
12
- attributes containing CSS. Any HTML or CSS that you don't explicitly allow will
13
- be removed.
10
+ protocols within attributes that contain URLs. You can also allow specific CSS
11
+ properties, @ rules, and URL protocols in elements or attributes containing CSS.
12
+ Any HTML or CSS that you don't explicitly allow will be removed.
14
13
 
15
14
  Sanitize is based on [Google's Gumbo HTML5 parser][gumbo], which parses HTML
16
15
  exactly the same way modern browsers do, and [Crass][crass], which parses CSS
17
- exactly the same way modern browsers do. As long as your whitelist config only
16
+ exactly the same way modern browsers do. As long as your allowlist config only
18
17
  allows safe markup and CSS, even the most malformed or malicious input will be
19
18
  transformed into safe output.
20
19
 
@@ -73,6 +72,11 @@ Sanitize can sanitize the following types of input:
73
72
  * Standalone CSS stylesheets
74
73
  * Standalone CSS properties
75
74
 
75
+ However, please note that Sanitize _cannot_ fully sanitize the contents of
76
+ `<math>` or `<svg>` elements, since these elements don't follow the same parsing
77
+ rules as the rest of HTML. If this is something you need, you may want to look
78
+ for another solution.
79
+
76
80
  ### HTML Fragments
77
81
 
78
82
  A fragment is a snippet of HTML that doesn't contain a root-level `<html>`
@@ -88,7 +92,7 @@ Sanitize.fragment(html)
88
92
  # => 'foo'
89
93
  ```
90
94
 
91
- To keep certain elements, add them to the element whitelist.
95
+ To keep certain elements, add them to the element allowlist.
92
96
 
93
97
  ```ruby
94
98
  Sanitize.fragment(html, :elements => ['b'])
@@ -97,7 +101,7 @@ Sanitize.fragment(html, :elements => ['b'])
97
101
 
98
102
  ### HTML Documents
99
103
 
100
- When sanitizing a document, the `<html>` element must be whitelisted. You can
104
+ When sanitizing a document, the `<html>` element must be allowlisted. You can
101
105
  also set `:allow_doctype` to `true` to allow well-formed document type
102
106
  definitions.
103
107
 
@@ -123,8 +127,8 @@ Sanitize.document(html,
123
127
 
124
128
  ### CSS in HTML
125
129
 
126
- To sanitize CSS in an HTML fragment or document, first whitelist the `<style>`
127
- element and/or the `style` attribute. Then whitelist the CSS properties,
130
+ To sanitize CSS in an HTML fragment or document, first allowlist the `<style>`
131
+ element and/or the `style` attribute. Then allowlist the CSS properties,
128
132
  @ rules, and URL protocols you wish to allow. You can also choose whether to
129
133
  allow CSS comments or browser compatibility hacks.
130
134
 
@@ -267,7 +271,7 @@ new copy using `Sanitize::Config.merge()`, like so:
267
271
 
268
272
  ```ruby
269
273
  # Create a customized copy of the Basic config, adding <div> and <table> to the
270
- # existing whitelisted elements.
274
+ # existing allowlisted elements.
271
275
  Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::BASIC,
272
276
  :elements => Sanitize::Config::BASIC[:elements] + ['div', 'table'],
273
277
  :remove_contents => true
@@ -395,8 +399,7 @@ Proc.new { |url| url.start_with?("https://fonts.googleapis.com") }
395
399
 
396
400
  ##### :css => :properties (Array or Set)
397
401
 
398
- Whitelist of CSS property names to allow. Names should be specified in
399
- lowercase.
402
+ List of CSS property names to allow. Names should be specified in lowercase.
400
403
 
401
404
  ##### :css => :protocols (Array or Set)
402
405
 
@@ -417,6 +420,23 @@ elements not in this array will be removed.
417
420
  ]
418
421
  ```
419
422
 
423
+ **Warning:** Sanitize cannot fully sanitize the contents of `<math>` or `<svg>`
424
+ elements, since these elements don't follow the same parsing rules as the rest
425
+ of HTML. If you add `math` or `svg` to the allowlist, you must assume that any
426
+ content inside them will be allowed, even if that content would otherwise be
427
+ removed by Sanitize.
428
+
429
+ #### :parser_options (Hash)
430
+
431
+ [Parsing options](https://github.com/rubys/nokogumbo/tree/v2.0.1#parsing-options) supplied to `nokogumbo`.
432
+
433
+ ```ruby
434
+ :parser_options => {
435
+ max_errors: -1,
436
+ max_tree_depth: -1
437
+ }
438
+ ```
439
+
420
440
  #### :protocols (Hash)
421
441
 
422
442
  URL protocols to allow in specific attributes. If an attribute is listed here
@@ -441,15 +461,15 @@ include the symbol `:relative` in the protocol array:
441
461
 
442
462
  #### :remove_contents (boolean or Array or Set)
443
463
 
444
- If set to `true`, Sanitize will remove the contents of any non-whitelisted
464
+ If this is `true`, Sanitize will remove the contents of any non-allowlisted
445
465
  elements in addition to the elements themselves. By default, Sanitize leaves the
446
466
  safe parts of an element's contents behind when the element is removed.
447
467
 
448
- If set to an array of element names, then only the contents of the specified
449
- elements (when filtered) will be removed, and the contents of all other filtered
450
- elements will be left behind.
468
+ If this is an Array or Set of element names, then only the contents of the
469
+ specified elements (when filtered) will be removed, and the contents of all
470
+ other filtered elements will be left behind.
451
471
 
452
- The default value is `false`.
472
+ The default value is `%w[iframe math noembed noframes noscript plaintext script style svg xmp]`.
453
473
 
454
474
  #### :transformers (Array or callable)
455
475
 
@@ -507,33 +527,33 @@ argument a Hash that contains the following items:
507
527
 
508
528
  * **:config** - The current Sanitize configuration Hash.
509
529
 
510
- * **:is_whitelisted** - `true` if the current node has been whitelisted by a
530
+ * **:is_allowlisted** - `true` if the current node has been allowlisted by a
511
531
  previous transformer, `false` otherwise. It's generally bad form to remove
512
- a node that a previous transformer has whitelisted.
532
+ a node that a previous transformer has allowlisted.
513
533
 
514
534
  * **:node** - A `Nokogiri::XML::Node` object representing an HTML node. The
515
535
  node may be an element, a text node, a comment, a CDATA node, or a document
516
536
  fragment. Use Nokogiri's inspection methods (`element?`, `text?`, etc.) to
517
537
  selectively ignore node types you aren't interested in.
518
538
 
539
+ * **:node_allowlist** - Set of `Nokogiri::XML::Node` objects in the current
540
+ document that have been allowlisted by previous transformers, if any. It's
541
+ generally bad form to remove a node that a previous transformer has
542
+ allowlisted.
543
+
519
544
  * **:node_name** - The name of the current HTML node, always lowercase (e.g.
520
545
  "div" or "span"). For non-element nodes, the name will be something like
521
546
  "text", "comment", "#cdata-section", "#document-fragment", etc.
522
547
 
523
- * **:node_whitelist** - Set of `Nokogiri::XML::Node` objects in the current
524
- document that have been whitelisted by previous transformers, if any. It's
525
- generally bad form to remove a node that a previous transformer has
526
- whitelisted.
527
-
528
548
  ### Output
529
549
 
530
550
  A transformer doesn't have to return anything, but may optionally return a Hash,
531
551
  which may contain the following items:
532
552
 
533
- * **:node_whitelist** - Array or Set of specific Nokogiri::XML::Node objects
534
- to add to the document's whitelist, bypassing the current Sanitize config.
535
- These specific nodes and all their attributes will be whitelisted, but
536
- their children will not be.
553
+ * **:node_allowlist** - Array or Set of specific `Nokogiri::XML::Node`
554
+ objects to add to the document's allowlist, bypassing the current Sanitize
555
+ config. These specific nodes and all their attributes will be allowlisted,
556
+ but their children will not be.
537
557
 
538
558
  If a transformer returns anything other than a Hash, the return value will be
539
559
  ignored.
@@ -576,16 +596,16 @@ Transformers have a tremendous amount of power, including the power to
576
596
  completely bypass Sanitize's built-in filtering. Be careful! Your safety is in
577
597
  your own hands.
578
598
 
579
- ### Example: Transformer to whitelist image URLs by domain
599
+ ### Example: Transformer to allow image URLs by domain
580
600
 
581
601
  The following example demonstrates how to remove image elements unless they use
582
602
  a relative URL or are hosted on a specific domain. It assumes that the `<img>`
583
- element and its `src` attribute are already whitelisted.
603
+ element and its `src` attribute are already allowlisted.
584
604
 
585
605
  ```ruby
586
606
  require 'uri'
587
607
 
588
- image_whitelist_transformer = lambda do |env|
608
+ image_allowlist_transformer = lambda do |env|
589
609
  # Ignore everything except <img> elements.
590
610
  return unless env[:node_name] == 'img'
591
611
 
@@ -601,20 +621,20 @@ image_whitelist_transformer = lambda do |env|
601
621
  end
602
622
  ```
603
623
 
604
- ### Example: Transformer to whitelist YouTube video embeds
624
+ ### Example: Transformer to allow YouTube video embeds
605
625
 
606
626
  The following example demonstrates how to create a transformer that will safely
607
- whitelist valid YouTube video embeds without having to blindly allow other kinds
608
- of embedded content, which would be the case if you tried to do this by just
609
- whitelisting all `<iframe>` elements:
627
+ allow valid YouTube video embeds without having to allow other kinds of embedded
628
+ content, which would be the case if you tried to do this by just allowing all
629
+ `<iframe>` elements:
610
630
 
611
631
  ```ruby
612
632
  youtube_transformer = lambda do |env|
613
633
  node = env[:node]
614
634
  node_name = env[:node_name]
615
635
 
616
- # Don't continue if this node is already whitelisted or is not an element.
617
- return if env[:is_whitelisted] || !node.element?
636
+ # Don't continue if this node is already allowlisted or is not an element.
637
+ return if env[:is_allowlisted] || !node.element?
618
638
 
619
639
  # Don't continue unless the node is an iframe.
620
640
  return unless node_name == 'iframe'
@@ -635,8 +655,8 @@ youtube_transformer = lambda do |env|
635
655
 
636
656
  # Now that we're sure that this is a valid YouTube embed and that there are
637
657
  # no unwanted elements or attributes hidden inside it, we can tell Sanitize
638
- # to whitelist the current node.
639
- {:node_whitelist => [node]}
658
+ # to allowlist the current node.
659
+ {:node_allowlist => [node]}
640
660
  end
641
661
 
642
662
  html = %[