apostrophecms/sanitize-html (sanitize-html)
### [`v2.12.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2121-2024-02-22)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/5a5a74e179ef98075a0c61789f64e009f6b4ac29...2.12.1)
- Do not parse sourcemaps in `post-css`. This fixes a vulnerability in which information about the existence or non-existence of files on a server could be disclosed via properly crafted HTML input when the `style` attribute is allowed by the configuration. Thanks to the [Snyk Security team](https://snyk.io/) for the disclosure and to [Dylan Armstrong](https://dylan.is/) for the fix.
### [`v2.12.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2120-2024-02-21)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.11.0...5a5a74e179ef98075a0c61789f64e009f6b4ac29)
- Introduced the `allowedEmptyAttributes` option, enabling explicit specification of empty string values for select attributes, with the default attribute set to `alt`. Thanks to [Na](https://togithub.com/zhna123) for the contribution.
- Clarified the use of SVGs with a new test and changes to documentation. Thanks to [Gauav Kumar](https://togithub.com/gkumar9891) for the contribution.
- Do not process source maps when processing style tags with PostCSS.
### [`v2.11.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2110-2023-06-21)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.10.0...2.11.0)
- Fix to allow `false` in `allowedClasses` attributes. Thanks to [Kevin Jiang](https://togithub.com/KevinSJ) for this fix!
- Upgrade mocha version
- Apply small linter fixes in tests
- Add `.idea` temp files to `.gitignore`
- Thanks to [Vitalii Shpital](https://togithub.com/VitaliiShpital) for the updates!
- Show parseStyleAttributes warning in browser only. Thanks to [mog422](https://togithub.com/mog422) for this update!
- Remove empty non-boolean attributes via an exhaustive, configurable list of known non-boolean attributes. [Thanks to Dylan Armstrong](https://togithub.com/dylanarmstrong) for this update!
### [`v2.10.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2100-2023-02-17)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.9.0...2.10.0)
- 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://togithub.com/apostrophecms/sanitize-html/issues/464). Thanks to [Daniel Liebner](https://togithub.com/dliebner)
- 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.
### [`v2.9.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#290-2023-01-27)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.8.1...2.9.0)
- Add option parseStyleAttributes to skip style parsing. This fixes [issue #547](https://togithub.com/apostrophecms/sanitize-html/issues/547). Thanks to [Bert Verhelst](https://togithub.com/bertyhell).
### [`v2.8.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#281-2022-12-21)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.8.0...2.8.1)
- If the argument is a number, convert it to a string, for backwards compatibility. Thanks to [Alexander Schranz](https://togithub.com/alexander-schranz).
### [`v2.8.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#280-2022-12-12)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.3...2.8.0)
- Upgrades `htmlparser2` to new major version `^8.0.0`. Thanks to [Kedar Chandrayan](https://togithub.com/kedarchandrayan) for this contribution.
### [`v2.7.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#273-2022-10-24)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.2...2.7.3)
- 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://togithub.com/apostrophecms/sanitize-html/issues/176). Thanks to [Kedar Chandrayan](https://togithub.com/kedarchandrayan) for the fix.
### [`v2.7.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#272-2022-09-15)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.1...2.7.2)
- Closing tags must agree with opening tags. This fixes [issue #549](https://togithub.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
[Kedar Chandrayan](https://togithub.com/kedarchandrayan) for the report and the fix.
### [`v2.7.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#271-2022-07-20)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.0...2.7.1)
- Protocol-relative URLs are properly supported for script tags. Thanks to [paweljq](https://togithub.com/paweljq).
- 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.
### [`v2.7.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#270-2022-02-04)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.6.1...2.7.0)
- Allows a more sensible set of default attributes on `` tags. Thanks to [Zade Viggers](https://togithub.com/zadeviggers).
### [`v2.6.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#261-2021-12-08)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.6.0...2.6.1)
- Fixes style filtering to retain `!important` when used.
- Fixed trailing text bug on `transformTags` options that was reported on [issue #506](https://togithub.com/apostrophecms/sanitize-html/issues/506). Thanks to [Alex Rantos](https://togithub.com/alex-rantos).
### [`v2.6.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#260-2021-11-23)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.5.3...2.6.0)
- Support for regular expressions in the `allowedClasses` option. Thanks to [Alex Rantos](https://togithub.com/alex-rantos).
### [`v2.5.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#253-2021-11-02-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.5.2...2.5.3)
- Fixed bug introduced by klona 2.0.5, by removing klona entirely.
### [`v2.5.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#252-2021-10-13-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.5.1...2.5.2)
- 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.
- Documented that all text content is escaped. Thanks to Siddharth Singh.
### [`v2.5.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#251-2021-09-14-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.5.0...2.5.1)
- 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.
### [`v2.5.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#250-2021-09-08-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.4.0...2.5.0)
- New `allowedScriptHostnames` option, it enables you to specify which hostnames are allowed in a script tag.
- New `allowedScriptDomains` option, it enables you to specify which domains are allowed in a script tag. Thank you to [Yorick Girard](https://togithub.com/yorickgirard) for this and the `allowedScriptHostnames` contribution.
- Updates whitelist to allowlist.
### [`v2.4.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#240-2021-05-19-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.3.3...2.4.0)
- Added support for class names with wildcards in `allowedClasses`. Thanks to [zhangbenber](https://togithub.com/zhangbenber) for the contribution.
### [`v2.3.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#233-2021-03-19-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.3.2...2.3.3)
- 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.
- Added a security note about the known risks associated with using the `parser` option, especially `decodeEntities: false`. See the documentation.
### [`v2.3.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#232-2021-01-26-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.3.1...2.3.2)
- 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.
- Updates README `yarn add` syntax. Thanks to [Tagir Khadshiev](https://togithub.com/Aspedm) for the contribution.
### [`v2.3.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#231-2021-01-22-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.3.0...2.3.1)
- 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.
### [`v2.3.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#230-2020-12-16-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.2.0...2.3.0)
- Upgrades `htmlparser2` to new major version `^6.0.0`. Thanks to [Bogdan Chadkin](https://togithub.com/TrySound) for the contribution.
### [`v2.2.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#220-2020-12-02-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.1.2...2.2.0)
- Adds a note to the README about Typescript support (or the lack-thereof).
- Adds `tel` to the default `allowedSchemes`. Thanks to [Arne Herbots](https://togithub.com/aHerbots) for this contribution.
### [`v2.1.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#212-2020-11-04-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.1.1...2.1.2)
- Fixes typos and inconsistencies in the README. Thanks to [Eric Lefevre-Ardant](https://togithub.com/elefevre) for this contribution.
### [`v2.1.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#211-2020-10-21-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.1.0...2.1.1)
- Fixes a bug when using `allowedClasses` with an `'*'` wildcard selector. Thanks to [Clemens Damke](https://togithub.com/Cortys) for this contribution.
- Updates mocha to 7.x to resolve security warnings.
### [`v2.1.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#210-2020-10-07-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.0.0...2.1.0)
- `sup` added to the default allowed tags list. Thanks to [Julian Lam](https://togithub.com/julianlam) for the contribution.
- Updates default `allowedTags` README documentation. Thanks to [Marco Arduini](https://togithub.com/nerfologist) for the contribution.
### [`v2.0.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#200-2020-09-23-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/9f36c3ca3013b279f9eaa8e85c1ef581bdaf61ba...2.0.0)
- `nestingLimit` option added.
- Updates ESLint config package and fixes warnings.
- Upgrade `is-plain-object` package with named export. Thanks to [Bogdan Chadkin](https://togithub.com/TrySound) for the contribution.
- Upgrade `postcss` package and drop Node 11 and Node 13 support (enforced by postcss).
##### Backwards compatibility breaks:
- 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.
- On the server side, Node.js 10 or higher is required.
- 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.
### [`v1.27.5`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1275-2020-09-23-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.27.4...9f36c3ca3013b279f9eaa8e85c1ef581bdaf61ba)
- Updates README to include ES modules syntax.
### [`v1.27.4`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1274-2020-08-26-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/788b7a649e1ffb0de0d1f0f25a6b0b21093768ca...1.27.4)
- Fixes an IE11 regression from using `Array.prototype.includes`, replacing it with `Array.prototype.indexOf`.
### [`v1.27.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1273-2020-08-12-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1f45e5f3f3de5789a4c99eea9a106676fe580034...788b7a649e1ffb0de0d1f0f25a6b0b21093768ca)
- Fixes a bug when using `transformTags` with out `textFilter`. Thanks to [Andrzej Porebski](https://togithub.com/andpor) for the help with a failing test.
### [`v1.27.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1272-2020-07-29-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/8bce25160dab6396cd9c98b7bf490b7e64f35b21...1f45e5f3f3de5789a4c99eea9a106676fe580034)
- Fixes CHANGELOG links. Thanks to [Alex Mayer](https://togithub.com/amayer5125) for the contribution.
- Replaces `srcset` with `parse-srcset`. Thanks to [Massimiliano Mirra](https://togithub.com/bard) for the contribution.
### [`v1.27.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1271-2020-07-15-)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/d7031b3ce21c7e5abb83e4027dca582da496b452...8bce25160dab6396cd9c98b7bf490b7e64f35b21)
- Removes the unused chalk dependency.
- Adds configuration for a Github stale bot.
- Replace `xtend` package with native `Object.assign`.
### [`v1.27.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1270)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/13f3a178669df4334907fbce8501342ba48e3ecd...d7031b3ce21c7e5abb83e4027dca582da496b452)
- 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://togithub.com/StanisLove) for the contribution.
### [`v1.26.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1260)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/f8e8c40d4cba987f305d3a300b30a7bbee778349...13f3a178669df4334907fbce8501342ba48e3ecd)
- 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.
### [`v1.25.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1250)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/10ee1276f9722ff0c6f7504f92547d74c4dd3274...f8e8c40d4cba987f305d3a300b30a7bbee778349)
- Adds `enforceHtmlBoundary` option to process code bounded by the `html` tag, discarding any code outside of those tags.
- Migrates to the main lodash package from the per method packages since they are deprecated and cause code duplication. Thanks to [Merceyz](https://togithub.com/merceyz) for the contribution.
- 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.
### [`v1.24.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1240)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/22964d642366eea191e2961898a2df5c6426f3f0...10ee1276f9722ff0c6f7504f92547d74c4dd3274)
- Fixes a bug where self-closing tags resulted in deletion with `disallowedTagsMode: 'escape'` set. Thanks to [Thiago Negri](https://togithub.com/thiago-negri) for the contribution.
- Adds `abbr` to the default `allowedTags` for better accessibility support. Thanks to [Will Farrell](https://togithub.com/willfarrell) for the contribution.
- 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://togithub.com/axdg) for the initial implementation and [Marco Arduini](https://togithub.com/nerfologist) for a failing test contribution.
### [`v1.23.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1230)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/592952e0fcb1b1d7b641e47eabb1d3092d3eb731...22964d642366eea191e2961898a2df5c6426f3f0)
- Adds eslint configuration and adds eslint to test script.
- 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://togithub.com/egorvoronov) for the contribution.
- Adds the `tagName` (HTML element name) as a second parameter passed to `textFilter`. Thanks to [Slava](https://togithub.com/slavaGanzin) for the contribution.
### [`v1.22.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1221)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.22.0...592952e0fcb1b1d7b641e47eabb1d3092d3eb731)
ncreases the patch version of `lodash.mergewith` to enforce an audit fix.
### [`v1.22.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1220)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.21.1...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.
### [`v1.21.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1211)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.21.0...1.21.1)
fixed issue with bad `main` setting in package.json that broke 1.21.0.
### [`v1.21.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1210)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/96c8807a9403752dd06576bad1b593a184270f2a...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.
### [`v1.20.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1201)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.20.0...96c8807a9403752dd06576bad1b593a184270f2a)
Fix failing tests, add CircleCI config
### [`v1.20.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1200)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.19.3...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.
### [`v1.19.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1193)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.19.2...1.19.3)
reverted to `postcss` due to a [reported issue with `css-tree` that might or might not have XSS implications](https://togithub.com/punkave/sanitize-html/issues/269).
### [`v1.19.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1192)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.19.1...1.19.2)
- Switched out the heavy `postcss` dependency for the lightweight `css-tree` module. No API changes. Thanks to Justin Braithwaite.
- Various doc updates. Thanks to Pulkit Aggarwal and Cody Robertson.
### [`v1.19.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1191)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.19.0...1.19.1)
- `"` characters are now entity-escaped only when they appear in attribute values, reducing the verbosity of the resulting markup.
- 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 `&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.
**For those using the default `parser` settings this bug is fixed.** Read on if you are using alternative `parser` settings.
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.
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.
### [`v1.19.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1190)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.18.5...1.19.0)
- 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.
### [`v1.18.5`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1185)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.18.4...1.18.5)
- Stop double encoding ampersands on HTML entities. Thanks to Will Gibson.
### [`v1.18.4`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1184)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.18.3...1.18.4)
- Removed incorrect `browser` key, restoring frontend build. Thanks to Felix Becker.
### [`v1.18.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1183)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.18.2...1.18.3)
- `iframe` is an allowed tag by default, to better facilitate typical use cases and the use of the `allowedIframeHostnames` option.
- Documentation improvements.
- More browser packaging improvements.
- Protocol-relative URLs are properly supported for iframe tags.
### [`v1.18.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1182)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/86af79ed2a44c91d3718633077c50b80e0279489...1.18.2)
- Travis tests passing.
- Fixed another case issue — and instituted Travis CI testing so this doesn't happen again. Sorry for the hassle.
### [`v1.18.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1181)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/9d516659a69c915901a3c618774502222a1a9edb...86af79ed2a44c91d3718633077c50b80e0279489)
- A file was required with incorrect case, breaking the library on case sensitive filesystems such as Linux. Fixed.
### [`v1.18.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1180)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/cfe21220b80b7130755b7e3fd9abadc7ba6f1658...9d516659a69c915901a3c618774502222a1a9edb)
- 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.
- 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.
- Fixed a bug in the npm test procedure.
### [`v1.17.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1170)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/35b0b7263c5efcea871d7328b8b7821508626654...cfe21220b80b7130755b7e3fd9abadc7ba6f1658)
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.
### [`v1.16.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1163)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/230caf780c50375311ec898840fdcd6d12c8ef30...35b0b7263c5efcea871d7328b8b7821508626654)
Don't throw away the browserified versions before publishing them. `prepare` is not a good place to `make clean`, it runs after `prepublish`.
### [`v1.16.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1162)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/984b359e8b8c942d13616c424e30cade029e9645...230caf780c50375311ec898840fdcd6d12c8ef30)
`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.
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.
### [`v1.16.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1161)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/476467ebb845cb514c6a2e2a96d71eb30a6ada14...984b359e8b8c942d13616c424e30cade029e9645)
changelog formatting only.
### [`v1.16.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1160)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/cdab9149388a7f307c4bf74bcf47fba6744346aa...476467ebb845cb514c6a2e2a96d71eb30a6ada14)
support for sanitizing inline CSS styles, by specifying the allowed attributes and a regular expression for each. Thanks to Cameron Will and Michael Loschiavo.
### [`v1.15.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1150)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/0a41ad66f90cba47c693ed6cb91330792d368f8b...cdab9149388a7f307c4bf74bcf47fba6744346aa)
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.
### [`v1.14.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1143)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/77e36193fd3ce8e323dc7d093ad323108fdba387...0a41ad66f90cba47c693ed6cb91330792d368f8b)
inadvertent removal of lodash regexp quote dependency in 1.14.2 has been corrected.
### [`v1.14.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1142)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/fb89a712ba29bed52d5b2a0931b99ed7edf0f00c...77e36193fd3ce8e323dc7d093ad323108fdba387)
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.
### [`v1.14.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1141)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/4c229fbbc9c269236b571dcbf834dc7c0ea19012...fb89a712ba29bed52d5b2a0931b99ed7edf0f00c)
documented `allowProtocolRelative` option. No code changes from 1.14.0, released a few moments ago.
### [`v1.14.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1140)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2597e3b6d45592ecc665cedec8bec72362beacd9...4c229fbbc9c269236b571dcbf834dc7c0ea19012)
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.
### [`v1.13.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1130)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/ab8f51567dea754145e42d63b431493a5edbef9e...2597e3b6d45592ecc665cedec8bec72362beacd9)
`transformTags` can now add text to an element that initially had none. Thanks to Dushyant Singh.
### [`v1.12.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1120)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.11.4...ab8f51567dea754145e42d63b431493a5edbef9e)
option to build for browser-side use. Thanks to Michael Blum.
### [`v1.11.4`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1114)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/b0d09c7c3f128849b6a9e93e5218354c899ba54c...1.11.4)
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.
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.
### [`v1.11.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1113)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/fed522e33f42f34411a5c326e7228de13c75bb6b...b0d09c7c3f128849b6a9e93e5218354c899ba54c)
bumped `htmlparser2` version to address crashing bug in older version. Thanks to e-jigsaw.
### [`v1.11.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1112)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.11.1...fed522e33f42f34411a5c326e7228de13c75bb6b)
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.
### [`v1.11.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1111)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.11.0...1.11.1)
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.
### [`v1.11.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1110)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/1.10.1...1.11.0)
added the `nonTextTags` option, with tests.
### [`v1.10.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1101)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/ff58854e49784e6886817d6aa2f6af0bc33b3bf2...1.10.1)
documentation cleanup. No code changes. Thanks to Rex Schrader.
### [`v1.10.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#1100)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/v1.9.0...ff58854e49784e6886817d6aa2f6af0bc33b3bf2)
`allowedAttributes` now allows you to allow attributes for all tags by specifying `*` as the tag name. Thanks to Zdravko Georgiev.
### [`v1.9.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#190)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/v1.8.0...v1.9.0)
`parser` option allows options to be passed directly to `htmlparser`. Thanks to Danny Scott.
### [`v1.8.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#180)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/v1.7.2...v1.8.0)
- `transformTags` now accepts the `*` wildcard to transform all tags. Thanks to Jamy Timmermans.
- Text that has been modified by `transformTags` is then passed through `textFilter`. Thanks to Pavlo Yurichuk.
- 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.
### [`v1.7.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#172)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/v1.7.1...v1.7.2)
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.
### [`v1.7.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#171)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/v1.7.0...v1.7.1)
removed lodash dependency, adding lighter dependencies and polyfills in its place. Thanks to Joseph Dykstra.
### [`v1.7.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#170)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/09c978af2331171ab67de9d8c2c8e88074896a12...v1.7.0)
introduced `allowedSchemesByTag` option. Thanks to Cameron Will.
### [`v1.6.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#161)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/9c6dcc812fb1d176c16611b94a2def47668ffc42...09c978af2331171ab67de9d8c2c8e88074896a12)
the string `'undefined'` (as opposed to `undefined`) is perfectly valid text and shouldn't be expressly converted to the empty string.
### [`v1.6.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#160)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/dd9a7e57931c5279141330cace4bb366f18ec611...9c6dcc812fb1d176c16611b94a2def47668ffc42)
added `textFilter` option. Thanks to Csaba Palfi.
### [`v1.5.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#153)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/v1.5.2...dd9a7e57931c5279141330cace4bb366f18ec611)
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.
### [`v1.5.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#152)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/a20c499c52afdd729307a96e04996aef635271a6...v1.5.2)
guard checks for allowed attributes correctly to avoid an undefined property error. Thanks to Zeke.
### [`v1.5.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#151)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/c1adeef6c400dff99afd9b5b64548569d409ad2c...a20c499c52afdd729307a96e04996aef635271a6)
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.
### [`v1.5.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#150)
[Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/141b0798f1f0bc51ab1a83d4912f6c8fee5d79b0...c1adeef6c400dff99afd9b5b64548569d409ad2c)
support for `*` wildcards in allowedAttributes. With tests. Thanks to Calvin Montgomery.
### [`v1.4.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#143)
invokes itself recursively until the markup stops changing to guard against [this issue](https://togithub.com/fb55/htmlparser2/issues/105). Bump to htmlparser2 version 3.7.x.
[ ] If you want to rebase/retry this PR, check this box
This PR contains the following updates:
1.4.2
->2.12.1
By merging this PR, the issue #19 will be automatically resolved and closed:
Release Notes
apostrophecms/sanitize-html (sanitize-html)
### [`v2.12.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2121-2024-02-22) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/5a5a74e179ef98075a0c61789f64e009f6b4ac29...2.12.1) - Do not parse sourcemaps in `post-css`. This fixes a vulnerability in which information about the existence or non-existence of files on a server could be disclosed via properly crafted HTML input when the `style` attribute is allowed by the configuration. Thanks to the [Snyk Security team](https://snyk.io/) for the disclosure and to [Dylan Armstrong](https://dylan.is/) for the fix. ### [`v2.12.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2120-2024-02-21) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.11.0...5a5a74e179ef98075a0c61789f64e009f6b4ac29) - Introduced the `allowedEmptyAttributes` option, enabling explicit specification of empty string values for select attributes, with the default attribute set to `alt`. Thanks to [Na](https://togithub.com/zhna123) for the contribution. - Clarified the use of SVGs with a new test and changes to documentation. Thanks to [Gauav Kumar](https://togithub.com/gkumar9891) for the contribution. - Do not process source maps when processing style tags with PostCSS. ### [`v2.11.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2110-2023-06-21) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.10.0...2.11.0) - Fix to allow `false` in `allowedClasses` attributes. Thanks to [Kevin Jiang](https://togithub.com/KevinSJ) for this fix! - Upgrade mocha version - Apply small linter fixes in tests - Add `.idea` temp files to `.gitignore` - Thanks to [Vitalii Shpital](https://togithub.com/VitaliiShpital) for the updates! - Show parseStyleAttributes warning in browser only. Thanks to [mog422](https://togithub.com/mog422) for this update! - Remove empty non-boolean attributes via an exhaustive, configurable list of known non-boolean attributes. [Thanks to Dylan Armstrong](https://togithub.com/dylanarmstrong) for this update! ### [`v2.10.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#2100-2023-02-17) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.9.0...2.10.0) - 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://togithub.com/apostrophecms/sanitize-html/issues/464). Thanks to [Daniel Liebner](https://togithub.com/dliebner) - 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. ### [`v2.9.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#290-2023-01-27) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.8.1...2.9.0) - Add option parseStyleAttributes to skip style parsing. This fixes [issue #547](https://togithub.com/apostrophecms/sanitize-html/issues/547). Thanks to [Bert Verhelst](https://togithub.com/bertyhell). ### [`v2.8.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#281-2022-12-21) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.8.0...2.8.1) - If the argument is a number, convert it to a string, for backwards compatibility. Thanks to [Alexander Schranz](https://togithub.com/alexander-schranz). ### [`v2.8.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#280-2022-12-12) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.3...2.8.0) - Upgrades `htmlparser2` to new major version `^8.0.0`. Thanks to [Kedar Chandrayan](https://togithub.com/kedarchandrayan) for this contribution. ### [`v2.7.3`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#273-2022-10-24) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.2...2.7.3) - 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://togithub.com/apostrophecms/sanitize-html/issues/176). Thanks to [Kedar Chandrayan](https://togithub.com/kedarchandrayan) for the fix. ### [`v2.7.2`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#272-2022-09-15) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.1...2.7.2) - Closing tags must agree with opening tags. This fixes [issue #549](https://togithub.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 [Kedar Chandrayan](https://togithub.com/kedarchandrayan) for the report and the fix. ### [`v2.7.1`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#271-2022-07-20) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.7.0...2.7.1) - Protocol-relative URLs are properly supported for script tags. Thanks to [paweljq](https://togithub.com/paweljq). - 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. ### [`v2.7.0`](https://togithub.com/apostrophecms/sanitize-html/blob/HEAD/CHANGELOG.md#270-2022-02-04) [Compare Source](https://togithub.com/apostrophecms/sanitize-html/compare/2.6.1...2.7.0) - Allows a more sensible set of default attributes on `