This is Linux
some text...
', { allowedTags: [ 'p', 'em', 'strong', 'iframe' ], allowedClasses: { 'p': [ 'fancy', 'simple' ], }, allowedAttributes: { 'iframe': ['src'] }, allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com'] }); ``` will pass through as safe whereas: ```javascript const clean = sanitizeHtml('
', { allowedTags: [ 'p', 'em', 'strong', 'iframe' ], allowedClasses: { 'p': [ 'fancy', 'simple' ], }, allowedAttributes: { 'iframe': ['src'] }, allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com'] }); ``` or ```javascript const clean = sanitizeHtml('
', { allowedTags: [ 'p', 'em', 'strong', 'iframe' ], allowedClasses: { 'p': [ 'fancy', 'simple' ], }, allowedAttributes: { 'iframe': ['src'] }, allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com'] }); ``` will return an empty iframe tag. If you want to allow any subdomain of any level you can provide the domain in `allowedIframeDomains` ```javascript // This iframe markup will pass through as safe. const clean = sanitizeHtml('
', { allowedTags: [ 'p', 'em', 'strong', 'iframe' ], allowedClasses: { 'p': [ 'fancy', 'simple' ], }, allowedAttributes: { 'iframe': ['src'] }, allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com'], allowedIframeDomains: ['zoom.us'] }); ``` ### Allowed URL schemes By default, we allow the following URL schemes in cases where `href`, `src`, etc. are allowed: ```js [ 'http', 'https', 'ftp', 'mailto' ] ``` You can override this if you want to: ```js sanitizeHtml( // teeny-tiny valid transparent GIF in a data URL '', { allowedTags: [ 'img', 'p' ], allowedSchemes: [ 'data', 'http' ] } ); ``` You can also allow a scheme for a particular tag only: ```js allowedSchemes: [ 'http', 'https' ], allowedSchemesByTag: { img: [ 'data' ] } ``` And you can forbid the use of protocol-relative URLs (starting with `//`) to access another site using the current protocol, which is allowed by default: ```js allowProtocolRelative: false ``` ### Discarding the entire contents of a disallowed tag Normally, 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. The exceptions are: `style`, `script`, `textarea`, `option` If you wish to replace this list, for instance to discard whatever is found inside a `noscript` tag, use the `nonTextTags` option: ```js nonTextTags: [ 'style', 'script', 'textarea', 'option', 'noscript' ] ``` 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. The content still gets escaped properly, with the exception of the `script` and `style` tags. *Allowing either `script` or `style` leaves you open to XSS attacks. Don't do that* unless you have good reason to trust their origin. sanitize-html will log a warning if these tags are allowed, which can be disabled with the `allowVulnerableTags: true` option. ### Choose what to do with disallowed tags Instead of discarding, or keeping text only, you may enable escaping of the entire content: ```js disallowedTagsMode: 'escape' ``` This will transform `content` to `<disallowed>content</disallowed>` Valid values are: `'discard'` (default), `'escape'` (escape the tag) and `'recursiveEscape'` (to escape the tag and all its content). ### Restricting deep nesting You can limit the depth of HTML tags in the document with the `nestingLimit` option: ```javascript nestingLimit: 6 ``` This will prevent the user from nesting tags more than 6 levels deep. Tags deeper than that are stripped out exactly as if they were disallowed. Note that this means text is preserved in the usual ways where appropriate. ## About ApostropheCMS sanitize-html was created at [P'unk Avenue](https://punkave.com) for use in [ApostropheCMS](https://apostrophecms.com), an open-source content management system built on Node.js. If you like sanitize-html you should definitely check out ApostropheCMS. ## Support Feel free to open issues on [github](https://github.com/apostrophecms/sanitize-html).