зеркало из
1
0
Форкнуть 0
Custom ESLint rule to disallows unsafe innerHTML, outerHTML, insertAdjacentHTML and alike
Перейти к файлу
Frederik Braun 656771c0a3 Align testing & support for latest nodejs and eslint releases 2021-10-21 10:06:38 +02:00
.github/workflows Align testing & support for latest nodejs and eslint releases 2021-10-21 10:06:38 +02:00
docs/rules Introduce new configuration 'variableTracing', default to disabled. Adding tests for both states (fix #178) 2021-09-28 12:45:52 +02:00
lib Introduce new configuration 'variableTracing', default to disabled. Adding tests for both states (fix #178) 2021-09-28 12:45:52 +02:00
tests Introduce new configuration 'variableTracing', default to disabled. Adding tests for both states (fix #178) 2021-09-28 12:45:52 +02:00
.eslintrc.json - Testing: Add nyc for checking coverage (#121) 2020-06-03 15:17:24 +02:00
.gitignore Add newline to gitignore 2021-03-24 08:28:44 -07:00
CODE_OF_CONDUCT.md Add Mozilla Code of Conduct file (#103) 2019-04-01 11:24:01 +02:00
LICENSE Add LICENSE file (MPL-2.0 already in package.json) 2018-11-28 10:53:12 +01:00
NOTES adding note to NOTES 2017-03-21 09:56:23 +01:00
README.md - Enhancement: Avoid need for `plugins` when using `extends` (#112) 2020-02-03 08:55:21 +00:00
SCHEMA.md Custom rules for configuring rules. Fixes #29 (#51) 2017-04-21 16:52:12 +02:00
SECURITY.md Create SECURITY.md (#139) 2020-06-29 16:08:53 +02:00
index.js Eslint 6 new parser-test api compat (#119) 2020-03-20 07:46:28 +00:00
package-lock.json Update outdated dependencies 2021-10-21 10:06:38 +02:00
package.json Update dependencies 2021-10-21 10:06:38 +02:00
yarn.lock Update outdated dependencies 2021-10-21 10:06:38 +02:00

README.md

Build Status

Disallow unsanitized code (no-unsanitized)

These rules disallow unsafe coding practices that may result into security vulnerabilities. We will disallow assignments (e.g., to innerHTML)as well as calls (e.g., to insertAdjacentHTML) without the use of a pre-defined escaping function. The escaping functions must be called with a template string. The function names are hardcoded as Sanitizer.escapeHTML and escapeHTML.

This rule is being used within Mozilla to maintain and improve the security of our products and services.

Rule Details

method

The method rule disallows certain function calls. E.g., document.write() or insertAdjacentHTML(). See docs/rules/method.md for more.

property

The property rule disallows certain assignment expressions, e.g., to innerHTML.

See docs/rules/property.md for more.

Examples

Here are a few examples of code that we do not want to allow:

foo.innerHTML = input.value;
bar.innerHTML = "<a href='"+url+"'>About</a>";

A few examples of allowed practices:

foo.innerHTML = 5;
bar.innerHTML = "<a href='/about.html'>About</a>";
bar.innerHTML = escapeHTML`<a href='${url}'>About</a>`;

Install

With yarn or npm:

$ yarn add -D eslint-plugin-no-unsanitized
$ npm install --save-dev eslint-plugin-no-unsanitized

Usage

In your .eslintrc.json file enable this rule with the following:

{
    "extends": ["plugin:no-unsanitized/DOM"]
}

Or:

{
    "plugins": ["no-unsanitized"],
    "rules": {
        "no-unsanitized/method": "error",
        "no-unsanitized/property": "error"
    }
}

Documentation

See docs/.