{"name":"sanitize-html","version":"2.7.2","description":"Clean up user-submitted HTML, preserving allowlisted elements and allowlisted attributes on a per-element basis","sideEffects":false,"main":"index.js","scripts":{"test":"npx eslint . && mocha test/test.js"},"repository":{"type":"git","url":"git+https://github.com/apostrophecms/sanitize-html.git"},"keywords":["html","parser","sanitizer","sanitize"],"author":{"name":"Apostrophe Technologies, Inc."},"license":"MIT","dependencies":{"deepmerge":"^4.2.2","escape-string-regexp":"^4.0.0","htmlparser2":"^6.0.0","is-plain-object":"^5.0.0","parse-srcset":"^1.0.2","postcss":"^8.3.11"},"devDependencies":{"eslint":"^7.3.1","eslint-config-apostrophe":"^3.4.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.25.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","mocha":"^7.0.0","sinon":"^9.0.2"},"gitHead":"0573fb6c67c74e98726db0637a648961c90046cc","bugs":{"url":"https://github.com/apostrophecms/sanitize-html/issues"},"homepage":"https://github.com/apostrophecms/sanitize-html#readme","_id":"sanitize-html@2.7.2","_nodeVersion":"14.20.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-DggSTe7MviO+K4YTCwprG6W1vsG+IIX67yp/QY55yQqKCJYSWzCA1rZbaXzkjoKeL9+jqwm56wD6srYLtUNivg==","shasum":"54c5189af75e3237d996e4b9a5e3eaad12c7f7fc","tarball":"https://registry.npmmirror.com/sanitize-html/-/sanitize-html-2.7.2.tgz","fileCount":4,"unpackedSize":53003,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDr9bPNtXfRI/t+6BNH7dUGPpMTPms7DwYqOFjMnONLGQIgPeece1DcYw3UgmwiaiAdPf5r5MnPctt1fe0a+NmNrhw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjIx/8ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrVfw//cbaYLsek29YoR//nj28lwnKqUZFBF2ZKF/zY9H+GbXc/j81/\r\nq6mTFj4EOMPOwSGkrFXiZHG8nfxbEvdxYeUZVVm1WAHAMFuKuvU6dNvwXw8t\r\nAKj1qY0WYS2B0G4aLj4ixfJe/ZjC224HXbZxnAb2Dm+CPF0HK+sK7YwkLqci\r\n4m6fwW0fA5b3hLcermUH0ewCExeJrSgdaGgqsMhF93SBQgyk4BFEFGH6LJf4\r\npuv/Y9ufovybDfSfN1R6AqW8l3Wu22mR+lVAaivBXpOhTmP6Ahe26Y3hsn0P\r\nFmpmf3xN8PuYK8s8tbIpUj8qAgxj9FtANbfIZLRmF2ExH41gY58XAB+nCGuO\r\n7d8wQf5IT4J+xroY2GsApEqW25u/O8lZrrUH69ccULafCCfuOSriwf63K1DN\r\nzBffxdIe9YQkhyk4AFJckcntNn0P59SzpOpd2r1XWw1OCc719DUEyjylBchS\r\n2DI3Jml7XiUNzw3M8jnXtVlerz4gMoJF/9UfccxgEjA26f6dEgRrTiTOEuQF\r\nBsVRi/+qmugdXOg0wa9vppOf7zAN4w9HLd6dpnaM/RVCX4Mph3o9r0usD5KI\r\n9ISdATdPjtStnPMnA+YdzZZI6BMCHHMfzvMgopFw74ASjODLG99LdTu6fKzp\r\nomHmjrk8gdpwL8tkMdFEZzU4Sbkn4f7CGuI=\r\n=t/en\r\n-----END PGP SIGNATURE-----\r\n","size":16309},"_npmUser":{"name":"etlaurent","email":"etlaurent@tuta.io"},"directories":{},"maintainers":[{"name":"mhiggins","email":"mhiggins.louis@gmail.com"},{"name":"bodonkey","email":"robert@robertmeans.net"},{"name":"etlaurent","email":"etlaurent@tuta.io"},{"name":"alexgilbert","email":"alex@apostrophecms.com"},{"name":"stuartromanek","email":"stuart@punkave.com"},{"name":"boutell","email":"tom@apostrophecms.com"},{"name":"alexbea","email":"abea@mailbox.org"},{"name":"gregvanbrug","email":"greg.vanbrug@gmail.com"},{"name":"valjed","email":"vjeudy@protonmail.com"},{"name":"romanek","email":"stuart+npm@apostrophecms.com"},{"name":"jimmyh","email":"jimmy@punkave.com"},{"name":"austinstarin","email":"austin.starin@gmail.com"},{"name":"grdunn","email":"grdunn@gmail.com"},{"name":"falkodev","email":"anthony@apostrophecms.com"},{"name":"mtthwmnc","email":"matthew.mance@gmail.com"},{"name":"breyell","email":"breyell@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sanitize-html_2.7.2_1663246332337_0.7663266541250842"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-09-15T13:08:52.736Z","readme":"# sanitize-html\n\n[![CircleCI](https://circleci.com/gh/apostrophecms/sanitize-html/tree/main.svg?style=svg)](https://circleci.com/gh/apostrophecms/sanitize-html/tree/main)\n\n\n\nsanitize-html provides a simple HTML sanitizer with a clear API.\n\nsanitize-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.\n\nsanitize-html allows you to specify the tags you want to permit, and the permitted attributes for each of those tags.\n\nIf a tag is not permitted, the contents of the tag are not discarded. There are\nsome exceptions to this, discussed below in the \"Discarding the entire contents\nof a disallowed tag\" section.\n\nThe syntax of poorly closed `p` and `img` elements is cleaned up.\n\n`href` attributes are validated to ensure they only contain `http`, `https`, `ftp` and `mailto` URLs. Relative URLs are also allowed. Ditto for `src` attributes.\n\nAllowing particular urls as a `src` to an iframe tag by filtering hostnames is also supported.\n\nHTML comments are not preserved.\nAdditionally, `sanitize-html` escapes _ALL_ text content - this means that ampersands, greater-than, and less-than signs are converted to their equivalent HTML character references (`&` --> `&`, `<` --> `<`, and so on). Additionally, in attribute values, quotation marks are escaped as well (`\"` --> `"`).\n\n## Requirements\n\nsanitize-html is intended for use with Node.js and supports Node 10+. All of its npm dependencies are pure JavaScript. sanitize-html is built on the excellent `htmlparser2` module.\n\n### Regarding TypeScript\n\nsanitize-html is not written in TypeScript and there is no plan to directly support it. There is a community supported typing definition, [`@types/sanitize-html`](https://www.npmjs.com/package/@types/sanitize-html), however.\n```bash\nnpm install -D @types/sanitize-html\n```\nIf `esModuleInterop=true` is not set in your `tsconfig.json` file, you have to import it with:\n\n```javascript\nimport * as sanitizeHtml from 'sanitize-html';\n```\n\nAny questions or problems while using `@types/sanitize-html` should be directed to its maintainers as directed by that project's contribution guidelines.\n\n## How to use\n\n### Browser\n\n*Think first: why do you want to use it in the browser?* Remember, *servers must never trust browsers.* You can't sanitize HTML for saving on the server anywhere else but on the server.\n\nBut, perhaps you'd like to display sanitized HTML immediately in the browser for preview. Or ask the browser to do the sanitization work on every page load. You can if you want to!\n\n* Install the package:\n\n```bash\nnpm install sanitize-html\n```\nor\n```\nyarn add sanitize-html\n```\n\nThe primary change in the 2.x version of sanitize-html is that it no longer includes a build that is ready for browser use. Developers are expected to include sanitize-html in their project builds (e.g., webpack) as they would any other dependency. So while sanitize-html is no longer ready to link to directly in HTML, developers can now more easily process it according to their needs.\n\nOnce built and linked in the browser with other project Javascript, it can be used to sanitize HTML strings in front end code:\n\n```javascript\nimport sanitizeHtml from 'sanitize-html';\n\nconst html = \"hello world\";\nconsole.log(sanitizeHtml(html));\nconsole.log(sanitizeHtml(\"\"));\nconsole.log(sanitizeHtml(\"console.log('hello world')\"));\nconsole.log(sanitizeHtml(\"\"));\n```\n\n### Node (Recommended)\n\nInstall module from console:\n\n```bash\nnpm install sanitize-html\n```\n\nImport the module:\n\n```js\n// In ES modules\nimport sanitizeHtml from 'sanitize-html';\n\n// Or in CommonJS\nconst sanitizeHtml = require('sanitize-html');\n```\n\nUse it in your JavaScript app:\n\n```js\nconst dirty = 'some really tacky HTML';\nconst clean = sanitizeHtml(dirty);\n```\n\nThat will allow our [default list of allowed tags and attributes](#default-options) through. It's a nice set, but probably not quite what you want. So:\n\n```js\n// Allow only a super restricted set of tags and attributes\nconst clean = sanitizeHtml(dirty, {\n allowedTags: [ 'b', 'i', 'em', 'strong', 'a' ],\n allowedAttributes: {\n 'a': [ 'href' ]\n },\n allowedIframeHostnames: ['www.youtube.com']\n});\n```\n\nBoom!\n\n### Default options\n\n```js\nallowedTags: [\n \"address\", \"article\", \"aside\", \"footer\", \"header\", \"h1\", \"h2\", \"h3\", \"h4\",\n \"h5\", \"h6\", \"hgroup\", \"main\", \"nav\", \"section\", \"blockquote\", \"dd\", \"div\",\n \"dl\", \"dt\", \"figcaption\", \"figure\", \"hr\", \"li\", \"main\", \"ol\", \"p\", \"pre\",\n \"ul\", \"a\", \"abbr\", \"b\", \"bdi\", \"bdo\", \"br\", \"cite\", \"code\", \"data\", \"dfn\",\n \"em\", \"i\", \"kbd\", \"mark\", \"q\", \"rb\", \"rp\", \"rt\", \"rtc\", \"ruby\", \"s\", \"samp\",\n \"small\", \"span\", \"strong\", \"sub\", \"sup\", \"time\", \"u\", \"var\", \"wbr\", \"caption\",\n \"col\", \"colgroup\", \"table\", \"tbody\", \"td\", \"tfoot\", \"th\", \"thead\", \"tr\"\n],\ndisallowedTagsMode: 'discard',\nallowedAttributes: {\n a: [ 'href', 'name', 'target' ],\n // We don't currently allow img itself by default, but\n // these attributes would make sense if we did.\n img: [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ]\n},\n// Lots of these won't come up by default because we don't allow them\nselfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', 'meta' ],\n// URL schemes we permit\nallowedSchemes: [ 'http', 'https', 'ftp', 'mailto', 'tel' ],\nallowedSchemesByTag: {},\nallowedSchemesAppliedToAttributes: [ 'href', 'src', 'cite' ],\nallowProtocolRelative: true,\nenforceHtmlBoundary: false\n```\n\n### Common use cases\n\n#### \"I like your set but I want to add one more tag. Is there a convenient way?\"\n\nSure:\n\n```js\nconst clean = sanitizeHtml(dirty, {\n allowedTags: sanitizeHtml.defaults.allowedTags.concat([ 'img' ])\n});\n```\n\nIf you do not specify `allowedTags` or `allowedAttributes`, our default list is applied. So if you really want an empty list, specify one.\n\n#### \"What if I want to allow all tags or all attributes?\"\n\nSimple! Instead of leaving `allowedTags` or `allowedAttributes` out of the options, set either\none or both to `false`:\n\n```js\nallowedTags: false,\nallowedAttributes: false\n```\n\n#### \"What if I don't want to allow *any* tags?\"\n\nAlso simple! Set `allowedTags` to `[]` and `allowedAttributes` to `{}`.\n\n```js\nallowedTags: [],\nallowedAttributes: {}\n```\n\n#### \"What if I want disallowed tags to be escaped rather than discarded?\"\n\nIf you set `disallowedTagsMode` to `discard` (the default), disallowed tags are discarded. Any text content or subtags are still included, depending on whether the individual subtags are allowed.\n\nIf you set `disallowedTagsMode` to `escape`, the disallowed tags are escaped rather than discarded. Any text or subtags are handled normally.\n\nIf you set `disallowedTagsMode` to `recursiveEscape`, the disallowed tags are escaped rather than discarded, and the same treatment is applied to all subtags, whether otherwise allowed or not.\n\n#### \"What if I want to allow only specific values on some attributes?\"\n\nWhen configuring the attribute in `allowedAttributes` simply use an object with attribute `name` and an allowed `values` array. In the following example `sandbox=\"allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-scripts\"` would become `sandbox=\"allow-popups allow-scripts\"`:\n\n```js\nallowedAttributes: {\n iframe: [\n {\n name: 'sandbox',\n multiple: true,\n values: ['allow-popups', 'allow-same-origin', 'allow-scripts']\n }\n ]\n}\n```\n\nWith `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.\n\n### Wildcards for attributes\n\nYou can use the `*` wildcard to allow all attributes with a certain prefix:\n\n```js\nallowedAttributes: {\n a: [ 'href', 'data-*' ]\n}\n```\n\nAlso you can use the `*` as name for a tag, to allow listed attributes to be valid for any tag:\n\n```js\nallowedAttributes: {\n '*': [ 'href', 'align', 'alt', 'center', 'bgcolor' ]\n}\n```\n\n## Additional options\n\n### Allowed CSS Classes\n\nIf you wish to allow specific CSS classes on a particular element, you can do so with the `allowedClasses` option. Any other CSS classes are discarded.\n\nThis implies that the `class` attribute is allowed on that element.\n\n```javascript\n// Allow only a restricted set of CSS classes and only on the p tag\nconst clean = sanitizeHtml(dirty, {\n allowedTags: [ 'p', 'em', 'strong' ],\n allowedClasses: {\n 'p': [ 'fancy', 'simple' ]\n }\n});\n```\n\nSimilar to `allowedAttributes`, you can use `*` to allow classes with a certain prefix, or use `*` as a tag name to allow listed classes to be valid for any tag:\n\n```js\nallowedClasses: {\n 'code': [ 'language-*', 'lang-*' ],\n '*': [ 'fancy', 'simple' ]\n}\n```\n\nFurthermore, regular expressions are supported too:\n\n```js\nallowedClasses: {\n p: [ /^regex\\d{2}$/ ]\n}\n```\n\n> 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.\n\n### Allowed CSS Styles\n\nIf you wish to allow specific CSS _styles_ on a particular element, you can do that with the `allowedStyles` option. Simply declare your desired attributes as regular expression options within an array for the given attribute. Specific elements will inherit allowlisted attributes from the global (`*`) attribute. Any other CSS classes are discarded.\n\n**You must also use `allowedAttributes`** to activate the `style` attribute for the relevant elements. Otherwise this feature will never come into play.\n\n**When constructing regular expressions, don't forget `^` and `$`.** It's not enough to say \"the string should contain this.\" It must also say \"and only this.\"\n\n**URLs in inline styles are NOT filtered by any mechanism other than your regular expression.**\n\n```javascript\nconst clean = sanitizeHtml(dirty, {\n allowedTags: ['p'],\n allowedAttributes: {\n 'p': [\"style\"],\n },\n allowedStyles: {\n '*': {\n // Match HEX and RGB\n 'color': [/^#(0x)?[0-9a-f]+$/i, /^rgb\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)$/],\n 'text-align': [/^left$/, /^right$/, /^center$/],\n // Match any number with px, em, or %\n 'font-size': [/^\\d+(?:px|em|%)$/]\n },\n 'p': {\n 'font-size': [/^\\d+rem$/]\n }\n }\n });\n```\n\n### Discarding text outside of `````` tags\n\nSome text editing applications generate HTML to allow copying over to a web application. These can sometimes include undesirable 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.\n\nSetting this option to true will instruct sanitize-html to discard all characters outside of `html` tag boundaries -- before `` and after `` tags.\n\n```js\nenforceHtmlBoundary: true\n```\n\n### htmlparser2 Options\n\nsanitize-html is built on `htmlparser2`. By default the only option passed down is `decodeEntities: true`. You can set the options to pass by using the parser option.\n\n**Security note: changing the `parser` settings can be risky.** In particular, `decodeEntities: false` has known security concerns and a complete test suite does not exist for every possible combination of settings when used with `sanitize-html`. If security is your goal we recommend you use the defaults rather than changing `parser`, except for the `lowerCaseTags` option.\n\n```javascript\nconst clean = sanitizeHtml(dirty, {\n allowedTags: ['a'],\n parser: {\n lowerCaseTags: true\n }\n});\n```\nSee the [htmlparser2 wiki](https://github.com/fb55/htmlparser2/wiki/Parser-options) for the full list of possible options.\n\n### Transformations\n\nWhat if you want to add or change an attribute? What if you want to transform one tag to another? No problem, it's simple!\n\nThe easiest way (will change all `ol` tags to `ul` tags):\n\n```js\nconst clean = sanitizeHtml(dirty, {\n transformTags: {\n 'ol': 'ul',\n }\n});\n```\n\nThe most advanced usage:\n\n```js\nconst clean = sanitizeHtml(dirty, {\n transformTags: {\n 'ol': function(tagName, attribs) {\n // My own custom magic goes here\n return {\n tagName: 'ul',\n attribs: {\n class: 'foo'\n }\n };\n }\n }\n});\n```\n\nYou can specify the `*` wildcard instead of a tag name to transform all tags.\n\nThere is also a helper method which should be enough for simple cases in which you want to change the tag and/or add some attributes:\n\n```js\nconst clean = sanitizeHtml(dirty, {\n transformTags: {\n 'ol': sanitizeHtml.simpleTransform('ul', {class: 'foo'}),\n }\n});\n```\n\nThe `simpleTransform` helper method has 3 parameters:\n\n```js\nsimpleTransform(newTag, newAttributes, shouldMerge)\n```\n\nThe last parameter (`shouldMerge`) is set to `true` by default. When `true`, `simpleTransform` will merge the current attributes with the new ones (`newAttributes`). When `false`, all existing attributes are discarded.\n\nYou can also add or modify the text contents of a tag:\n\n```js\nconst clean = sanitizeHtml(dirty, {\n transformTags: {\n 'a': function(tagName, attribs) {\n return {\n tagName: 'a',\n text: 'Some text'\n };\n }\n }\n});\n```\nFor example, you could transform a link element with missing anchor text:\n```js\n\n```\nTo a link with anchor text:\n```js\nSome text\n```\n\n### Filters\n\nYou can provide a filter function to remove unwanted tags. Let's suppose we need to remove empty `a` tags like:\n\n```html\n\n```\n\nWe can do that with the following filter:\n\n```js\nsanitizeHtml(\n '
',\n {\n exclusiveFilter: function(frame) {\n return frame.tag === 'a' && !frame.text.trim();\n }\n }\n);\n```\n\nThe `frame` object supplied to the callback provides the following attributes:\n\n- `tag`: The tag name, i.e. `'img'`.\n- `attribs`: The tag's attributes, i.e. `{ src: \"/path/to/tux.png\" }`.\n- `text`: The text content of the tag.\n- `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.\n- `tagPosition`: The index of the tag's position in the result string.\n\nYou can also process all text content with a provided filter function. Let's say we want an ellipsis instead of three dots.\n\n```html\nsome text...
\n```\n\nWe can do that with the following filter:\n\n```js\nsanitizeHtml(\n 'some text...
',\n {\n textFilter: function(text, tagName) {\n if (['a'].indexOf(tagName) > -1) return //Skip anchor tags\n\n return text.replace(/\\.\\.\\./, '…');\n }\n }\n);\n```\n\nNote that the text passed to the `textFilter` method is already escaped for safe display as HTML. You may add markup and use entity escape sequences in your `textFilter`.\n\n### Iframe Filters\n\nIf you would like to allow iframe tags but want to control the domains that are allowed through, you can provide an array of hostnames and/or array of domains that you would like to allow as iframe sources. This hostname is a property in the options object passed as an argument to the sanitize-html function.\n\nThese arrays will be checked against the html that is passed to the function and return only `src` urls that include the allowed hostnames or domains in the object. The url in the html that is passed must be formatted correctly (valid hostname) as an embedded iframe otherwise the module will strip out the src from the iframe.\n\nMake sure to pass a valid hostname along with the domain you wish to allow, i.e.:\n\n```js\nallowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com'],\nallowedIframeDomains: ['zoom.us']\n```\n\nYou may also specify whether or not to allow relative URLs as iframe sources.\n\n```js\nallowIframeRelativeUrls: true\n```\n\nNote that if unspecified, relative URLs will be allowed by default if no hostname or domain filter is provided but removed by default if a hostname or domain filter is provided.\n\n**Remember that the `iframe` tag must be allowed as well as the `src` attribute.**\n\nFor example:\n\n```javascript\nconst clean = sanitizeHtml('', {\n allowedTags: [ 'p', 'em', 'strong', 'iframe' ],\n allowedClasses: {\n 'p': [ 'fancy', 'simple' ],\n },\n allowedAttributes: {\n 'iframe': ['src']\n },\n allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com']\n});\n```\n\nwill pass through as safe whereas:\n\n```javascript\nconst clean = sanitizeHtml('
', {\n allowedTags: [ 'p', 'em', 'strong', 'iframe' ],\n allowedClasses: {\n 'p': [ 'fancy', 'simple' ],\n },\n allowedAttributes: {\n 'iframe': ['src']\n },\n allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com']\n});\n```\n\nor\n\n```javascript\nconst clean = sanitizeHtml('
', {\n allowedTags: [ 'p', 'em', 'strong', 'iframe' ],\n allowedClasses: {\n 'p': [ 'fancy', 'simple' ],\n },\n allowedAttributes: {\n 'iframe': ['src']\n },\n allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com']\n});\n```\n\nwill return an empty iframe tag.\n\nIf you want to allow any subdomain of any level you can provide the domain in `allowedIframeDomains`\n\n```javascript\n// This iframe markup will pass through as safe.\nconst clean = sanitizeHtml('
', {\n allowedTags: [ 'p', 'em', 'strong', 'iframe' ],\n allowedClasses: {\n 'p': [ 'fancy', 'simple' ],\n },\n allowedAttributes: {\n 'iframe': ['src']\n },\n allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com'],\n allowedIframeDomains: ['zoom.us']\n});\n```\n\n### Script Filters\n\nSimilarly to iframes you can allow a script tag on a list of allowlisted domains\n\n```js\nconst clean = sanitizeHtml('', {\n allowedTags: ['script'],\n allowedAttributes: {\n script: ['src']\n },\n allowedScriptDomains: ['authorized.com'],\n})\n```\n\nYou can allow a script tag on a list of allowlisted hostnames too\n\n```js\nconst clean = sanitizeHtml('', {\n allowedTags: ['script'],\n allowedAttributes: {\n script: ['src']\n },\n allowedScriptHostnames: [ 'www.authorized.com' ],\n})\n```\n\n### Allowed URL schemes\n\nBy default, we allow the following URL schemes in cases where `href`, `src`, etc. are allowed:\n\n```js\n[ 'http', 'https', 'ftp', 'mailto' ]\n```\n\nYou can override this if you want to:\n\n```js\nsanitizeHtml(\n // teeny-tiny valid transparent GIF in a data URL\n '',\n {\n allowedTags: [ 'img', 'p' ],\n allowedSchemes: [ 'data', 'http' ]\n }\n);\n```\n\nYou can also allow a scheme for a particular tag only:\n\n```js\nallowedSchemes: [ 'http', 'https' ],\nallowedSchemesByTag: {\n img: [ 'data' ]\n}\n```\n\nAnd you can forbid the use of protocol-relative URLs (starting with `//`) to access another site using the current protocol, which is allowed by default:\n\n```js\nallowProtocolRelative: false\n```\n\n### Discarding the entire contents of a disallowed tag\n\nNormally, with a few exceptions, if a tag is not allowed, all of the text within it is preserved, and so are any allowed tags within it.\n\nThe exceptions are:\n\n`style`, `script`, `textarea`, `option`\n\nIf you wish to replace this list, for instance to discard whatever is found\ninside a `noscript` tag, use the `nonTextTags` option:\n\n```js\nnonTextTags: [ 'style', 'script', 'textarea', 'option', 'noscript' ]\n```\n\nNote 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.\n\nThe content still gets escaped properly, with the exception of the `script` and\n`style` tags. *Allowing either `script` or `style` leaves you open to XSS\nattacks. Don't do that* unless you have good reason to trust their origin.\nsanitize-html will log a warning if these tags are allowed, which can be\ndisabled with the `allowVulnerableTags: true` option.\n\n### Choose what to do with disallowed tags\n\nInstead of discarding, or keeping text only, you may enable escaping of the entire content:\n\n```js\ndisallowedTagsMode: 'escape'\n```\n\nThis will transform `