Skip to content

Commit 263bed9

Browse files
authored
docs: automate docs with eslint-doc-generator (#101)
1 parent 657921a commit 263bed9

35 files changed

+2795
-198
lines changed

.eslint-doc-generatorrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { format } = require('prettier');
2+
const { prettier: prettierRC } = require('./.prettierrc.json');
3+
4+
/** @type {import('eslint-doc-generator').GenerateOptions} */
5+
const config = {
6+
postprocess: (doc) => format(doc, { ...prettierRC, parser: 'markdown' }),
7+
};
8+
9+
module.exports = config;

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
},
1414
"rules": {
1515
"eslint-plugin/prefer-message-ids": "off", // TODO: enable
16+
"eslint-plugin/require-meta-docs-description": ["error", { "pattern": "^(Detects|Enforces|Requires|Disallows) .+\\.$" }],
1617
"eslint-plugin/require-meta-docs-url": [
1718
"error",
1819
{
1920
"pattern":
20-
"https://github.com/nodesecurity/eslint-plugin-security#{{name}}",
21+
"https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/{{name}}.md",
2122
},
2223
],
2324
"eslint-plugin/require-meta-schema": "off", // TODO: enable

.markdownlint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"line-length": false,
3+
"no-inline-html": { "allowed_elements": ["kbd"]}
4+
}

.markdownlintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CHANGELOG.md
2+
LICENSE
3+
node_modules

README.md

Lines changed: 36 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ ESLint rules for Node Security
66

77
This project will help identify potential security hotspots, but finds a lot of false positives which need triage by a human.
88

9-
### Installation
9+
## Installation
1010

11-
`npm install --save-dev eslint-plugin-security` or `yarn add eslint-plugin-security --dev`
11+
```sh
12+
npm install --save-dev eslint-plugin-security
13+
```
14+
15+
or
16+
17+
```sh
18+
yarn add --dev eslint-plugin-security
19+
```
1220

13-
### Usage
21+
## Usage
1422

1523
Add the following to your `.eslintrc` file:
1624

@@ -31,86 +39,33 @@ Add the following to your `.eslintrc` file:
3139
npm run-script cont-int
3240
```
3341

34-
### Tests
42+
## Tests
3543

3644
```sh
3745
npm test
3846
```
3947

40-
### Rules
41-
42-
#### `detect-unsafe-regex`
43-
44-
Locates potentially unsafe regular expressions, which may take a very long time to run, blocking the event loop.
45-
46-
More information: [Regular Expression DoS and Node.js](docs/regular-expression-dos-and-node.md)
47-
48-
#### `detect-buffer-noassert`
49-
50-
Detect calls to [`buffer`](https://nodejs.org/api/buffer.html) with `noAssert` flag set.
51-
52-
From the Node.js API docs: "Setting `noAssert` to true skips validation of the `offset`. This allows the `offset` to be beyond the end of the `Buffer`."
53-
54-
#### `detect-child-process`
55-
56-
Detect instances of [`child_process`](https://nodejs.org/api/child_process.html) & non-literal [`exec()`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
57-
58-
More information: [Avoiding Command Injection in Node.js](docs/avoid-command-injection-node.md)
59-
60-
#### `detect-disable-mustache-escape`
61-
62-
Detects `object.escapeMarkup = false`, which can be used with some template engines to disable escaping of HTML entities. This can lead to Cross-Site Scripting (XSS) vulnerabilities.
63-
64-
More information: [OWASP XSS](<https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)>)
65-
66-
#### `detect-eval-with-expression`
67-
68-
Detects `eval(variable)` which can allow an attacker to run arbitrary code inside your process.
69-
70-
More information: [What are the security issues with eval in JavaScript?](http://security.stackexchange.com/questions/94017/what-are-the-security-issues-with-eval-in-javascript)
71-
72-
#### `detect-no-csrf-before-method-override`
73-
74-
Detects Express `csrf` middleware setup before `method-override` middleware. This can allow `GET` requests (which are not checked by `csrf`) to turn into `POST` requests later.
75-
76-
More information: [Bypass Connect CSRF protection by abusing methodOverride Middleware](docs/bypass-connect-csrf-protection-by-abusing.md)
77-
78-
#### `detect-non-literal-fs-filename`
79-
80-
Detects variable in filename argument of `fs` calls, which might allow an attacker to access anything on your system.
81-
82-
More information: [OWASP Path Traversal](https://www.owasp.org/index.php/Path_Traversal)
83-
84-
#### `detect-non-literal-regexp`
85-
86-
Detects `RegExp(variable)`, which might allow an attacker to DOS your server with a long-running regular expression.
87-
88-
More information: [Regular Expression DoS and Node.js](docs/regular-expression-dos-and-node.md)
89-
90-
#### `detect-non-literal-require`
91-
92-
Detects `require(variable)`, which might allow an attacker to load and run arbitrary code, or access arbitrary files on disk.
93-
94-
More information: [Where does Node.js and require look for modules?](http://www.bennadel.com/blog/2169-where-does-node-js-and-require-look-for-modules.htm)
95-
96-
#### `detect-object-injection`
97-
98-
Detects `variable[key]` as a left- or right-hand assignment operand.
99-
100-
More information: [The Dangers of Square Bracket Notation](docs/the-dangers-of-square-bracket-notation.md)
101-
102-
#### `detect-possible-timing-attacks`
103-
104-
Detects insecure comparisons (`==`, `!=`, `!==` and `===`), which check input sequentially.
105-
106-
More information: [A lesson in timing attacks](https://codahale.com/a-lesson-in-timing-attacks/)
107-
108-
#### `detect-pseudoRandomBytes`
109-
110-
Detects if `pseudoRandomBytes()` is in use, which might not give you the randomness you need and expect.
111-
112-
More information: [Randombytes vs pseudorandombytes](http://stackoverflow.com/questions/18130254/randombytes-vs-pseudorandombytes)
113-
114-
#### `detect-new-buffer`
115-
116-
Detect instances of new Buffer(argument) where argument is any non-literal value.
48+
## Rules
49+
50+
<!-- begin auto-generated rules list -->
51+
52+
⚠️ Configurations set to warn in.\
53+
✅ Set in the `recommended` configuration.
54+
55+
| Name                                  | Description | ⚠️ |
56+
| :------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-- |
57+
| [detect-buffer-noassert](docs/rules/detect-buffer-noassert.md) | Detects calls to "buffer" with "noAssert" flag set. ||
58+
| [detect-child-process](docs/rules/detect-child-process.md) | Detects instances of "child_process" & non-literal "exec()" calls. ||
59+
| [detect-disable-mustache-escape](docs/rules/detect-disable-mustache-escape.md) | Detects "object.escapeMarkup = false", which can be used with some template engines to disable escaping of HTML entities. ||
60+
| [detect-eval-with-expression](docs/rules/detect-eval-with-expression.md) | Detects "eval(variable)" which can allow an attacker to run arbitrary code inside your process. ||
61+
| [detect-new-buffer](docs/rules/detect-new-buffer.md) | Detects instances of new Buffer(argument) where argument is any non-literal value. ||
62+
| [detect-no-csrf-before-method-override](docs/rules/detect-no-csrf-before-method-override.md) | Detects Express "csrf" middleware setup before "method-override" middleware. ||
63+
| [detect-non-literal-fs-filename](docs/rules/detect-non-literal-fs-filename.md) | Detects variable in filename argument of "fs" calls, which might allow an attacker to access anything on your system. ||
64+
| [detect-non-literal-regexp](docs/rules/detect-non-literal-regexp.md) | Detects "RegExp(variable)", which might allow an attacker to DOS your server with a long-running regular expression. ||
65+
| [detect-non-literal-require](docs/rules/detect-non-literal-require.md) | Detects "require(variable)", which might allow an attacker to load and run arbitrary code, or access arbitrary files on disk. ||
66+
| [detect-object-injection](docs/rules/detect-object-injection.md) | Detects "variable[key]" as a left- or right-hand assignment operand. ||
67+
| [detect-possible-timing-attacks](docs/rules/detect-possible-timing-attacks.md) | Detects insecure comparisons (`==`, `!=`, `!==` and `===`), which check input sequentially. ||
68+
| [detect-pseudoRandomBytes](docs/rules/detect-pseudoRandomBytes.md) | Detects if "pseudoRandomBytes()" is in use, which might not give you the randomness you need and expect. ||
69+
| [detect-unsafe-regex](docs/rules/detect-unsafe-regex.md) | Detects potentially unsafe regular expressions, which may take a very long time to run, blocking the event loop. ||
70+
71+
<!-- end auto-generated rules list -->

docs/bypass-connect-csrf-protection-by-abusing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This issue was found and reported to us by [Luca Carettoni](http://twitter.com/_
88

99
Connect, methodOverride middleware
1010

11-
### Description:
11+
### Description
1212

1313
**Connect's "methodOverride" middleware allows an HTTP request to override the method of the request with the value of the "\_method" post key or with the header "x-http-method-override".**
1414

@@ -25,15 +25,15 @@ app.use express.methodOverride()
2525

2626
Connect's CSRF middleware does not check csrf tokens in case of idempotent verbs (GET/HEAD/OPTIONS, see lib/middleware/csrf.js). As a result, it is possible to bypass this security control by sending a GET request with a POST MethodOverride header or key.
2727

28-
### Example:
28+
### Example
2929

3030
```sh
3131
GET / HTTP/1.1
3232
[..]
3333
_method=POST
3434
```
3535

36-
### Mitigation Factors:
36+
### Mitigation Factors
3737

3838
Disable methodOverride or make sure that it takes precedence over other middleware declarations.
3939

docs/rules/detect-buffer-noassert.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Detects calls to "buffer" with "noAssert" flag set (`security/detect-buffer-noassert`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
Detect calls to [`buffer`](https://nodejs.org/api/buffer.html) with `noAssert` flag set.
8+
9+
From the Node.js API docs: "Setting `noAssert` to true skips validation of the `offset`. This allows the `offset` to be beyond the end of the `Buffer`."

docs/rules/detect-child-process.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Detects instances of "child_process" & non-literal "exec()" calls (`security/detect-child-process`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
Detect instances of [`child_process`](https://nodejs.org/api/child_process.html) & non-literal [`exec()`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
8+
9+
More information: [Avoiding Command Injection in Node.js](../avoid-command-injection-node.md)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Detects "object.escapeMarkup = false", which can be used with some template engines to disable escaping of HTML entities (`security/detect-disable-mustache-escape`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
This can lead to Cross-Site Scripting (XSS) vulnerabilities.
8+
9+
More information: [OWASP XSS](<https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)>)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Detects "eval(variable)" which can allow an attacker to run arbitrary code inside your process (`security/detect-eval-with-expression`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
More information: [What are the security issues with eval in JavaScript?](http://security.stackexchange.com/questions/94017/what-are-the-security-issues-with-eval-in-javascript)

0 commit comments

Comments
 (0)