sanitize-html 1.20.1 → 1.22.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## Changelog
2
2
 
3
+ 1.22.1: Increases the patch version of `lodash.mergewith` to enforce an audit fix.
4
+
5
+ 1.22.0: bumped `htmlparser2` dependency to the 4.x series. This fixes longstanding bugs and should cause no bc breaks for this module, since the only bc breaks upstream are in regard to features we don't expose in this module.
6
+
7
+ 1.21.1: fixed issue with bad `main` setting in package.json that broke 1.21.0.
8
+
9
+ 1.21.0: new `disallowedTagsMode` option can be set to `escape` to escape disallowed tags rather than discarding them. Any subtags are handled as usual. If you want to recursively escape them too, you can set `disallowedTagsMode` to `recursiveEscape`. Thanks to Yehonatan Zecharia for this contribution.
10
+
3
11
  1.20.1: Fix failing tests, add CircleCI config
4
12
 
5
13
  1.20.0: reduced size of npm package via the `files` key; we only need to publish what's in `dist`. Thanks to Steven. There should be zero impact on behavior, minor version bump is precautionary.
@@ -77,7 +85,7 @@ Please note that running `sanitize-html` in the browser is usually a security ho
77
85
 
78
86
  1.14.2: protocol-relative URL detection must spot URLs starting with `\\` rather than `//` due to ages-old tolerance features of web browsers, intended for sleepy Windows developers. Thanks to Martin Bajanik.
79
87
 
80
- 1.14.1: documented `allowProtocolRelative` option. No code changes from 1.14.0, released a few moments ago.
88
+ 1.14.1: documented `allowProtocolRelative` option. No code changes from 1.14.0, released a few moments ago.
81
89
 
82
90
  1.14.0: the new `allowProtocolRelative` option, which is set to `true` by default, allows you to decline to accept URLs that start with `//` and thus point to a different host using the current protocol. If you do **not** want to permit this, set this option to `false`. This is fully backwards compatible because the default behavior is to allow them. Thanks to Luke Bernard.
83
91
 
package/README.md CHANGED
@@ -109,6 +109,7 @@ If you do not specify `allowedTags` or `allowedAttributes` our default list is a
109
109
  allowedTags: [ 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol',
110
110
  'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div',
111
111
  'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'iframe' ],
112
+ disallowedTagsMode: 'discard',
112
113
  allowedAttributes: {
113
114
  a: [ 'href', 'name', 'target' ],
114
115
  // We don't currently allow img itself by default, but this
@@ -144,6 +145,14 @@ allowedTags: [],
144
145
  allowedAttributes: {}
145
146
  ```
146
147
 
148
+ ### "What if I want disallowed tags to be escaped rather than discarded?"
149
+
150
+ If you set `disallowedTagsMode` to `discard` (the default), disallowed tags are discarded. Any text content or subtags is still included, depending on whether the individual subtags are allowed.
151
+
152
+ If you set `disallowedTagsMode` to `escape`, the disallowed tags are escaped rather than discarded. Any text or subtags is handled normally.
153
+
154
+ If you set `disallowedTagsMode` to `recursiveEscape`, the disallowed tags are escaped rather than discarded, and the same treatment is applied to all subtags, whether otherwise allowed or not.
155
+
147
156
  ### "What if I want to allow only specific values on some attributes?"
148
157
 
149
158
  When configuring the attribute in `allowedAttributes` simply use an object with attribute `name` and an allowed `values` array. In the following example `sandbox="allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-scripts"` would become `sandbox="allow-popups allow-scripts"`:
@@ -422,7 +431,7 @@ clean = sanitizeHtml(dirty, {
422
431
  allowedStyles: {
423
432
  '*': {
424
433
  // Match HEX and RGB
425
- 'color': [/^\#(0x)?[0-9a-f]+$/i, /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/],
434
+ 'color': [/^#(0x)?[0-9a-f]+$/i, /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/],
426
435
  'text-align': [/^left$/, /^right$/, /^center$/],
427
436
  // Match any number with px, em, or %
428
437
  'font-size': [/^\d+(?:px|em|%)$/]
@@ -488,6 +497,18 @@ Note that if you use this option you are responsible for stating the entire list
488
497
 
489
498
  The content still gets escaped properly, with the exception of the `script` and `style` tags. *Allowing either `script` or `style` leaves you open to XSS attacks. Don't do that* unless you have good reason to trust their origin.
490
499
 
500
+ ### Choose what to do with disallowed tags
501
+
502
+ Instead of discarding, or keeping text only, you may enable escaping of the entire content:
503
+
504
+ ```javascript
505
+ disallowedTagsMode: 'escape'
506
+ ```
507
+
508
+ This will transform `<disallowed>content</disallowed>` to `&lt;disallowed&gt;content&lt;/disallowed&gt;`
509
+
510
+ Valid values are: `'discard'` (default), `'escape'` (escape the tag) and `'recursiveEscape'` (to escape the tag and all its content).
511
+
491
512
  ## About P'unk Avenue and Apostrophe
492
513
 
493
514
  `sanitize-html` was created at [P'unk Avenue](http://punkave.com) for use in ApostropheCMS, an open-source content management system built on node.js. If you like `sanitize-html` you should definitely [check out apostrophecms.org](http://apostrophecms.org).