sanitize-html 1.22.0 → 1.25.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.
- package/CHANGELOG.md +18 -1
- package/README.md +30 -13
- package/dist/sanitize-html-es2015.js +2913 -3194
- package/dist/sanitize-html.js +800 -1473
- package/dist/sanitize-html.min.js +1 -1
- package/package.json +16 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
+
1.25.0:
|
|
4
|
+
- Adds `enforceHtmlBoundary` option to process code bounded by the `html` tag, discarding any code outside of those tags.
|
|
5
|
+
- 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.
|
|
6
|
+
- 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.
|
|
7
|
+
|
|
8
|
+
1.24.0:
|
|
9
|
+
- 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.
|
|
10
|
+
- Adds `abbr` to the default `allowedTags` for better accessibility support. Thanks to [Will Farrell](https://github.com/willfarrell) for the contribution.
|
|
11
|
+
- 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.
|
|
12
|
+
|
|
13
|
+
1.23.0:
|
|
14
|
+
- Adds eslint configuration and adds eslint to test script.
|
|
15
|
+
- 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.
|
|
16
|
+
- Adds the `tagName` (HTML element name) as a second parameter passed to `textFilter`. Thanks to [Slava](https://github.com/slavaGanzin) for the contribution.
|
|
17
|
+
|
|
18
|
+
1.22.1: Increases the patch version of `lodash.mergewith` to enforce an audit fix.
|
|
19
|
+
|
|
3
20
|
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.
|
|
4
21
|
|
|
5
22
|
1.21.1: fixed issue with bad `main` setting in package.json that broke 1.21.0.
|
|
@@ -83,7 +100,7 @@ Please note that running `sanitize-html` in the browser is usually a security ho
|
|
|
83
100
|
|
|
84
101
|
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.
|
|
85
102
|
|
|
86
|
-
1.14.1: documented `allowProtocolRelative` option. No code changes from 1.14.0, released a few moments ago.
|
|
103
|
+
1.14.1: documented `allowProtocolRelative` option. No code changes from 1.14.0, released a few moments ago.
|
|
87
104
|
|
|
88
105
|
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.
|
|
89
106
|
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# sanitize-html
|
|
2
2
|
|
|
3
|
-
[](https://circleci.com/gh/apostrophecms/sanitize-html/tree/master)
|
|
4
4
|
|
|
5
|
-
<a href="https://apostrophecms.
|
|
5
|
+
<a href="https://apostrophecms.com/"><img src="https://raw.github.com/apostrophecms/sanitize-html/master/logos/logo-box-madefor.png" align="right" /></a>
|
|
6
6
|
|
|
7
7
|
`sanitize-html` provides a simple HTML sanitizer with a clear API.
|
|
8
8
|
|
|
@@ -107,7 +107,7 @@ If you do not specify `allowedTags` or `allowedAttributes` our default list is a
|
|
|
107
107
|
|
|
108
108
|
```js
|
|
109
109
|
allowedTags: [ 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol',
|
|
110
|
-
'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div',
|
|
110
|
+
'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'abbr', 'code', 'hr', 'br', 'div',
|
|
111
111
|
'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'iframe' ],
|
|
112
112
|
disallowedTagsMode: 'discard',
|
|
113
113
|
allowedAttributes: {
|
|
@@ -123,7 +123,8 @@ selfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', '
|
|
|
123
123
|
allowedSchemes: [ 'http', 'https', 'ftp', 'mailto' ],
|
|
124
124
|
allowedSchemesByTag: {},
|
|
125
125
|
allowedSchemesAppliedToAttributes: [ 'href', 'src', 'cite' ],
|
|
126
|
-
allowProtocolRelative: true
|
|
126
|
+
allowProtocolRelative: true,
|
|
127
|
+
enforceHtmlBoundary: false
|
|
127
128
|
```
|
|
128
129
|
|
|
129
130
|
#### "What if I want to allow all tags or all attributes?"
|
|
@@ -187,6 +188,15 @@ allowedAttributes: {
|
|
|
187
188
|
'*': [ 'href', 'align', 'alt', 'center', 'bgcolor' ]
|
|
188
189
|
}
|
|
189
190
|
```
|
|
191
|
+
### Discarding text outside of ```<html></html>``` tags
|
|
192
|
+
|
|
193
|
+
Some text editing applications generate HTML to allow copying over to a web application. These can sometimes include undesireable control characters after terminating `html` tag. By default sanitize-html will not discard these characters, instead returning them in sanitized string. This behaviour can be modified using `enforceHtmlBoundary` option.
|
|
194
|
+
|
|
195
|
+
Setting this option to true will instruct sanitize-html to discard all characters outside of `html` tag boundaries -- before `<html>` and after `</html>` tags.
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
enforceHtmlBoundary: true
|
|
199
|
+
```
|
|
190
200
|
|
|
191
201
|
### htmlparser2 Options
|
|
192
202
|
|
|
@@ -301,10 +311,11 @@ sanitizeHtml(
|
|
|
301
311
|
|
|
302
312
|
The `frame` object supplied to the callback provides the following attributes:
|
|
303
313
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
314
|
+
- `tag`: The tag name, i.e. `'img'`.
|
|
315
|
+
- `attribs`: The tag's attributes, i.e. `{ src: "/path/to/tux.png" }`.
|
|
316
|
+
- `text`: The text content of the tag.
|
|
317
|
+
- `mediaChildren`: Immediate child tags that are likely to represent self-contained media (e.g., `img`, `video`, `picture`, `iframe`). See the `mediaTags` variable in `src/index.js` for the full list.
|
|
318
|
+
- `tagPosition`: The index of the tag's position in the result string.
|
|
308
319
|
|
|
309
320
|
You can also process all text content with a provided filter function. Let's say we want an ellipsis instead of three dots.
|
|
310
321
|
|
|
@@ -318,7 +329,9 @@ We can do that with the following filter:
|
|
|
318
329
|
sanitizeHtml(
|
|
319
330
|
'<p>some text...</p>',
|
|
320
331
|
{
|
|
321
|
-
textFilter: function(text) {
|
|
332
|
+
textFilter: function(text, tagName) {
|
|
333
|
+
if (['a'].indexOf(tagName) > -1) return //Skip anchor tags
|
|
334
|
+
|
|
322
335
|
return text.replace(/\.\.\./, '…');
|
|
323
336
|
}
|
|
324
337
|
}
|
|
@@ -495,7 +508,11 @@ nonTextTags: [ 'style', 'script', 'textarea', 'noscript' ]
|
|
|
495
508
|
|
|
496
509
|
Note that if you use this option you are responsible for stating the entire list. This gives you the power to retain the content of `textarea`, if you want to.
|
|
497
510
|
|
|
498
|
-
The content still gets escaped properly, with the exception of the `script` and
|
|
511
|
+
The content still gets escaped properly, with the exception of the `script` and
|
|
512
|
+
`style` tags. *Allowing either `script` or `style` leaves you open to XSS
|
|
513
|
+
attacks. Don't do that* unless you have good reason to trust their origin.
|
|
514
|
+
sanitize-html will log a warning if these tags are allowed, which can be
|
|
515
|
+
disabled with the `allowVulnerableTags: true` option.
|
|
499
516
|
|
|
500
517
|
### Choose what to do with disallowed tags
|
|
501
518
|
|
|
@@ -515,10 +532,10 @@ Valid values are: `'discard'` (default), `'escape'` (escape the tag) and `'recur
|
|
|
515
532
|
|
|
516
533
|
## Changelog
|
|
517
534
|
|
|
518
|
-
[The changelog is now in a separate file for readability.](https://github.com/
|
|
535
|
+
[The changelog is now in a separate file for readability.](https://github.com/apostrophecms/sanitize-html/blob/master/CHANGELOG.md)
|
|
519
536
|
|
|
520
537
|
## Support
|
|
521
538
|
|
|
522
|
-
Feel free to open issues on [github](http://github.com/
|
|
539
|
+
Feel free to open issues on [github](http://github.com/apostrophecms/sanitize-html).
|
|
523
540
|
|
|
524
|
-
<a href="http://
|
|
541
|
+
<a href="http://apostrophecms.com/"><img src="https://raw.github.com/apostrophecms/sanitize-html/master/logos/logo-box-builtby.png" /></a>
|