Code Monkey home page Code Monkey logo

rehype-sanitize's Introduction

rehype-sanitize

Build Coverage Downloads Size Sponsors Backers Chat

rehype plugin to sanitize HTML.

Contents

What is this?

This package is a unified (rehype) plugin to make sure HTML is safe. It drops anything that isn’t explicitly allowed by a schema (defaulting to how github.com works).

unified is a project that transforms content with abstract syntax trees (ASTs). rehype adds support for HTML to unified. hast is the HTML AST that rehype uses. This is a rehype plugin that transforms hast.

When should I use this?

It’s recommended to sanitize your HTML any time you do not completely trust authors or the plugins being used.

This plugin is built on hast-util-sanitize, which cleans hast syntax trees. rehype focusses on making it easier to transform content by abstracting such internals away.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install rehype-sanitize

In Deno with esm.sh:

import rehypeSanitize from 'https://esm.sh/rehype-sanitize@6'

In browsers with esm.sh:

<script type="module">
  import rehypeSanitize from 'https://esm.sh/rehype-sanitize@6?bundle'
</script>

Use

Say we have the following file index.html:

<div onmouseover="alert('alpha')">
  <a href="jAva script:alert('bravo')">delta</a>
  <img src="x" onerror="alert('charlie')">
  <iframe src="javascript:alert('delta')"></iframe>
  <math>
    <mi xlink:href="data:x,<script>alert('echo')</script>"></mi>
  </math>
</div>
<script>
require('child_process').spawn('echo', ['hack!']);
</script>

…and our module example.js looks as follows:

import rehypeParse from 'rehype-parse'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'

const file = await unified()
  .use(rehypeParse, {fragment: true})
  .use(rehypeSanitize)
  .use(rehypeStringify)
  .process(await read('index.html'))

console.log(String(file))

Now running node example.js yields:

<div>
  <a>delta</a>
  <img src="x">




</div>

API

This package exports the identifier defaultSchema. The default export is rehypeSanitize.

defaultSchema

Default schema (Options).

Follows GitHub style sanitation.

unified().use(rehypeSanitize[, schema])

Sanitize HTML.

Parameters
  • options (Options, optional) — configuration
Returns

Transform (Transformer).

Options

Schema that defines what nodes and properties are allowed (TypeScript type).

This option is a bit advanced as it requires knowledge of syntax trees, so see the docs for Schema in hast-util-sanitize.

Example

Example: headings (DOM clobbering)

DOM clobbering is an attack in which malicious HTML confuses an application by naming elements, through id or name attributes, such that they overshadow presumed properties in window (the global scope in browsers). DOM clobbering often occurs when user content is used to generate heading IDs. To illustrate, say we have this browser.js file:

console.log(current)

And our module example.js contains:

/**
 * @typedef {import('hast').Root} Root
 */

import fs from 'node:fs/promises'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'

const browser = String(await fs.readFile('browser.js'))
const document = `<a name="old"></a>
<h1 id="current">Current</h1>
${`<p>${'Lorem ipsum dolor sit amet. '.repeat(20)}</p>\n`.repeat(20)}
<p>Link to <a href="#current">current</a>, link to <a href="#old">old</a>.`

const file = await unified()
  .use(rehypeParse, {fragment: true})
  .use(function () {
    /**
     * @param {Root} tree
     */
    return function (tree) {
      tree.children.push({
        type: 'element',
        tagName: 'script',
        properties: {type: 'module'},
        children: [{type: 'text', value: browser}]
      })
    }
  })
  .use(rehypeStringify)
  .process(document)

await fs.writeFile('output.html', String(file))

This code processes HTML, inlines our browser script into it, and writes it out. The input HTML models how markdown often looks on platforms like GitHub, which allow heading IDs to be generated from their text and embedded HTML (including <a name="old"></a>, which can be used to create anchors for renamed headings to prevent links from breaking). The generated HTML looks like:

<a name="old"></a>
<h1 id="current">Current</h1>
<p>Lorem ipsum dolor sit amet.<!--…--></p>
<p>Link to <a href="#current">current</a>, link to <a href="#old">old</a>.</p>
<script type="module">console.log(current)</script>

When you run this code locally and open the generated output.html, you can observe that the links at the bottom work, but also that the <h1> element is printed to the console (the clobbering).

rehype-sanitize solves the clobbering by prefixing every id and name attribute with 'user-content-'. Changing example.js:

@@ -15,6 +15,7 @@ ${`<p>${'Lorem ipsum dolor sit amet. '.repeat(20)}</p>\n`.repeat(20)}

   const file = await unified()
     .use(rehypeParse, {fragment: true})
+    .use(rehypeSanitize)
     .use(function () {
       /**
        * @param {Root} tree

Now yields:

-<a name="old"></a>
-<h1 id="current">Current</h1>
+<a name="user-content-old"></a>
+<h1 id="user-content-current">Current</h1>

This introduces another problem as the links are now broken. It could perhaps be solved by changing all links, but that would make the links rather ugly, and we’d need to track what IDs we have outside of the user content on our pages too. Alternatively, and what arguably looks better, we could rewrite pretty links to their safe but ugly prefixed elements. This is what GitHub does. Replace browser.js with the following:

/// <reference lib="dom" />
/* eslint-env browser */

// Page load (you could wrap this in a DOM ready if the script is loaded early).
hashchange()

// When URL changes.
window.addEventListener('hashchange', hashchange)

// When on the URL already, perhaps after scrolling, and clicking again, which
// doesn’t emit `hashchange`.
document.addEventListener(
  'click',
  function (event) {
    if (
      event.target &&
      event.target instanceof HTMLAnchorElement &&
      event.target.href === location.href &&
      location.hash.length > 1
    ) {
      setImmediate(function () {
        if (!event.defaultPrevented) {
          hashchange()
        }
      })
    }
  },
  false
)

function hashchange() {
  /** @type {string | undefined} */
  let hash

  try {
    hash = decodeURIComponent(location.hash.slice(1)).toLowerCase()
  } catch {
    return
  }

  const name = 'user-content-' + hash
  const target =
    document.getElementById(name) || document.getElementsByName(name)[0]

  if (target) {
    setImmediate(function () {
      target.scrollIntoView()
    })
  }
}

Example: math

Math can be enabled in rehype by using the plugins rehype-katex or rehype-mathjax. The operate on elements with certain classes and inject complex markup and of inline styles, most of which this plugin will remove. Say our module example.js contains:

import rehypeKatex from 'rehype-katex'
import rehypeParse from 'rehype-parse'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'

const file = await unified()
  .use(rehypeParse, {fragment: true})
  .use(rehypeKatex)
  .use(rehypeSanitize)
  .use(rehypeStringify)
  .process('<code class="math-inline">L</code>')

console.log(String(file))

Running that yields:

<span><span>LL</span><span><span><span></span><span>L</span></span></span></span>

It is possible to pass a schema which allows MathML and inline styles, but it would be complex and allows all inline styles, which is unsafe. Alternatively, and arguably better, would be to first sanitize the HTML, allowing only the specific classes that rehype-katex and rehype-mathjax use, and then using those plugins:

@@ -1,13 +1,20 @@
 import rehypeKatex from 'rehype-katex'
 import rehypeParse from 'rehype-parse'
-import rehypeSanitize from 'rehype-sanitize'
+import rehypeSanitize, {defaultSchema} from 'rehype-sanitize'
 import rehypeStringify from 'rehype-stringify'
 import {unified} from 'unified'

 const file = await unified()
   .use(rehypeParse, {fragment: true})
+  .use(rehypeSanitize, {
+    ...defaultSchema,
+    attributes: {
+      ...defaultSchema.attributes,
+      // The `language-*` regex is allowed by default.
+      code: [['className', /^language-./, 'math-inline', 'math-display']]
+    }
+  })
   .use(rehypeKatex)
-  .use(rehypeSanitize)
   .use(rehypeStringify)
   .process('<code class="math-inline">L</code>')

Running that yields:

<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"></math></span><span class="katex-html" aria-hidden="true"></span></span>

Example: syntax highlighting

Highlighting, for example with rehype-highlight, can be solved similar to how math is solved (see previous example). That is, use rehype-sanitize and allow the classes needed for highlighting, and highlight afterwards:

import rehypeHighlight from 'rehype-highlight'
import rehypeParse from 'rehype-parse'
import rehypeSanitize, {defaultSchema} from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'

const file = await unified()
  .use(rehypeParse, {fragment: true})
  .use(rehypeSanitize, {
    ...defaultSchema,
    attributes: {
      ...defaultSchema.attributes,
      code: [
        ...(defaultSchema.attributes.code || []),
        // List of all allowed languages:
        ['className', 'language-js', 'language-css', 'language-md']
      ]
    }
  })
  .use(rehypeHighlight, {subset: false})
  .use(rehypeStringify)
  .process('<pre><code className="language-js">console.log(1)</code></pre>')

console.log(String(file))

Alternatively, it’s possible to make highlighting safe by allowing all the classes used on tokens. Modifying the above code like so:

 const file = await unified()
   .use(rehypeParse, {fragment: true})
+  .use(rehypeHighlight, {subset: false})
   .use(rehypeSanitize, {
     ...defaultSchema,
     attributes: {
       ...defaultSchema.attributes,
-      code: [
-        ...(defaultSchema.attributes.code || []),
-        // List of all allowed languages:
-        ['className', 'hljs', 'language-js', 'language-css', 'language-md']
+      span: [
+        ...(defaultSchema.attributes.span || []),
+        // List of all allowed tokens:
+        ['className', 'hljs-addition', 'hljs-attr', 'hljs-attribute', 'hljs-built_in', 'hljs-bullet', 'hljs-char', 'hljs-code', 'hljs-comment', 'hljs-deletion', 'hljs-doctag', 'hljs-emphasis', 'hljs-formula', 'hljs-keyword', 'hljs-link', 'hljs-literal', 'hljs-meta', 'hljs-name', 'hljs-number', 'hljs-operator', 'hljs-params', 'hljs-property', 'hljs-punctuation', 'hljs-quote', 'hljs-regexp', 'hljs-section', 'hljs-selector-attr', 'hljs-selector-class', 'hljs-selector-id', 'hljs-selector-pseudo', 'hljs-selector-tag', 'hljs-string', 'hljs-strong', 'hljs-subst', 'hljs-symbol', 'hljs-tag', 'hljs-template-tag', 'hljs-template-variable', 'hljs-title', 'hljs-type', 'hljs-variable'
+          ]
       ]
     }
   })
-  .use(rehypeHighlight, {subset: false})
   .use(rehypeStringify)
   .process('<pre><code className="language-js">console.log(1)</code></pre>')

Types

This package is fully typed with TypeScript. It exports the additional type Options.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, rehype-sanitize@^6, compatible with Node.js 16.

This plugin works with rehype-parse version 3+, rehype-stringify version 3+, rehype version 5+, and unified version 6+.

Security

The defaults are safe but improper use of rehype-sanitize can open you up to a cross-site scripting (XSS) attack.

Use rehype-sanitize after the last unsafe thing: everything after rehype-sanitize could be unsafe (but is fine if you do trust it).

Related

Contribute

See contributing.md in rehypejs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

rehype-sanitize's People

Contributors

greenkeeperio-bot avatar pd4d10 avatar trebeljahr avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

wiatt1706 teleki

rehype-sanitize's Issues

h2 id is consistently removed

Initial checklist

Affected packages and versions

6.0.0

Link to runnable example

No response

Steps to reproduce

no build or bundle tools, only the specific npms required to run this bit of code.

import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeSlug from 'rehype-slug'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'

  unified()
    .use(rehypeParse)
    .use(rehypeSlug)
    .use(rehypeSanitize)
    .use(rehypeStringify)
    .processSync('<h1>foo</h1><h2>bar</h2><h3>baz</h3>')

Expected behavior

h2 to have an id:

<h1 id="user-content-foo">foo</h1>
<h2 id="user-content-bar">bar</h2>
<h3 id="user-content-baz">baz</h3>

Actual behavior

h2 does not have an id:

<h1 id="user-content-foo">foo</h1>
<h2>bar</h2>
<h3 id="user-content-baz">baz</h3>

Runtime

Node v16

Package manager

npm 8

OS

Linux

Build and bundle tools

Other (please specify in steps to reproduce)

Schema ancestors are not respected

Subject of the issue

A schemas ancestors property is not respected.

Your environment

Steps to reproduce

Simple schema:

{
  "ancestors": {
    "li": ["ul"]
  },
  "tagNames": [
    "div",
    "ul",
    "li"
  ]
}

HTML:

<div>
  <li>List Item</li>
</div>

Expected behavior

Expecting the resulting tree to exclude the li tag:

root[1]
│ data: {"quirksMode":true}
└─0 element<div>[3]
    │ properties: {}
    ├─0 text "\n  "
    ├─1 text "List Item"
    └─2 text "\n"

Actual behavior

The li tag is still included:

root[1]
│ data: {"quirksMode":true}
└─0 element<div>[3]
    │ properties: {}
    ├─0 text "\n  "
    ├─1 element<li>[1]
    │   │ properties: {}
    │   └─0 text "List Item"
    └─2 text "\n"

I investigated a bit and it seems like this bug has appeared because of this: syntax-tree/hast-util-sanitize@19631bb#diff-92bbac9a308cd5fcf9db165841f2d90ce981baddcb2b1e26cfff170929af3bd1R252. I can create a PR for it if you want.

Some attributes explicitly allowed are being removed

Subject of the issue

I'm trying to sanitize html and some explicitly allowed tags and attributes are being removed when they are expected to remain.

Your environment

  • OS: Ubuntu 20.04
  • Packages:

The packages were installed with:

$ yarn add rehype-sanitize unified rehype-parse rehype-stringify to-vfile

version list:

$ yarn list --pattern "rehype-sanitize|unified|rehype-parse|rehype-stringify|to-vfile"
yarn list v1.22.5
├─ [email protected]
│  └─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
│  └─ [email protected]
├─ [email protected]
└─ [email protected]
  • Env: node v14.5.0

Steps to reproduce

full minimal reproduction:

original html sample (page.html):


<table class="table">
  <tbody>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="firstName">
          Your first name
        </label>
      </td>
      <td>
        <input
          type="text"
          class="form-control"
          name="firstName"
          placeholder="E.g. John"
          autofocus
          required
        />
      </td>
    </tr>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="lastName">
          Your last name
        </label>
      </td>
      <td>
        <input
          type="text"
          class="form-control"
          name="lastName"
          placeholder="E.g. Doe"
          autofocus
          required
        />
      </td>
    </tr>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="email">
          Your work email<sup></sup>
        </label>
      </td>
      <td>
        <input
          type="email"
          class="form-control"
          name="email"
          placeholder="E.g. [email protected]"
          required
          inputmode="email"
        />
      </td>
    </tr>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="country">
          Country<sup></sup>
        </label>
      </td>
      <td>
        <select class="custom-select" required name="country">
          <option value>Select your country...</option>
          <option value="us">United States</option>
          <option value="fr">France</option>
          <option value="es">Japan</option>
        </select>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <label
          class="text-capitalize text-center"
          for="text"
          style="margin-top: 10px"
        >
          Your message<sup></sup>
        </label>
        <div class="form-group">
          <textarea
            class="form-control"
            rows="10"
            placeholder="Write your message text here..."
            required
            name="text"
            spellcheck="true"
          ></textarea>
        </div>
      </td>
    </tr>
    <tr>
      <td></td>
      <td class="text-right">
        <button
          class="btn btn-outline-light btn-lg text-capitalize"
          id="submit-contact-message"
          type="submit"
        >
          Send message
        </button>
      </td>
    </tr>
  </tbody>
</table>
<picture aria-label="My label">
  <source srcset="1.webp 128w" type="image/webp" />
  <source srcset="1.png 128w" type="image/png" />
  <img class="someClass" alt="my-image" data-src="img/1.png"
/></picture>

the script that uses rehype-sanitize (index.js):

const unified = require("unified");
const parser = require("rehype-parse");
const stringify = require("rehype-stringify");
const toVfile = require("to-vfile");
const fs = require("fs-extra");
const sanitize = require("rehype-sanitize");

sanitizeHTML();

function sanitizeHTML() {
  var schema = fs.readJSONSync("./sanitize-schema.json");
  unified()
    .use(parser, {
      fragment: true,
    })
    .use(sanitize, schema)
    .use(stringify)
    .process(toVfile.readSync("./page.html"), (err, file) => {
      if (err) {
        throw new Error(err);
      }
      fs.writeFileSync("./sanitized.html", String(file));
    });
}

the JSON schema I'm using (sanitize-schema.json):

{
  "strip": ["script"],
  "clobberPrefix": "user-content-",
  "clobber": [],
  "ancestors": {
    "tbody": ["table"],
    "tfoot": ["table"],
    "thead": ["table"],
    "td": ["table"],
    "th": ["table"],
    "tr": ["table"],
    "li": ["ol", "ul"]
  },
  "protocols": {
    "href": ["http", "https", "mailto", "xmpp", "irc", "ircs"],
    "cite": ["http", "https"],
    "src": ["http", "https"],
    "longDesc": ["http", "https"]
  },
  "tagNames": [
    "h1",
    "h2",
    "h3",
    "h4",
    "h5",
    "h6",
    "br",
    "b",
    "i",
    "strong",
    "em",
    "a",
    "pre",
    "code",
    "img",
    "tt",
    "div",
    "ins",
    "del",
    "sup",
    "sub",
    "p",
    "ol",
    "ul",
    "table",
    "thead",
    "tbody",
    "tfoot",
    "blockquote",
    "dl",
    "dt",
    "dd",
    "kbd",
    "q",
    "samp",
    "var",
    "hr",
    "ruby",
    "rt",
    "rp",
    "li",
    "tr",
    "td",
    "th",
    "s",
    "strike",
    "summary",
    "details",
    "caption",
    "figure",
    "figcaption",
    "abbr",
    "bdo",
    "cite",
    "dfn",
    "mark",
    "small",
    "span",
    "time",
    "wbr",
    "input",
    "aside",
    "body",
    "button",
    "cite",
    "details",
    "footer",
    "head",
    "header",
    "html",
    "label",
    "link",
    "main",
    "meta",
    "nav",
    "picture",
    "section",
    "select",
    "option",
    "source",
    "strike",
    "summary",
    "svg",
    "textarea",
    "title"
  ],
  "attributes": {
    "a": ["href"],
    "img": ["src", "longDesc"],
    "input": ["placeholder", "type", "autofocus", "required", "inputmode"],
    "li": ["className"],
    "div": ["itemScope", "itemType"],
    "blockquote": ["cite"],
    "del": ["cite"],
    "ins": ["cite"],
    "q": ["cite"],
    "*": [
      "abbr",
      "accept",
      "acceptCharset",
      "accessKey",
      "action",
      "align",
      "alt",
      "ariaDescribedBy",
      "ariaHidden",
      "ariaLabel",
      "ariaLabelledBy",
      "axis",
      "border",
      "cellPadding",
      "cellSpacing",
      "char",
      "charOff",
      "charSet",
      "checked",
      "clear",
      "cols",
      "colSpan",
      "color",
      "compact",
      "coords",
      "dateTime",
      "dir",
      "disabled",
      "encType",
      "htmlFor",
      "frame",
      "headers",
      "height",
      "hrefLang",
      "hSpace",
      "isMap",
      "id",
      "label",
      "lang",
      "maxLength",
      "media",
      "method",
      "multiple",
      "name",
      "noHref",
      "noShade",
      "noWrap",
      "open",
      "prompt",
      "readOnly",
      "rel",
      "rev",
      "rows",
      "rowSpan",
      "rules",
      "scope",
      "selected",
      "shape",
      "size",
      "span",
      "start",
      "summary",
      "tabIndex",
      "target",
      "title",
      "type",
      "useMap",
      "vAlign",
      "value",
      "vSpace",
      "width",
      "itemProp",
      "ariaControls",
      "ariaExpanded",
      "className",
      "contenteditable",
      "data*",
      "role",
      "spellcheck",
      "style"
    ],
    "link": ["href"],
    "meta": ["content", "name", "property"],
    "source": ["srcset", "type"],
    "label": ["for"],
    "textarea": ["placeholder", "required", "autofocus", "inputmode"]
  },
  "required": {},
  "allowComments": true,
  "allowDoctypes": true
}

Run script with

$ node index.js

output html (sanitized.html):

<table class="table">
  <tbody>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="firstName">
          Your first name
        </label>
      </td>
      <td>
        <input
          type="text"
          class="form-control"
          name="firstName"
          placeholder="E.g. John"
          required
        />
      </td>
    </tr>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="lastName">
          Your last name
        </label>
      </td>
      <td>
        <input
          type="text"
          class="form-control"
          name="lastName"
          placeholder="E.g. Doe"
          required
        />
      </td>
    </tr>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="email">
          Your work email<sup></sup>
        </label>
      </td>
      <td>
        <input
          type="email"
          class="form-control"
          name="email"
          placeholder="E.g. [email protected]"
          required
        />
      </td>
    </tr>
    <tr>
      <td>
        <label class="text-capitalize text-center" for="country">
          Country<sup></sup>
        </label>
      </td>
      <td>
        <select class="custom-select" name="country">
          <option value="">Select your country...</option>
          <option value="us">United States</option>
          <option value="fr">France</option>
          <option value="es">Japan</option>
        </select>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <label
          class="text-capitalize text-center"
          for="text"
          style="margin-top: 10px"
        >
          Your message<sup></sup>
        </label>
        <div class="form-group">
          <textarea
            class="form-control"
            rows="10"
            placeholder="Write your message text here..."
            required
            name="text"
          ></textarea>
        </div>
      </td>
    </tr>
    <tr>
      <td></td>
      <td class="text-right">
        <button
          class="btn btn-outline-light btn-lg text-capitalize"
          id="submit-contact-message"
          type="submit"
        >
          Send message
        </button>
      </td>
    </tr>
  </tbody>
</table>
<picture aria-label="My label">
  <source type="image/webp" />
  <source type="image/png" />
  <img class="someClass" alt="my-image" data-src="img/1.png"
/></picture>

things to note:

  • the autofocus attribute is removed everywhere despite being explicitly allowed with "input": ["placeholder", "type", "autofocus", "required", "inputmode"],
  • the srcset attribute is removed everywhere despite being allowed with "source": ["srcset", "type"],
  • the same happens with inputmode attribute despite being allowed "input": ["placeholder", "type", "autofocus", "required", "inputmode"],
  • same thing happens with spellcheck despite being allowed under "*"

Expected behavior

The explicitly allowed attributes should remain in the sanitized html.

Actual behavior

Some explicitly allowed attributes are removed from the sanitized output as noted above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.