From aea9b62737886386fbc2288a47fc5eff04b27dca Mon Sep 17 00:00:00 2001 From: Manuel Puyol Date: Thu, 24 Mar 2022 17:07:37 +0000 Subject: [PATCH 1/3] Add rule to prohibit building script tags in the client --- README.md | 1 + docs/rules/no-script-tag-building.md | 24 ++++++++++++++++++ lib/configs/recommended.js | 1 + lib/index.js | 1 + lib/rules/no-script-tag-building.js | 30 ++++++++++++++++++++++ tests/no-script-tag-building.js | 38 ++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 docs/rules/no-script-tag-building.md create mode 100644 lib/rules/no-script-tag-building.js create mode 100644 tests/no-script-tag-building.js diff --git a/README.md b/README.md index 24cde393..e19efc10 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ The available configs are: - [No Implicit Buggy Globals](./docs/rules/no-implicit-buggy-globals.md) - [No Inner HTML](./docs/rules/no-inner-html.md) - [No InnerText](./docs/rules/no-innerText.md) +- [No Script Tag Building](./docs/rules/no-script-tag-building.md) - [No Then](./docs/rules/no-then.md) - [No Useless Passive](./docs/rules/no-useless-passive.md) - [Prefer Observers](./docs/rules/prefer-observers.md) diff --git a/docs/rules/no-script-tag-building.md b/docs/rules/no-script-tag-building.md new file mode 100644 index 00000000..3342cf84 --- /dev/null +++ b/docs/rules/no-script-tag-building.md @@ -0,0 +1,24 @@ +# No Script Tag Building + +## Rule Details + +Creating dynamic script tags bypasses a lot of security measures - like SRIs - and pose a potential threat to your application. +Instead of creating a `script` tag in the client, provide all necessary `script` tags in the page's HTML. + +👎 Examples of **incorrect** code for this rule: + +```js +document.createElement('script') +document.getElementById('some-id').type = 'text/javascript' +``` + +👍 Examples of **correct** code for this rule: + +```html + +