sanitize-html 2.10.0 → 2.12.0

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.
Files changed (4) hide show
  1. package/README.md +83 -3
  2. package/index.js +76 -14
  3. package/package.json +3 -3
  4. package/CHANGELOG.md +0 -410
package/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  # sanitize-html
2
2
 
3
- [![CircleCI](https://circleci.com/gh/apostrophecms/sanitize-html/tree/main.svg?style=svg)](https://circleci.com/gh/apostrophecms/sanitize-html/tree/main)
4
-
5
3
  <a href="https://apostrophecms.com/"><img src="https://raw.githubusercontent.com/apostrophecms/sanitize-html/main/logos/logo-box-madefor.png" align="right" /></a>
6
4
 
7
5
  sanitize-html provides a simple HTML sanitizer with a clear API.
8
6
 
9
7
  sanitize-html is tolerant. It is well suited for cleaning up HTML fragments such as those created by CKEditor and other rich text editors. It is especially handy for removing unwanted CSS when copying and pasting from Word.
10
8
 
11
- sanitize-html allows you to specify the tags you want to permit, and the permitted attributes for each of those tags.
9
+ sanitize-html allows you to specify the tags you want to permit, and the permitted
10
+ attributes for each of those tags. If an attribute is a known non-boolean value,
11
+ and it is empty, it will be removed. For example `checked` can be empty, but `href`
12
+ cannot.
12
13
 
13
14
  If a tag is not permitted, the contents of the tag are not discarded. There are
14
15
  some exceptions to this, discussed below in the "Discarding the entire contents
@@ -125,6 +126,48 @@ allowedTags: [
125
126
  "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "caption",
126
127
  "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr"
127
128
  ],
129
+ nonBooleanAttributes: [
130
+ 'abbr', 'accept', 'accept-charset', 'accesskey', 'action',
131
+ 'allow', 'alt', 'as', 'autocapitalize', 'autocomplete',
132
+ 'blocking', 'charset', 'cite', 'class', 'color', 'cols',
133
+ 'colspan', 'content', 'contenteditable', 'coords', 'crossorigin',
134
+ 'data', 'datetime', 'decoding', 'dir', 'dirname', 'download',
135
+ 'draggable', 'enctype', 'enterkeyhint', 'fetchpriority', 'for',
136
+ 'form', 'formaction', 'formenctype', 'formmethod', 'formtarget',
137
+ 'headers', 'height', 'hidden', 'high', 'href', 'hreflang',
138
+ 'http-equiv', 'id', 'imagesizes', 'imagesrcset', 'inputmode',
139
+ 'integrity', 'is', 'itemid', 'itemprop', 'itemref', 'itemtype',
140
+ 'kind', 'label', 'lang', 'list', 'loading', 'low', 'max',
141
+ 'maxlength', 'media', 'method', 'min', 'minlength', 'name',
142
+ 'nonce', 'optimum', 'pattern', 'ping', 'placeholder', 'popover',
143
+ 'popovertarget', 'popovertargetaction', 'poster', 'preload',
144
+ 'referrerpolicy', 'rel', 'rows', 'rowspan', 'sandbox', 'scope',
145
+ 'shape', 'size', 'sizes', 'slot', 'span', 'spellcheck', 'src',
146
+ 'srcdoc', 'srclang', 'srcset', 'start', 'step', 'style',
147
+ 'tabindex', 'target', 'title', 'translate', 'type', 'usemap',
148
+ 'value', 'width', 'wrap',
149
+ // Event handlers
150
+ 'onauxclick', 'onafterprint', 'onbeforematch', 'onbeforeprint',
151
+ 'onbeforeunload', 'onbeforetoggle', 'onblur', 'oncancel',
152
+ 'oncanplay', 'oncanplaythrough', 'onchange', 'onclick', 'onclose',
153
+ 'oncontextlost', 'oncontextmenu', 'oncontextrestored', 'oncopy',
154
+ 'oncuechange', 'oncut', 'ondblclick', 'ondrag', 'ondragend',
155
+ 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart',
156
+ 'ondrop', 'ondurationchange', 'onemptied', 'onended',
157
+ 'onerror', 'onfocus', 'onformdata', 'onhashchange', 'oninput',
158
+ 'oninvalid', 'onkeydown', 'onkeypress', 'onkeyup',
159
+ 'onlanguagechange', 'onload', 'onloadeddata', 'onloadedmetadata',
160
+ 'onloadstart', 'onmessage', 'onmessageerror', 'onmousedown',
161
+ 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout',
162
+ 'onmouseover', 'onmouseup', 'onoffline', 'ononline', 'onpagehide',
163
+ 'onpageshow', 'onpaste', 'onpause', 'onplay', 'onplaying',
164
+ 'onpopstate', 'onprogress', 'onratechange', 'onreset', 'onresize',
165
+ 'onrejectionhandled', 'onscroll', 'onscrollend',
166
+ 'onsecuritypolicyviolation', 'onseeked', 'onseeking', 'onselect',
167
+ 'onslotchange', 'onstalled', 'onstorage', 'onsubmit', 'onsuspend',
168
+ 'ontimeupdate', 'ontoggle', 'onunhandledrejection', 'onunload',
169
+ 'onvolumechange', 'onwaiting', 'onwheel'
170
+ ],
128
171
  disallowedTagsMode: 'discard',
129
172
  allowedAttributes: {
130
173
  a: [ 'href', 'name', 'target' ],
@@ -167,6 +210,26 @@ allowedTags: false,
167
210
  allowedAttributes: false
168
211
  ```
169
212
 
213
+ #### "What if I want to allow empty attributes, even for cases like href that normally don't make sense?"
214
+
215
+ Very simple! Set `nonBooleanAttributes` to `[]`.
216
+
217
+ ```js
218
+ nonBooleanAttributes: []
219
+ ```
220
+
221
+ #### "What if I want to remove all empty attributes, including valid ones?"
222
+
223
+ Also very simple! Set `nonBooleanAttributes` to `['*']`.
224
+
225
+ **Note**: This will break common valid cases like `checked` and `selected`, so this is
226
+ unlikely to be what you want. For most ordinary HTML use, it is best to avoid making
227
+ this change.
228
+
229
+ ```js
230
+ nonBooleanAttributes: ['*']
231
+ ```
232
+
170
233
  #### "What if I don't want to allow *any* tags?"
171
234
 
172
235
  Also simple! Set `allowedTags` to `[]` and `allowedAttributes` to `{}`.
@@ -202,6 +265,21 @@ allowedAttributes: {
202
265
 
203
266
  With `multiple: true`, several allowed values may appear in the same attribute, separated by spaces. Otherwise the attribute must exactly match one and only one of the allowed values.
204
267
 
268
+ #### "What if I want to maintain the original case for SVG elements and attributes?"
269
+
270
+ If you're incorporating SVG elements like `linearGradient` into your content and notice that they're not rendering as expected due to case sensitivity issues, it's essential to prevent `sanitize-html` from converting element and attribute names to lowercase. This situation often arises when SVGs fail to display correctly because their case-sensitive tags, such as `linearGradient` and attributes like `viewBox`, are inadvertently lowercased.
271
+
272
+ To address this, ensure you set `lowerCaseTags: false` and `lowerCaseAttributeNames: false` in the parser options of your sanitize-html configuration. This adjustment stops the library from altering the case of your tags and attributes, preserving the integrity of your SVG content.
273
+
274
+ ```js
275
+ allowedTags: [ 'svg', 'g', 'defs', 'linearGradient', 'stop', 'circle' ],
276
+ allowedAttributes: false,
277
+ parser: {
278
+ lowerCaseTags: false,
279
+ lowerCaseAttributeNames: false
280
+ }
281
+ ```
282
+
205
283
  ### Wildcards for attributes
206
284
 
207
285
  You can use the `*` wildcard to allow all attributes with a certain prefix:
@@ -255,6 +333,8 @@ allowedClasses: {
255
333
  }
256
334
  ```
257
335
 
336
+ If `allowedClasses` for a certain tag is `false`, all the classes for this tag will be allowed.
337
+
258
338
  > Note: It is advised that your regular expressions always begin with `^` so that you are requiring a known prefix. A regular expression with neither `^` nor `$` just requires that something appear in the middle.
259
339
 
260
340
  ### Allowed CSS Styles
package/index.js CHANGED
@@ -170,20 +170,24 @@ function sanitizeHtml(html, options, _recursing) {
170
170
  allowedAttributesMap[tag].push('class');
171
171
  }
172
172
 
173
- allowedClassesMap[tag] = [];
174
- allowedClassesRegexMap[tag] = [];
175
- const globRegex = [];
176
- classes.forEach(function(obj) {
177
- if (typeof obj === 'string' && obj.indexOf('*') >= 0) {
178
- globRegex.push(escapeStringRegexp(obj).replace(/\\\*/g, '.*'));
179
- } else if (obj instanceof RegExp) {
180
- allowedClassesRegexMap[tag].push(obj);
181
- } else {
182
- allowedClassesMap[tag].push(obj);
173
+ allowedClassesMap[tag] = classes;
174
+
175
+ if (Array.isArray(classes)) {
176
+ const globRegex = [];
177
+ allowedClassesMap[tag] = [];
178
+ allowedClassesRegexMap[tag] = [];
179
+ classes.forEach(function(obj) {
180
+ if (typeof obj === 'string' && obj.indexOf('*') >= 0) {
181
+ globRegex.push(escapeStringRegexp(obj).replace(/\\\*/g, '.*'));
182
+ } else if (obj instanceof RegExp) {
183
+ allowedClassesRegexMap[tag].push(obj);
184
+ } else {
185
+ allowedClassesMap[tag].push(obj);
186
+ }
187
+ });
188
+ if (globRegex.length) {
189
+ allowedClassesGlobMap[tag] = new RegExp('^(' + globRegex.join('|') + ')$');
183
190
  }
184
- });
185
- if (globRegex.length) {
186
- allowedClassesGlobMap[tag] = new RegExp('^(' + globRegex.join('|') + ')$');
187
191
  }
188
192
  });
189
193
 
@@ -291,6 +295,14 @@ function sanitizeHtml(html, options, _recursing) {
291
295
  delete frame.attribs[a];
292
296
  return;
293
297
  }
298
+ // If the value is empty, check if the attribute is in the allowedEmptyAttributes array.
299
+ // If it is not in the allowedEmptyAttributes array, and it is a known non-boolean attribute, delete it
300
+ // List taken from https://html.spec.whatwg.org/multipage/indices.html#attributes-3
301
+ if (value === '' && (!options.allowedEmptyAttributes.includes(a)) &&
302
+ (options.nonBooleanAttributes.includes(a) || options.nonBooleanAttributes.includes('*'))) {
303
+ delete frame.attribs[a];
304
+ return;
305
+ }
294
306
  // check allowedAttributesMap for the element and attribute and modify the value
295
307
  // as necessary if there are specific values defined.
296
308
  let passedAllowedAttributesMapCheck = false;
@@ -451,7 +463,9 @@ function sanitizeHtml(html, options, _recursing) {
451
463
  return;
452
464
  }
453
465
  } catch (e) {
454
- console.warn('Failed to parse "' + name + ' {' + value + '}' + '", If you\'re running this in a browser, we recommend to disable style parsing: options.parseStyleAttributes: false, since this only works in a node environment due to a postcss dependency, More info: https://github.com/apostrophecms/sanitize-html/issues/547');
466
+ if (typeof window !== 'undefined') {
467
+ console.warn('Failed to parse "' + name + ' {' + value + '}' + '", If you\'re running this in a browser, we recommend to disable style parsing: options.parseStyleAttributes: false, since this only works in a node environment due to a postcss dependency, More info: https://github.com/apostrophecms/sanitize-html/issues/547');
468
+ }
455
469
  delete frame.attribs[a];
456
470
  return;
457
471
  }
@@ -462,6 +476,8 @@ function sanitizeHtml(html, options, _recursing) {
462
476
  result += ' ' + a;
463
477
  if (value && value.length) {
464
478
  result += '="' + escapeHtml(value, true) + '"';
479
+ } else if (options.allowedEmptyAttributes.includes(a)) {
480
+ result += '=""';
465
481
  }
466
482
  } else {
467
483
  delete frame.attribs[a];
@@ -814,6 +830,49 @@ sanitizeHtml.defaults = {
814
830
  'caption', 'col', 'colgroup', 'table', 'tbody', 'td', 'tfoot', 'th',
815
831
  'thead', 'tr'
816
832
  ],
833
+ // Tags that cannot be boolean
834
+ nonBooleanAttributes: [
835
+ 'abbr', 'accept', 'accept-charset', 'accesskey', 'action',
836
+ 'allow', 'alt', 'as', 'autocapitalize', 'autocomplete',
837
+ 'blocking', 'charset', 'cite', 'class', 'color', 'cols',
838
+ 'colspan', 'content', 'contenteditable', 'coords', 'crossorigin',
839
+ 'data', 'datetime', 'decoding', 'dir', 'dirname', 'download',
840
+ 'draggable', 'enctype', 'enterkeyhint', 'fetchpriority', 'for',
841
+ 'form', 'formaction', 'formenctype', 'formmethod', 'formtarget',
842
+ 'headers', 'height', 'hidden', 'high', 'href', 'hreflang',
843
+ 'http-equiv', 'id', 'imagesizes', 'imagesrcset', 'inputmode',
844
+ 'integrity', 'is', 'itemid', 'itemprop', 'itemref', 'itemtype',
845
+ 'kind', 'label', 'lang', 'list', 'loading', 'low', 'max',
846
+ 'maxlength', 'media', 'method', 'min', 'minlength', 'name',
847
+ 'nonce', 'optimum', 'pattern', 'ping', 'placeholder', 'popover',
848
+ 'popovertarget', 'popovertargetaction', 'poster', 'preload',
849
+ 'referrerpolicy', 'rel', 'rows', 'rowspan', 'sandbox', 'scope',
850
+ 'shape', 'size', 'sizes', 'slot', 'span', 'spellcheck', 'src',
851
+ 'srcdoc', 'srclang', 'srcset', 'start', 'step', 'style',
852
+ 'tabindex', 'target', 'title', 'translate', 'type', 'usemap',
853
+ 'value', 'width', 'wrap',
854
+ // Event handlers
855
+ 'onauxclick', 'onafterprint', 'onbeforematch', 'onbeforeprint',
856
+ 'onbeforeunload', 'onbeforetoggle', 'onblur', 'oncancel',
857
+ 'oncanplay', 'oncanplaythrough', 'onchange', 'onclick', 'onclose',
858
+ 'oncontextlost', 'oncontextmenu', 'oncontextrestored', 'oncopy',
859
+ 'oncuechange', 'oncut', 'ondblclick', 'ondrag', 'ondragend',
860
+ 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart',
861
+ 'ondrop', 'ondurationchange', 'onemptied', 'onended',
862
+ 'onerror', 'onfocus', 'onformdata', 'onhashchange', 'oninput',
863
+ 'oninvalid', 'onkeydown', 'onkeypress', 'onkeyup',
864
+ 'onlanguagechange', 'onload', 'onloadeddata', 'onloadedmetadata',
865
+ 'onloadstart', 'onmessage', 'onmessageerror', 'onmousedown',
866
+ 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout',
867
+ 'onmouseover', 'onmouseup', 'onoffline', 'ononline', 'onpagehide',
868
+ 'onpageshow', 'onpaste', 'onpause', 'onplay', 'onplaying',
869
+ 'onpopstate', 'onprogress', 'onratechange', 'onreset', 'onresize',
870
+ 'onrejectionhandled', 'onscroll', 'onscrollend',
871
+ 'onsecuritypolicyviolation', 'onseeked', 'onseeking', 'onselect',
872
+ 'onslotchange', 'onstalled', 'onstorage', 'onsubmit', 'onsuspend',
873
+ 'ontimeupdate', 'ontoggle', 'onunhandledrejection', 'onunload',
874
+ 'onvolumechange', 'onwaiting', 'onwheel'
875
+ ],
817
876
  disallowedTagsMode: 'discard',
818
877
  allowedAttributes: {
819
878
  a: [ 'href', 'name', 'target' ],
@@ -821,6 +880,9 @@ sanitizeHtml.defaults = {
821
880
  // these attributes would make sense if we did.
822
881
  img: [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ]
823
882
  },
883
+ allowedEmptyAttributes: [
884
+ 'alt'
885
+ ],
824
886
  // Lots of these won't come up by default because we don't allow them
825
887
  selfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', 'meta' ],
826
888
  // URL schemes we permit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitize-html",
3
- "version": "2.10.0",
3
+ "version": "2.12.0",
4
4
  "description": "Clean up user-submitted HTML, preserving allowlisted elements and allowlisted attributes on a per-element basis",
5
5
  "sideEffects": false,
6
6
  "main": "index.js",
@@ -38,7 +38,7 @@
38
38
  "eslint-plugin-node": "^11.1.0",
39
39
  "eslint-plugin-promise": "^4.2.1",
40
40
  "eslint-plugin-standard": "^4.0.1",
41
- "mocha": "^7.0.0",
41
+ "mocha": "^10.2.0",
42
42
  "sinon": "^9.0.2"
43
43
  }
44
- }
44
+ }
package/CHANGELOG.md DELETED
@@ -1,410 +0,0 @@
1
- # Changelog
2
-
3
- ## 2.10.0 (2023-02-17)
4
-
5
- - Fix auto-adding escaped closing tags. In other words, do not add implied closing tags to disallowed tags when `disallowedTagMode` is set to any variant of `escape` -- just escape the disallowed tags that are present. This fixes [issue #464](https://github.com/apostrophecms/sanitize-html/issues/464). Thanks to [Daniel Liebner](https://github.com/dliebner)
6
- - Add `tagAllowed()` helper function which takes a tag name and checks it against `options.allowedTags` and returns `true` if the tag is allowed and `false` if it is not.
7
-
8
- ## 2.9.0 (2023-01-27)
9
-
10
- - Add option parseStyleAttributes to skip style parsing. This fixes [issue #547](https://github.com/apostrophecms/sanitize-html/issues/547). Thanks to [Bert Verhelst](https://github.com/bertyhell).
11
-
12
- ## 2.8.1 (2022-12-21)
13
-
14
- - If the argument is a number, convert it to a string, for backwards compatibility. Thanks to [Alexander Schranz](https://github.com/alexander-schranz).
15
-
16
- ## 2.8.0 (2022-12-12)
17
-
18
- - Upgrades `htmlparser2` to new major version `^8.0.0`. Thanks to [Kedar Chandrayan](https://github.com/kedarchandrayan) for this contribution.
19
-
20
- ## 2.7.3 (2022-10-24)
21
-
22
- - If allowedTags is falsy but not exactly `false`, then do not assume that all tags are allowed. Rather, allow no tags in this case, to be on the safe side. This matches the existing documentation and fixes [issue #176](https://github.com/apostrophecms/sanitize-html/issues/176). Thanks to [Kedar Chandrayan](https://github.com/kedarchandrayan) for the fix.
23
-
24
- ## 2.7.2 (2022-09-15)
25
-
26
- - Closing tags must agree with opening tags. This fixes [issue #549](https://github.com/apostrophecms/sanitize-html/issues/549), in which closing tags not associated with any permitted opening tag could be passed through. No known exploit exists, but it's better not to permit this. Thanks to
27
- [Kedar Chandrayan](https://github.com/kedarchandrayan) for the report and the fix.
28
-
29
- ## 2.7.1 (2022-07-20)
30
-
31
- - Protocol-relative URLs are properly supported for script tags. Thanks to [paweljq](https://github.com/paweljq).
32
- - A denial-of-service vulnerability has been fixed by replacing global regular expression replacement logic for comment removal with a new implementation. Thanks to Nariyoshi Chida of NTT Security Japan for pointing out the issue.
33
-
34
- ## 2.7.0 (2022-02-04)
35
-
36
- - Allows a more sensible set of default attributes on `<img />` tags. Thanks to [Zade Viggers](https://github.com/zadeviggers).
37
-
38
- ## 2.6.1 (2021-12-08)
39
-
40
- - Fixes style filtering to retain `!important` when used.
41
- - Fixed trailing text bug on `transformTags` options that was reported on [issue #506](https://github.com/apostrophecms/sanitize-html/issues/506). Thanks to [Alex Rantos](https://github.com/alex-rantos).
42
-
43
- ## 2.6.0 (2021-11-23)
44
-
45
- - Support for regular expressions in the `allowedClasses` option. Thanks to [Alex Rantos](https://github.com/alex-rantos).
46
-
47
- ## 2.5.3 (2021-11-02):
48
-
49
- - Fixed bug introduced by klona 2.0.5, by removing klona entirely.
50
-
51
- ## 2.5.2 (2021-10-13):
52
-
53
- - Nullish HTML input now returns an empty string. Nullish value may be explicit `null`, `undefined` or implicit `undefined` when value is not provided. Thanks to Artem Kostiuk for the contribution.
54
- - Documented that all text content is escaped. Thanks to Siddharth Singh.
55
-
56
- ## 2.5.1 (2021-09-14):
57
- - The `allowedScriptHostnames` and `allowedScriptDomains` options now implicitly purge the inline content of all script tags, not just those with `src` attributes. This behavior was already strongly implied by the fact that they purged it in the case where a `src` attribute was actually present, and is necessary for the feature to provide any real security. Thanks to Grigorii Duca for pointing out the issue.
58
-
59
- ## 2.5.0 (2021-09-08):
60
-
61
- - New `allowedScriptHostnames` option, it enables you to specify which hostnames are allowed in a script tag.
62
- - New `allowedScriptDomains` option, it enables you to specify which domains are allowed in a script tag. Thank you to [Yorick Girard](https://github.com/yorickgirard) for this and the `allowedScriptHostnames` contribution.
63
- - Updates whitelist to allowlist.
64
-
65
- ## 2.4.0 (2021-05-19):
66
- - Added support for class names with wildcards in `allowedClasses`. Thanks to [zhangbenber](https://github.com/zhangbenber) for the contribution.
67
-
68
- ## 2.3.3 (2021-03-19):
69
- - Security fix: `allowedSchemes` and related options did not properly block schemes containing a hyphen, plus sign, period or digit, such as `ms-calculator:`. Thanks to Lukas Euler for pointing out the issue.
70
- - Added a security note about the known risks associated with using the `parser` option, especially `decodeEntities: false`. See the documentation.
71
-
72
- ## 2.3.2 (2021-01-26):
73
-
74
- - Additional fixes for iframe validation exploits. Prevent exploits based on browsers' tolerance of the use of "\" rather than "/" and the presence of whitespace at this point in the URL. Thanks to Ron Masas of [Checkmarx](https://www.checkmarx.com/) for pointing out the issue and writing unit tests.
75
- - Updates README `yarn add` syntax. Thanks to [Tagir Khadshiev](https://github.com/Aspedm) for the contribution.
76
-
77
- ## 2.3.1 (2021-01-22):
78
- - Uses the standard WHATWG URL parser to stop IDNA (Internationalized Domain Name) attacks on the iframe hostname validator. Thanks to Ron Masas of [Checkmarx](https://www.checkmarx.com/) for pointing out the issue and suggesting the use of the WHATWG parser.
79
-
80
- ## 2.3.0 (2020-12-16):
81
- - Upgrades `htmlparser2` to new major version `^6.0.0`. Thanks to [Bogdan Chadkin](https://github.com/TrySound) for the contribution.
82
-
83
- ## 2.2.0 (2020-12-02):
84
- - Adds a note to the README about Typescript support (or the lack-thereof).
85
- - Adds `tel` to the default `allowedSchemes`. Thanks to [Arne Herbots](https://github.com/aHerbots) for this contribution.
86
-
87
- ## 2.1.2 (2020-11-04):
88
- - Fixes typos and inconsistencies in the README. Thanks to [Eric Lefevre-Ardant](https://github.com/elefevre) for this contribution.
89
-
90
- ## 2.1.1 (2020-10-21):
91
- - Fixes a bug when using `allowedClasses` with an `'*'` wildcard selector. Thanks to [Clemens Damke](https://github.com/Cortys) for this contribution.
92
- - Updates mocha to 7.x to resolve security warnings.
93
-
94
- ## 2.1.0 (2020-10-07):
95
- - `sup` added to the default allowed tags list. Thanks to [Julian Lam](https://github.com/julianlam) for the contribution.
96
- - Updates default `allowedTags` README documentation. Thanks to [Marco Arduini](https://github.com/nerfologist) for the contribution.
97
-
98
- ## 2.0.0 (2020-09-23):
99
- - `nestingLimit` option added.
100
- - Updates ESLint config package and fixes warnings.
101
- - Upgrade `is-plain-object` package with named export. Thanks to [Bogdan Chadkin](https://github.com/TrySound) for the contribution.
102
- - Upgrade `postcss` package and drop Node 11 and Node 13 support (enforced by postcss).
103
-
104
- ### Backwards compatibility breaks:
105
- - There is no build. You should no longer directly link to a sanitize-html file directly in the browser as it is using modern Javascript that is not fully supported by all major browsers (depending on your definition). You should now include sanitize-html in your project build for this purpose if you have one.
106
- - On the server side, Node.js 10 or higher is required.
107
- - The default `allowedTags` array was updated significantly. This mostly added HTML tags to be more comprehensive by default. You should review your projects and consider the `allowedTags` defaults if you are not already overriding them.
108
-
109
- ## 2.0.0-rc.2 (2020-09-09):
110
- - Always use existing `has` function rather than duplicating it.
111
-
112
- ## 2.0.0-rc.1 (2020-08-26):
113
- - Upgrade `klona` package. Thanks to [Bogdan Chadkin](https://github.com/TrySound) for the contribution.
114
-
115
- ## 2.0.0-beta.2:
116
- - Add `files` to `package.json` to prevent publishing unnecessary files to npm #392. Thanks to [styfle](https://github.com/styfle) for the contribution.
117
- - Removes `iframe` and `nl` from default allowed tags. Adds most innocuous tags to the default `allowedTags` array.
118
- - Fixes a bug when using `transformTags` with out `textFilter`. Thanks to [Andrzej Porebski](https://github.com/andpor) for the help with a failing test.
119
-
120
- ## 2.0.0-beta:
121
- - Moves the `index.js` file to the project root and removes all build steps within the package. Going forward, it is up to the developer to include sanitize-html in their project builds as-needed. This removes major points of conflict with project code and frees this module to not worry about myriad build-related questions.
122
- - Replaces lodash with utility packages: klona, is-plain-object, deepmerge, escape-string-regexp.
123
- - Makes custom tag transformations less error-prone by escaping frame `innerText`. Thanks to [Mike Samuel](https://github.com/mikesamuel) for the contribution. Prior to this patch, tag transformations which turned an attribute
124
- value into a text node could be vulnerable to code execution.
125
- - Updates code to use modern features including `const`/`let` variable assignment.
126
- - ESLint clean up.
127
- - Updates `is-plain-object` to the 4.x major version.
128
- - Updates `srcset` to the 3.x major version.
129
-
130
- Thanks to [Bogdan Chadkin](https://github.com/TrySound) for contributions to this major version update.
131
-
132
- ## 1.27.5 (2020-09-23):
133
- - Updates README to include ES modules syntax.
134
-
135
- ## 1.27.4 (2020-08-26):
136
- - Fixes an IE11 regression from using `Array.prototype.includes`, replacing it with `Array.prototype.indexOf`.
137
-
138
- ## 1.27.3 (2020-08-12):
139
- - Fixes a bug when using `transformTags` with out `textFilter`. Thanks to [Andrzej Porebski](https://github.com/andpor) for the help with a failing test.
140
-
141
- ## 1.27.2 (2020-07-29):
142
- - Fixes CHANGELOG links. Thanks to [Alex Mayer](https://github.com/amayer5125) for the contribution.
143
- - Replaces `srcset` with `parse-srcset`. Thanks to [Massimiliano Mirra](https://github.com/bard) for the contribution.
144
-
145
- ## 1.27.1 (2020-07-15):
146
- - Removes the unused chalk dependency.
147
- - Adds configuration for a Github stale bot.
148
- - Replace `xtend` package with native `Object.assign`.
149
-
150
- ## 1.27.0:
151
- - Adds the `allowedIframeDomains` option. This works similar to `allowedIframeHostnames`, where you would set it to an array of web domains. It would then permit any hostname on those domains to be used in iframe `src` attributes. Thanks to [Stanislav Kravchenko](https://github.com/StanisLove) for the contribution.
152
-
153
- ## 1.26.0:
154
- - Adds the `option` element to the default `nonTextTagsArray` of tags with contents that aren't meant to be displayed visually as text. This can be overridden with the `nonTextTags` option.
155
-
156
- ## 1.25.0:
157
- - Adds `enforceHtmlBoundary` option to process code bounded by the `html` tag, discarding any code outside of those tags.
158
- - Migrates to the main lodash package from the per method packages since they are deprecated and cause code duplication. Thanks to [Merceyz](https://github.com/merceyz) for the contribution.
159
- - Adds a warning when `style` and `script` tags are allowed, as they are inherently vulnerable to being used in XSS attacks. That warning can be disabled by including the option `allowVulnerableTags: true` so this choice is knowing and explicit.
160
-
161
- ## 1.24.0:
162
- - Fixes a bug where self-closing tags resulted in deletion with `disallowedTagsMode: 'escape'` set. Thanks to [Thiago Negri](https://github.com/thiago-negri) for the contribution.
163
- - Adds `abbr` to the default `allowedTags` for better accessibility support. Thanks to [Will Farrell](https://github.com/willfarrell) for the contribution.
164
- - Adds a `mediaChildren` property to the `frame` object in custom filters. This allows you to check for links or other parent tags that contain self-contained media to prevent collapse, regardless of whether there is also text inside. Thanks to [axdg](https://github.com/axdg) for the initial implementation and [Marco Arduini](https://github.com/nerfologist) for a failing test contribution.
165
-
166
- ## 1.23.0:
167
- - Adds eslint configuration and adds eslint to test script.
168
- - Sets `sideEffects: false` on package.json to allow module bundlers like webpack tree-shake this module and all the dependencies from client build. Thanks to [Egor Voronov](https://github.com/egorvoronov) for the contribution.
169
- - Adds the `tagName` (HTML element name) as a second parameter passed to `textFilter`. Thanks to [Slava](https://github.com/slavaGanzin) for the contribution.
170
-
171
- ## 1.22.1:
172
- ncreases the patch version of `lodash.mergewith` to enforce an audit fix.
173
-
174
- ## 1.22.0:
175
- 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.
176
-
177
- ## 1.21.1:
178
- fixed issue with bad `main` setting in package.json that broke 1.21.0.
179
-
180
- ## 1.21.0:
181
- 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.
182
-
183
- ## 1.20.1:
184
- Fix failing tests, add CircleCI config
185
-
186
- ## 1.20.0:
187
- 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.
188
-
189
- ## 1.19.3:
190
- reverted to `postcss` due to a [reported issue with `css-tree` that might or might not have XSS implications](https://github.com/punkave/sanitize-html/issues/269).
191
-
192
- ## 1.19.2:
193
-
194
- * Switched out the heavy `postcss` dependency for the lightweight `css-tree` module. No API changes. Thanks to Justin Braithwaite.
195
- * Various doc updates. Thanks to Pulkit Aggarwal and Cody Robertson.
196
-
197
- ## 1.19.1:
198
-
199
- * `"` characters are now entity-escaped only when they appear in attribute values, reducing the verbosity of the resulting markup.
200
-
201
- * Fixed a regression introduced in version 1.18.5 in the handling of markup that looks similar to a valid entity, but isn't. The bogus entity was passed through intact, i.e. `&0;` did not become `&amp;0;` as it should have. This fix has been made for the default parser settings only. There is no fix yet for those who wish to enable `decodeEntities: false`. That will require improving the alternative encoder in the `escapeHtml` function to only pass 100% valid entities.
202
-
203
- **For those using the default `parser` settings this bug is fixed.** Read on if you are using alternative `parser` settings.
204
-
205
- When `decodeEntities: true` is in effect (the default), this is not a problem because we only have to encode `& < > "` and we always encode those things.
206
-
207
- There is currently a commented-out test which verifies one example of the problem when `decodeEntities` is false. However a correct implementation would need to not only pass that simple example but correctly escape all invalid entities, and not escape those that are valid.
208
-
209
- ## 1.19.0:
210
-
211
- * New `allowIframeRelativeUrls` option. It defaults to `true` unless `allowedIframeHostnames` is present, in which case it defaults to false, for backwards compatibility with existing behavior in both cases; however you can now set the option explicitly to allow both certain hostnames and relative URLs. Thanks to Rick Martin.
212
-
213
- ## 1.18.5:
214
-
215
- * Stop double encoding ampersands on HTML entities. Thanks to Will Gibson.
216
-
217
- ## 1.18.4:
218
-
219
- * Removed incorrect `browser` key, restoring frontend build. Thanks to Felix Becker.
220
-
221
- ## 1.18.3:
222
-
223
- * `iframe` is an allowed tag by default, to better facilitate typical use cases and the use of the `allowedIframeHostnames` option.
224
- * Documentation improvements.
225
- * More browser packaging improvements.
226
- * Protocol-relative URLs are properly supported for iframe tags.
227
-
228
- ## 1.18.2:
229
-
230
- * Travis tests passing.
231
- * Fixed another case issue — and instituted Travis CI testing so this doesn't happen again. Sorry for the hassle.
232
-
233
- ## 1.18.1:
234
-
235
- * A file was required with incorrect case, breaking the library on case sensitive filesystems such as Linux. Fixed.
236
-
237
- ## 1.18.0:
238
-
239
- * The new `allowedSchemesAppliedToAttributes` option. This determines which attributes are validated as URLs, replacing the old hardcoded list of `src` and `href` only. The default list now includes `cite`. Thanks to ml-dublin for this contribution.
240
- * It is now easy to configure a specific list of allowed values for an attribute. When configuring `allowedAttributes`, rather than listing an attribute name, simply list an object with an attribute `name` property and an allowed `values` array property. You can also add `multiple: true` to allow multiple space-separated allowed values in the attribute, otherwise the attribute must match one and only one of the allowed values. Thanks again to ml-dublin for this contribution.
241
- * Fixed a bug in the npm test procedure.
242
-
243
- ## 1.17.0:
244
- The new `allowedIframeHostnames` option. If present, this must be an array, and only iframe `src` URLs hostnames (complete hostnames; domain name matches are not enough) that appear on this list are allowed. You must also configure `hostname` as an allowed attribute for `iframe`. Thanks to Ryan Verys for this contribution.
245
-
246
- ## 1.16.3:
247
- Don't throw away the browserified versions before publishing them. `prepare` is not a good place to `make clean`, it runs after `prepublish`.
248
-
249
- ## 1.16.2:
250
- `sanitize-html` is now compiled with `babel`. An npm `prepublish` script takes care of this at `npm publish` time, so the latest code should always be compiled to operate all the way back to ES5 browsers and earlier versions of Node. Thanks to Ayushya Jaiswal.
251
-
252
- Please note that running `sanitize-html` in the browser is usually a security hole. Are you trusting the browser? Anyone could bypass that using the network panel. Sanitization is almost always best done on servers and that is the primary use case for this module.
253
-
254
- ## 1.16.1:
255
- changelog formatting only.
256
-
257
- ## 1.16.0:
258
- support for sanitizing inline CSS styles, by specifying the allowed attributes and a regular expression for each. Thanks to Cameron Will and Michael Loschiavo.
259
-
260
- ## 1.15.0:
261
- if configured as an allowed attribute (not the default), check for naughty URLs in `srcset` attributes. Thanks to Mike Samuel for the nudge to do this and to Sindre Sorhus for the `srcset` module.
262
-
263
- ## 1.14.3:
264
- inadvertent removal of lodash regexp quote dependency in 1.14.2 has been corrected.
265
-
266
- ## 1.14.2:
267
- 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.
268
-
269
- ## 1.14.1:
270
- documented `allowProtocolRelative` option. No code changes from 1.14.0, released a few moments ago.
271
-
272
- ## 1.14.0:
273
- 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.
274
-
275
- ## 1.13.0:
276
- `transformTags` can now add text to an element that initially had none. Thanks to Dushyant Singh.
277
-
278
- ## 1.12.0:
279
- option to build for browser-side use. Thanks to Michael Blum.
280
-
281
- ## 1.11.4:
282
- fixed crash when `__proto__` is a tag name. Now using a safe check for the existence of properties in all cases. Thanks to Andrew Krasichkov.
283
-
284
- Fixed XSS attack vector via `textarea` tags (when explicitly allowed). Decided that `script` (obviously) and `style` (due to its own XSS vectors) cannot realistically be afforded any XSS protection if allowed, unless we add a full CSS parser. Thanks again to Andrew Krasichkov.
285
-
286
- ## 1.11.3:
287
- bumped `htmlparser2` version to address crashing bug in older version. Thanks to e-jigsaw.
288
-
289
- ## 1.11.2:
290
- fixed README typo that interfered with readability due to markdown issues. No code changes. Thanks to Mikael Korpela. Also improved code block highlighting in README. Thanks to Alex Siman.
291
-
292
- ## 1.11.1:
293
- fixed a regression introduced in 1.11.0 which caused the closing tag of the parent of a `textarea` tag to be lost. Thanks to Stefano Sala, who contributed the missing test.
294
-
295
- ## 1.11.0:
296
- added the `nonTextTags` option, with tests.
297
-
298
- ## 1.10.1:
299
- documentation cleanup. No code changes. Thanks to Rex Schrader.
300
-
301
- ## 1.10.0:
302
- `allowedAttributes` now allows you to allow attributes for all tags by specifying `*` as the tag name. Thanks to Zdravko Georgiev.
303
-
304
- ## 1.9.0:
305
- `parser` option allows options to be passed directly to `htmlparser`. Thanks to Danny Scott.
306
-
307
- ## 1.8.0:
308
-
309
- * `transformTags` now accepts the `*` wildcard to transform all tags. Thanks to Jamy Timmermans.
310
-
311
- * Text that has been modified by `transformTags` is then passed through `textFilter`. Thanks to Pavlo Yurichuk.
312
-
313
- * Content inside `textarea` is discarded if `textarea` is not allowed. I don't know why it took me this long to see that this is just common sense. Thanks to David Frank.
314
-
315
- ## 1.7.2:
316
- removed `array-includes` dependency in favor of `indexOf`, which is a little more verbose but slightly faster and doesn't require a shim. Thanks again to Joseph Dykstra.
317
-
318
- ## 1.7.1:
319
- removed lodash dependency, adding lighter dependencies and polyfills in its place. Thanks to Joseph Dykstra.
320
-
321
- ## 1.7.0:
322
- introduced `allowedSchemesByTag` option. Thanks to Cameron Will.
323
-
324
- ## 1.6.1:
325
- the string `'undefined'` (as opposed to `undefined`) is perfectly valid text and shouldn't be expressly converted to the empty string.
326
-
327
- ## 1.6.0:
328
- added `textFilter` option. Thanks to Csaba Palfi.
329
-
330
- ## 1.5.3:
331
- do not escape special characters inside a script or style element, if they are allowed. This is consistent with the way browsers parse them; nothing closes them except the appropriate closing tag for the entire element. Of course, this only comes into play if you actually choose to allow those tags. Thanks to aletorrado.
332
-
333
- ## 1.5.2:
334
- guard checks for allowed attributes correctly to avoid an undefined property error. Thanks to Zeke.
335
-
336
- ## 1.5.1:
337
- updated to htmlparser2 1.8.x. Started using the `decodeEntities` option, which allows us to pass our filter evasion tests without the need to recursively invoke the filter.
338
-
339
- ## 1.5.0:
340
- support for `*` wildcards in allowedAttributes. With tests. Thanks to Calvin Montgomery.
341
-
342
- ## 1.4.3:
343
- invokes itself recursively until the markup stops changing to guard against [this issue](https://github.com/fb55/htmlparser2/issues/105). Bump to htmlparser2 version 3.7.x.
344
-
345
- ## 1.4.1, 1.4.2:
346
- more tests.
347
-
348
- ## 1.4.0:
349
- ability to allow all attributes or tags through by setting `allowedAttributes` and/or `allowedTags` to false. Thanks to Anand Thakker.
350
-
351
- ## 1.3.0:
352
- `attribs` now available on frames passed to exclusive filter.
353
-
354
- ## 1.2.3:
355
- fixed another possible XSS attack vector; no definitive exploit was found but it looks possible. [See this issue.](https://github.com/punkave/sanitize-html/pull/20) Thanks to Jim O'Brien.
356
-
357
- ## 1.2.2:
358
- reject `javascript:` URLs when disguised with an internal comment. This is probably not respected by browsers anyway except when inside an XML data island element, which you almost certainly are not allowing in your `allowedTags`, but we aim to be thorough. Thanks to Jim O'Brien.
359
-
360
- ## 1.2.1:
361
- fixed crashing bug when presented with bad markup. The bug was in the `exclusiveFilter` mechanism. Unit test added. Thanks to Ilya Kantor for catching it.
362
-
363
- ## 1.2.0:
364
- * The `allowedClasses` option now allows you to permit CSS classes in a fine-grained way.
365
-
366
- * Text passed to your `exclusiveFilter` function now includes the text of child elements, making it more useful for identifying elements that truly lack any inner text.
367
-
368
- ## 1.1.7:
369
- use `he` for entity decoding, because it is more actively maintained.
370
-
371
- ## 1.1.6:
372
- `allowedSchemes` option for those who want to permit `data` URLs and such.
373
-
374
- ## 1.1.5:
375
- just a packaging thing.
376
-
377
- ## 1.1.4:
378
- custom exclusion filter.
379
-
380
- ## 1.1.3:
381
- moved to lodash. 1.1.2 pointed to the wrong version of lodash.
382
-
383
- ## 1.1.0:
384
- the `transformTags` option was added. Thanks to [kl3ryk](https://github.com/kl3ryk).
385
-
386
- ## 1.0.3:
387
- fixed several more javascript URL attack vectors after [studying the XSS filter evasion cheat sheet](https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet) to better understand my enemy. Whitespace characters (codes from 0 to 32), which browsers ignore in URLs in certain cases allowing the "javascript" scheme to be snuck in, are now stripped out when checking for naughty URLs. Thanks again to [pinpickle](https://github.com/pinpickle).
388
-
389
- ## 1.0.2:
390
- fixed a javascript URL attack vector. naughtyHref must entity-decode URLs and also check for mixed-case scheme names. Thanks to [pinpickle](https://github.com/pinpickle).
391
-
392
- ## 1.0.1:
393
- Doc tweaks.
394
-
395
- ## 1.0.0:
396
- If the style tag is disallowed, then its content should be dumped, so that it doesn't appear as text. We were already doing this for script tags, however in both cases the content is now preserved if the tag is explicitly allowed.
397
-
398
- We're rocking our tests and have been working great in production for months, so: declared 1.0.0 stable.
399
-
400
- ## 0.1.3:
401
- do not double-escape entities in attributes or text. Turns out the "text" provided by htmlparser2 is already escaped.
402
-
403
- ## 0.1.2:
404
- packaging error meant it wouldn't install properly.
405
-
406
- ## 0.1.1:
407
- discard the text of script tags.
408
-
409
- ## 0.1.0:
410
- initial release.