eslint-plugin-node-security 4.4.3 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +119 -1
- package/README.md +1 -0
- package/package.json +28 -20
- package/src/index.js +18 -1
- package/src/index.js.map +1 -1
- package/src/rules/no-ssrf/index.js +87 -18
- package/src/rules/no-ssrf/index.js.map +1 -1
- package/src/rules/no-unsafe-buffer-alloc/index.d.ts +47 -0
- package/src/rules/no-unsafe-buffer-alloc/index.js +100 -0
- package/src/rules/no-unsafe-buffer-alloc/index.js.map +1 -0
- package/src/rules/require-secure-deletion/index.d.ts +5 -0
- package/src/rules/require-secure-deletion/index.js +71 -9
- package/src/rules/require-secure-deletion/index.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,120 @@
|
|
|
1
|
-
##
|
|
1
|
+
## 4.6.0
|
|
2
|
+
|
|
3
|
+
### Minor Changes
|
|
4
|
+
|
|
5
|
+
- [#305](https://github.com/ofri-peretz/eslint/pull/305) [`8f1c9ef`](https://github.com/ofri-peretz/eslint/commit/8f1c9efbe99c592f8ed5ffca2d1ed8f53408af19) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - New rule `no-unsafe-buffer-alloc` (CWE-908, Use of Uninitialized Resource) —
|
|
6
|
+
closes a measured coverage gap against `security-node/detect-buffer-unsafe-allocation`
|
|
7
|
+
and `@microsoft/eslint-plugin-sdl/no-unsafe-alloc`.
|
|
8
|
+
|
|
9
|
+
It reports `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()`, both of which
|
|
10
|
+
return memory that was never zeroed, with a suggestion to swap in
|
|
11
|
+
`Buffer.alloc()`. Neither the existing `no-deprecated-buffer` (deprecated
|
|
12
|
+
`Buffer()` constructor, CWE-676) nor `no-buffer-overread` (read-side CWE-126)
|
|
13
|
+
flagged the allocation itself.
|
|
14
|
+
|
|
15
|
+
**The rule is unconditional and does no dataflow** — it does not try to prove
|
|
16
|
+
the buffer is fully overwritten before it is read, so a correct
|
|
17
|
+
`allocUnsafe` + `copy` pair is still reported. The one structural exemption is
|
|
18
|
+
`Buffer.allocUnsafe(n).fill(0)`, a parent-node check rather than variable
|
|
19
|
+
tracking. Because of that false-positive profile it ships as `warn` in
|
|
20
|
+
`recommended` rather than `error` (upstream `security-node` ships its
|
|
21
|
+
equivalent off by default).
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#317](https://github.com/ofri-peretz/eslint/pull/317) [`5a8456b`](https://github.com/ofri-peretz/eslint/commit/5a8456b08ffa567be73a66393758ed17805e2fe4) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - `no-ssrf`: recognise `needle` as an HTTP client, so `needle.get(req.query.url)` reports. The verb-first `needle('get', url)` form is still not covered — the rule only inspects the first argument.
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`09d2951`](https://github.com/ofri-peretz/eslint/commit/09d2951b3ac74efc9ba49b64e9089d66800b16cc)]:
|
|
28
|
+
- @interlace/eslint-devkit@1.4.4
|
|
29
|
+
|
|
30
|
+
## 4.5.0
|
|
31
|
+
|
|
32
|
+
### Minor Changes
|
|
33
|
+
|
|
34
|
+
- [#310](https://github.com/ofri-peretz/eslint/pull/310) [`28d7898`](https://github.com/ofri-peretz/eslint/commit/28d789896b06dd13ac7c50bcb4aaa36fa5e4be29) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Add `no-timing-unsafe-compare` to the `recommended` preset, restoring CWE-697
|
|
35
|
+
coverage.
|
|
36
|
+
|
|
37
|
+
`secure-coding/no-insecure-comparison` was removed from every `secure-coding`
|
|
38
|
+
preset, with `node-security/no-timing-unsafe-compare` named as the replacement.
|
|
39
|
+
But that rule was not in any `recommended` preset, so the practical result was
|
|
40
|
+
that **no `recommended` preset anywhere covered CWE-697 timing-unsafe
|
|
41
|
+
comparison**, and the migration note pointed users at a rule they would have had
|
|
42
|
+
to enable by hand — which the note did not say.
|
|
43
|
+
|
|
44
|
+
It enters at `'warn'` rather than `'error'`, matching the precedent already set
|
|
45
|
+
by `no-deprecated-buffer` in this preset: adopters shouldn't have CI turn red on
|
|
46
|
+
a version bump. Promote to `'error'` on the next major.
|
|
47
|
+
|
|
48
|
+
Note the coverage now lives in a different package than before. A project that
|
|
49
|
+
installs only `eslint-plugin-secure-coding` and relied on its presets for this
|
|
50
|
+
check needs `eslint-plugin-node-security` as well.
|
|
51
|
+
|
|
52
|
+
A lock test in `src/index.test.ts` fails if the rule leaves `recommended` again,
|
|
53
|
+
since that would silently make the migration note false.
|
|
54
|
+
|
|
55
|
+
- [#288](https://github.com/ofri-peretz/eslint/pull/288) [`89bea05`](https://github.com/ofri-peretz/eslint/commit/89bea05c6c48f5f1bdbcc3c87b301d967d962051) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Cut false positives in five security rules, measured against a 1,470-file corpus (webpack `lib/`, lodash, eslint-plugin-import `src/`, and two NestJS boilerplates).
|
|
56
|
+
|
|
57
|
+
**`secure-coding/no-hardcoded-credentials` — decide on the value, not the key name.** The rule reported any string in a credential-named slot, so `errors: { password: 'incorrectPassword' }` (an i18n error key) was a CVSS 9.8 finding — 5 of its 10 corpus hits. Detection is now driven by the value's shape: entropy, character-class mix, charset, and a "natural word string" test that rejects identifier- and message-shaped values. A credential-shaped name is still consulted, but only to promote an already-secret-shaped value. Corpus: **10 → 7 findings, and all 7 are true positives** — including two the old logic missed, because a 25-character random `key:` is now found by shape rather than by being on a name allowlist.
|
|
58
|
+
|
|
59
|
+
**`secure-coding/no-unsafe-deserialization` — `setTimeout` is not a deserializer.** `await new Promise(resolve => setTimeout(resolve, 1000))` was rated CVSS 9.8 CRITICAL. `setTimeout` / `setInterval` now only report in their implied-`eval` form (string first argument), and calls inside a function named `deserialize` / `unserialize` / `fromJSON` / `fromBuffer` — a class implementing a serialization protocol — are exempt. Corpus: **35 → 4**.
|
|
60
|
+
|
|
61
|
+
**`secure-coding/no-graphql-injection` — require real GraphQL syntax.** Any template literal containing a nested brace or the word `type` was a CVSS 9.8 GraphQL injection. Operation and schema keywords must now start a line, schema keywords require a body, and a bare selection set must be the entire string. Concatenations are matched on their reassembled static value rather than on their source text. Corpus: **41 → 0**.
|
|
62
|
+
|
|
63
|
+
**`node-security/require-secure-deletion` — only sensitive properties.** The rule fired on every `delete obj.prop`. It now reports only a statically known, sensitive property name (`password`, `token`, `apiKey`, `privateKey`, `sessionId`, …), configurable via the new `additionalSensitiveProperties` option, and understands computed access and optional chaining. Corpus: **25 → 1** (a genuine `delete userDto.oldPassword`).
|
|
64
|
+
|
|
65
|
+
**`secure-coding/no-insecure-comparison` — removed from `recommended`, `recommended-strict` and `owasp-top-10`.** It is deprecated in favour of `node-security/no-timing-unsafe-compare`, and its loose-equality half re-reports core `eqeqeq` under a CWE-697 banner — 433 corpus findings, all duplicates. No narrowing fixes that, so the honest change is to stop switching it on for people; it remains exported and available via `strict` or explicit opt-in. Its timing-attack half was also narrowed to match secret keywords on identifier **word segments** instead of substrings of the whole expression text, which stops `if (key === "__non_webpack_require__")` (and `monkey`, `keyword`, `machine`, `author`) from being reported: **443 → 221**.
|
|
66
|
+
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- [#294](https://github.com/ofri-peretz/eslint/pull/294) [`659f6dc`](https://github.com/ofri-peretz/eslint/commit/659f6dc0181b03b675f72b5949fcf123dd066358) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Rewrite `description` and `keywords` on every published package for npm search discovery. npm ranks on name, description, and keywords, and the registry only picks up these fields at publish — so this is metadata-only and takes effect for each package on its next release.
|
|
70
|
+
|
|
71
|
+
**Descriptions now lead with the search phrase.** Every one starts `ESLint plugin for <the thing you'd search>` instead of a brand-first or category-first framing, and names the concrete vulnerabilities the plugin actually detects. Three were corrected while doing so:
|
|
72
|
+
|
|
73
|
+
- `eslint-plugin-import-next` claimed "100x faster no-cycle detection". No 100x measurement exists: `CLAIMS.md` records **3.1x end-to-end** (8x in pure rule execution) on a 5,483-file React codebase, and the highest number in any benchmark result is 54.9x on the synthetic corpus. The description now states the real-codebase figure.
|
|
74
|
+
- `eslint-plugin-secure-coding` claimed SQL injection, XSS and CSRF coverage — none of which are its rules. It now names what it does detect: LDAP, XPath, XXE, GraphQL and template injection, unsafe deserialization, ReDoS, missing authentication, and PII in logs.
|
|
75
|
+
- `eslint-plugin-secure-coding` ("89 rules") and `eslint-plugin-react-a11y` ("37 rules") hard-coded rule counts that had drifted from reality. Counts are generated into `interlace-numbers.json`; hand-typed copies are removed rather than corrected.
|
|
76
|
+
|
|
77
|
+
**Keywords now match the vocabulary of the plugins that rank.** `eslint-plugin-security`, `eslint-plugin-jsx-a11y`, `eslint-plugin-n` and `eslint-plugin-import` all carry the `eslint` / `eslintplugin` / `eslint-plugin` trio — six of our packages were missing `eslintplugin`, and every one now carries all three plus `static-analysis`, `linting` and `code-quality`. Security plugins add `sast`, `appsec` and `vulnerability`; `node-security` and `secure-coding` also carry `nodesecurity`, the exact keyword `eslint-plugin-security` ranks on. Each plugin gained the CWE identifiers and attack names for what it detects (`cwe-78` command injection, `cwe-22` path traversal, `cwe-89` SQL injection, `cwe-79` XSS, `cwe-347` JWT algorithm confusion, `cwe-352` CSRF, `cwe-943` NoSQL injection), and `node-security` gained the crypto vocabulary it had been missing entirely despite absorbing the crypto rule set (`crypto`, `cryptography`, `weak-hash`, `md5`, `sha1`, `timing-attack`).
|
|
78
|
+
|
|
79
|
+
No rule behavior, exports, or configuration changes.
|
|
80
|
+
|
|
81
|
+
- [#296](https://github.com/ofri-peretz/eslint/pull/296) [`0c7a208`](https://github.com/ofri-peretz/eslint/commit/0c7a208f568436cc55ac6732641df46e8f44af1f) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Cut two false positives confirmed against the benchmark corpus SAFE fixtures.
|
|
82
|
+
|
|
83
|
+
**`node-security/no-ssrf`** — the user-input gate only ran when the URL argument
|
|
84
|
+
was a bare identifier, so every other shape reported unconditionally. A Node
|
|
85
|
+
options object built from a helper's own parameters —
|
|
86
|
+
`https.request({ host, path, method: 'GET' })`, from
|
|
87
|
+
`benchmarks/corpus/CWE-444/safe/request-default-parser.js` — was flagged with no
|
|
88
|
+
user data anywhere in the flow.
|
|
89
|
+
|
|
90
|
+
The gate now applies to every argument shape and requires evidence: a
|
|
91
|
+
user-input-named identifier standing as the URL, a read off a request object
|
|
92
|
+
(`req` / `request` / `ctx` / `event`), or a template literal or concatenation
|
|
93
|
+
interpolating either. Options-object fields count when they are request-sourced,
|
|
94
|
+
or when a `url` / `href` / `uri` key holds a user-input-named identifier.
|
|
95
|
+
|
|
96
|
+
Newly ignored: options objects and interpolations built purely from locals.
|
|
97
|
+
Still reported: `fetch(userUrl)`, `fetch(req.query.url)`,
|
|
98
|
+
`https.request({ host: req.query.host })`, ``fetch(`https://${userHost}/x`)``.
|
|
99
|
+
|
|
100
|
+
**`secure-coding/no-hardcoded-credentials`** — `secret: '<your-secret-here>'`
|
|
101
|
+
from `benchmarks/corpus/CWE-798/safe/test-placeholder-values.js` was reported at
|
|
102
|
+
CVSS 9.8. The angle brackets are two character classes, which is all the shape
|
|
103
|
+
gate asks for once the slot is credential-named.
|
|
104
|
+
|
|
105
|
+
Self-evident placeholders are now skipped: bracketed template slots (`<…>`,
|
|
106
|
+
`{{…}}`, `${…}`, `[…]`), placeholder words standing as their own token
|
|
107
|
+
(`changeme`, `YOUR_API_KEY`, `example`), and one character repeated
|
|
108
|
+
(`xxxxxxxxxxxx`). Whole-token matching only, so a real secret that merely
|
|
109
|
+
contains such a substring is unaffected.
|
|
110
|
+
|
|
111
|
+
The allowlist applies to non-structural findings only — a JWT, an `sk_live_`
|
|
112
|
+
key, or a `postgres://user:pass@host` string still reports whatever words it
|
|
113
|
+
contains. Set the new `allowPlaceholders: false` option to restore the previous
|
|
114
|
+
behaviour.
|
|
115
|
+
|
|
116
|
+
- Updated dependencies [[`e1cdf83`](https://github.com/ofri-peretz/eslint/commit/e1cdf83e3db761907f0ab06f7fc6c1f1da7513a5), [`659f6dc`](https://github.com/ofri-peretz/eslint/commit/659f6dc0181b03b675f72b5949fcf123dd066358)]:
|
|
117
|
+
- @interlace/eslint-devkit@1.4.3
|
|
2
118
|
|
|
3
119
|
## 4.4.3
|
|
4
120
|
|
|
@@ -160,6 +276,8 @@
|
|
|
160
276
|
- Updated dependencies [[`736a5fe`](https://github.com/ofri-peretz/eslint/commit/736a5fed47e673f6157ea900b29fe2a54e4bc7df)]:
|
|
161
277
|
- @interlace/eslint-devkit@1.4.1
|
|
162
278
|
|
|
279
|
+
## [4.1.0] - 2026-05-03
|
|
280
|
+
|
|
163
281
|
### Added
|
|
164
282
|
|
|
165
283
|
- New rule `no-deprecated-buffer` — flags use of the deprecated `Buffer()` constructor (Node.js security advisory; `Buffer.from`/`Buffer.alloc` should be used instead). Enabled in the `recommended` preset at `warn` to avoid breaking adopters with legacy `Buffer()` calls; will be promoted to `error` in the next major.
|
package/README.md
CHANGED
|
@@ -105,6 +105,7 @@ See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md)
|
|
|
105
105
|
| [no-static-iv](https://eslint.interlace.tools/docs/security/plugin-node-security/rules/no-static-iv?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-node-security) | CWE-329 | A02:2021 | | Disallow static or hardcoded initialization vectors (IVs) | 🟢 | | | | | |
|
|
106
106
|
| [no-timing-unsafe-compare](https://eslint.interlace.tools/docs/security/plugin-node-security/rules/no-timing-unsafe-compare?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-node-security) | CWE-208 | A02:2021 | | Disallow timing-unsafe comparison of secrets | 🟢 | | | | | |
|
|
107
107
|
| [no-toctou-vulnerability](https://eslint.interlace.tools/docs/security/plugin-node-security/rules/no-toctou-vulnerability?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-node-security) | CWE-367 | A01:2021 | | Detects Time-of-Check-Time-of-Use (TOCTOU) race condition vulnerabilities in file system operations. | 🟢 | | | | | |
|
|
108
|
+
| [no-unsafe-buffer-alloc](https://eslint.interlace.tools/docs/security/plugin-node-security/rules/no-unsafe-buffer-alloc?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-node-security) | CWE-908 | A01:2021 | | Disallow `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()`, which return uninitialized memory. | 🟢 | | | | 💡 | |
|
|
108
109
|
| [no-unsafe-dynamic-require](https://eslint.interlace.tools/docs/security/plugin-node-security/rules/no-unsafe-dynamic-require?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-node-security) | CWE-494 | | | Disallows dynamic require() calls with non-literal arguments that could lead to security vulnerabilities | 🟢 | | | | | |
|
|
109
110
|
| [no-weak-cipher-algorithm](https://eslint.interlace.tools/docs/security/plugin-node-security/rules/no-weak-cipher-algorithm?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-node-security) | CWE-327 | A02:2021 | | Disallow weak cipher algorithms (DES, 3DES, RC4, Blowfish, RC2, IDEA) | 🟢 | | | | | |
|
|
110
111
|
| [no-weak-hash-algorithm](https://eslint.interlace.tools/docs/security/plugin-node-security/rules/no-weak-hash-algorithm?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-node-security) | CWE-327 | A02:2021 | | Disallow weak hash algorithms (MD5, MD4, SHA-1, RIPEMD) | 🟢 | | | | | |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-node-security",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.6.0",
|
|
4
|
+
"description": "ESLint plugin for Node.js security — detects command injection, path traversal, SSRF, zip slip, and weak crypto (MD5/SHA-1, ECB, static IV) in fs, child_process, vm, and crypto.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
@@ -43,38 +43,46 @@
|
|
|
43
43
|
],
|
|
44
44
|
"keywords": [
|
|
45
45
|
"eslint",
|
|
46
|
-
"eslint-plugin",
|
|
47
46
|
"eslintplugin",
|
|
48
|
-
"
|
|
47
|
+
"eslint-plugin",
|
|
48
|
+
"static-analysis",
|
|
49
|
+
"linting",
|
|
50
|
+
"code-quality",
|
|
49
51
|
"security",
|
|
50
|
-
"
|
|
52
|
+
"sast",
|
|
53
|
+
"appsec",
|
|
54
|
+
"vulnerability",
|
|
55
|
+
"owasp",
|
|
56
|
+
"cwe",
|
|
57
|
+
"interlace-security",
|
|
58
|
+
"node",
|
|
51
59
|
"nodejs",
|
|
52
|
-
"
|
|
60
|
+
"node-security",
|
|
61
|
+
"nodesecurity",
|
|
53
62
|
"command-injection",
|
|
63
|
+
"cwe-78",
|
|
54
64
|
"path-traversal",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
65
|
+
"cwe-22",
|
|
66
|
+
"ssrf",
|
|
67
|
+
"zip-slip",
|
|
68
|
+
"child-process",
|
|
69
|
+
"crypto",
|
|
70
|
+
"cryptography",
|
|
71
|
+
"weak-hash",
|
|
72
|
+
"md5",
|
|
73
|
+
"sha1",
|
|
74
|
+
"timing-attack",
|
|
61
75
|
"llm-optimized",
|
|
62
76
|
"ai-assistant",
|
|
63
|
-
"auto-fix",
|
|
64
77
|
"typescript",
|
|
65
|
-
"
|
|
66
|
-
"code-quality",
|
|
67
|
-
"ast",
|
|
68
|
-
"static-analysis",
|
|
69
|
-
"mcp",
|
|
70
|
-
"model-context-protocol"
|
|
78
|
+
"auto-fix"
|
|
71
79
|
],
|
|
72
80
|
"engines": {
|
|
73
81
|
"node": ">=18.0.0"
|
|
74
82
|
},
|
|
75
83
|
"dependencies": {
|
|
76
84
|
"tslib": "^2.3.0",
|
|
77
|
-
"@interlace/eslint-devkit": "^1.4.
|
|
85
|
+
"@interlace/eslint-devkit": "^1.4.4"
|
|
78
86
|
},
|
|
79
87
|
"devDependencies": {
|
|
80
88
|
"@typescript-eslint/parser": "^8.46.2",
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const detect_non_literal_fs_filename_1 = require("./rules/detect-non-literal-fs-
|
|
|
12
12
|
const no_unsafe_dynamic_require_1 = require("./rules/no-unsafe-dynamic-require");
|
|
13
13
|
const no_buffer_overread_1 = require("./rules/no-buffer-overread");
|
|
14
14
|
const no_deprecated_buffer_1 = require("./rules/no-deprecated-buffer");
|
|
15
|
+
const no_unsafe_buffer_alloc_1 = require("./rules/no-unsafe-buffer-alloc");
|
|
15
16
|
const no_toctou_vulnerability_1 = require("./rules/no-toctou-vulnerability");
|
|
16
17
|
const no_zip_slip_1 = require("./rules/no-zip-slip");
|
|
17
18
|
const no_arbitrary_file_access_1 = require("./rules/no-arbitrary-file-access");
|
|
@@ -50,6 +51,7 @@ exports.rules = {
|
|
|
50
51
|
'no-unsafe-dynamic-require': no_unsafe_dynamic_require_1.noUnsafeDynamicRequire,
|
|
51
52
|
'no-buffer-overread': no_buffer_overread_1.noBufferOverread,
|
|
52
53
|
'no-deprecated-buffer': no_deprecated_buffer_1.noDeprecatedBuffer,
|
|
54
|
+
'no-unsafe-buffer-alloc': no_unsafe_buffer_alloc_1.noUnsafeBufferAlloc,
|
|
53
55
|
'no-toctou-vulnerability': no_toctou_vulnerability_1.noToctouVulnerability,
|
|
54
56
|
'no-zip-slip': no_zip_slip_1.noZipSlip,
|
|
55
57
|
'no-arbitrary-file-access': no_arbitrary_file_access_1.noArbitraryFileAccess,
|
|
@@ -85,7 +87,7 @@ exports.rules = {
|
|
|
85
87
|
exports.plugin = {
|
|
86
88
|
meta: {
|
|
87
89
|
name: 'eslint-plugin-node-security',
|
|
88
|
-
version: '4.
|
|
90
|
+
version: '4.6.0',
|
|
89
91
|
},
|
|
90
92
|
rules: exports.rules,
|
|
91
93
|
};
|
|
@@ -105,6 +107,12 @@ const recommendedRules = {
|
|
|
105
107
|
// adopters who already use the preset and have legacy `Buffer()` calls.
|
|
106
108
|
// Promote to 'error' on the next major bump.
|
|
107
109
|
'node-security/no-deprecated-buffer': 'error',
|
|
110
|
+
// Added in 4.5.0. Unconditional flag on `Buffer.allocUnsafe()` — a real but
|
|
111
|
+
// legitimate performance API — so it ships as 'warn', not 'error'. The rule
|
|
112
|
+
// does no dataflow, so a correctly-overwritten buffer still reports.
|
|
113
|
+
// Upstream `security-node/detect-buffer-unsafe-allocation` ships this off by
|
|
114
|
+
// default; 'warn' is the middle ground.
|
|
115
|
+
'node-security/no-unsafe-buffer-alloc': 'warn',
|
|
108
116
|
'node-security/no-toctou-vulnerability': 'error',
|
|
109
117
|
'node-security/no-zip-slip': 'error',
|
|
110
118
|
'node-security/no-arbitrary-file-access': 'error',
|
|
@@ -112,6 +120,15 @@ const recommendedRules = {
|
|
|
112
120
|
'node-security/no-ssrf': 'warn',
|
|
113
121
|
'node-security/no-shell-injection': 'error',
|
|
114
122
|
'node-security/no-dynamic-algorithm-selection': 'error',
|
|
123
|
+
// Added to `recommended` 2026-08-02. `secure-coding/no-insecure-comparison`
|
|
124
|
+
// was removed from every `secure-coding` preset in favour of this rule, but
|
|
125
|
+
// this rule was not in any `recommended` preset — so CWE-697 timing-unsafe
|
|
126
|
+
// comparison had no preset coverage anywhere in the ecosystem, and the
|
|
127
|
+
// migration note pointed at a rule users would have had to enable by hand.
|
|
128
|
+
// Enters at 'warn' rather than 'error' for the same reason as
|
|
129
|
+
// `no-deprecated-buffer` above: adopters already on this preset shouldn't
|
|
130
|
+
// have CI turn red on a version bump. Promote on the next major.
|
|
131
|
+
'node-security/no-timing-unsafe-compare': 'warn',
|
|
115
132
|
// Migrated Rules
|
|
116
133
|
'node-security/detect-suspicious-dependencies': 'warn',
|
|
117
134
|
'node-security/lock-file': 'warn', // filesystem check — not pure AST; CI enforces this better
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,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8CAA8C,EAAE,MAAM;IACtD,yBAAyB,EAAE,MAAM,EAAE,2DAA2D;IAC9F,4CAA4C,EAAE,OAAO;IAErD,8BAA8B;IAC9B,sCAAsC,EAAE,OAAO;IAC/C,wCAAwC,EAAE,OAAO;IACjD,4BAA4B,EAAE,OAAO;IACrC,2BAA2B,EAAE,OAAO;IACpC,qCAAqC,EAAE,OAAO;IAC9C,2BAA2B,EAAE,OAAO;CACrC,CAAC;AAEW,QAAA,OAAO,GAA+C;IACjE,WAAW,EAAE;QACX,OAAO,EAAE;YACP,eAAe,EAAE,cAAM;SACxB;QACD,KAAK,EAAE,gBAAgB;KACa;IACtC,MAAM,EAAE;QACN,OAAO,EAAE;YACP,eAAe,EAAE,cAAM;SACxB;QACD,KAAK,EAAE,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,IAAI,CAAC,aAAK,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;YACnC,iBAAiB,QAAQ,EAAE;YAC3B,OAAO;SACR,CAAC,CACH;KACmC;CACvC,CAAC;AAEF,kBAAe,cAAM,CAAC"}
|
|
@@ -19,8 +19,10 @@ const HTTP_CLIENT_METHODS = new Set([
|
|
|
19
19
|
'get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'request',
|
|
20
20
|
]);
|
|
21
21
|
// Object names that are HTTP client libraries
|
|
22
|
+
// `needle.get(url)` is covered here; the `needle('get', url)` verb-first form
|
|
23
|
+
// is not — the URL sits in argument 1, and this rule only reads argument 0.
|
|
22
24
|
const HTTP_CLIENT_OBJECTS = new Set([
|
|
23
|
-
'axios', 'got', 'superagent', 'request', 'http', 'https', 'undici',
|
|
25
|
+
'axios', 'got', 'superagent', 'request', 'http', 'https', 'undici', 'needle',
|
|
24
26
|
]);
|
|
25
27
|
// Function names that indicate URL validation
|
|
26
28
|
const VALIDATION_FUNCTION_NAMES = new Set([
|
|
@@ -40,6 +42,82 @@ function isUserInputParamName(name) {
|
|
|
40
42
|
const lower = name.toLowerCase();
|
|
41
43
|
return USER_INPUT_SUBSTRINGS.some(sub => lower.includes(sub));
|
|
42
44
|
}
|
|
45
|
+
// Object roots whose members carry attacker-controlled data in the common
|
|
46
|
+
// server frameworks: Express `req`/`request`, Koa `ctx`, Lambda `event`.
|
|
47
|
+
const REQUEST_ROOT_NAMES = new Set(['req', 'request', 'ctx', 'event']);
|
|
48
|
+
// Keys of a Node `http.request(options)` object that actually name a URL.
|
|
49
|
+
// `host`/`hostname`/`path`/`port` are deliberately absent: a helper that
|
|
50
|
+
// parameterises them is ordinary internal plumbing, not evidence of user flow.
|
|
51
|
+
const URL_OPTION_KEYS = new Set(['url', 'href', 'uri']);
|
|
52
|
+
/**
|
|
53
|
+
* True when the expression reads off a request object — `req.query.url`,
|
|
54
|
+
* `ctx.request.body.target`, `event.queryStringParameters.u`. Everything
|
|
55
|
+
* hanging off a request is untrusted, so the root name is the whole test.
|
|
56
|
+
*/
|
|
57
|
+
function isRequestSourced(node) {
|
|
58
|
+
let current = node;
|
|
59
|
+
while (current.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
60
|
+
current = current.object;
|
|
61
|
+
}
|
|
62
|
+
return (current !== node &&
|
|
63
|
+
current.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
64
|
+
REQUEST_ROOT_NAMES.has(current.name.toLowerCase()));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Does the URL argument carry untrusted data into the request?
|
|
68
|
+
*
|
|
69
|
+
* The rule reports on evidence of flow, never on the mere presence of a
|
|
70
|
+
* dynamic argument. Three shapes qualify:
|
|
71
|
+
*
|
|
72
|
+
* 1. The whole argument is a user-input-named identifier — `fetch(userUrl)`.
|
|
73
|
+
* This is the rule's documented naming heuristic: a bare identifier in
|
|
74
|
+
* URL position *is* the URL.
|
|
75
|
+
* 2. Any part of the expression reads from a request object —
|
|
76
|
+
* `fetch(req.query.url)`, `https.request({ host: req.query.h })`.
|
|
77
|
+
* 3. A template literal URL interpolates either of the above —
|
|
78
|
+
* `fetch(\`https://\${userHost}/x\`)`.
|
|
79
|
+
*
|
|
80
|
+
* Everything else is not evidence. In particular an options object whose
|
|
81
|
+
* fields are plain locals — `https.request({ host, path, method: 'GET' })`,
|
|
82
|
+
* benchmarks/corpus/CWE-444/safe/request-default-parser.js — used to be
|
|
83
|
+
* reported unconditionally because a non-Identifier argument bypassed the
|
|
84
|
+
* name gate entirely.
|
|
85
|
+
*/
|
|
86
|
+
function carriesUntrustedUrl(node) {
|
|
87
|
+
switch (node.type) {
|
|
88
|
+
case eslint_devkit_1.AST_NODE_TYPES.Identifier:
|
|
89
|
+
return isUserInputParamName(node.name);
|
|
90
|
+
case eslint_devkit_1.AST_NODE_TYPES.MemberExpression:
|
|
91
|
+
return isRequestSourced(node);
|
|
92
|
+
case eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral:
|
|
93
|
+
return node.expressions.some(carriesUntrustedUrl);
|
|
94
|
+
// `new URL(userUrl)` / `String(req.query.url)` — inspect the arguments.
|
|
95
|
+
case eslint_devkit_1.AST_NODE_TYPES.CallExpression:
|
|
96
|
+
case eslint_devkit_1.AST_NODE_TYPES.NewExpression:
|
|
97
|
+
return node.arguments.some(carriesUntrustedUrl);
|
|
98
|
+
// `'https://host' + userPath`
|
|
99
|
+
case eslint_devkit_1.AST_NODE_TYPES.BinaryExpression:
|
|
100
|
+
return carriesUntrustedUrl(node.left) || carriesUntrustedUrl(node.right);
|
|
101
|
+
// `http.request({ url: x, host: y })` — only URL-naming keys count by
|
|
102
|
+
// name; every other key still counts if its value is request-sourced.
|
|
103
|
+
case eslint_devkit_1.AST_NODE_TYPES.ObjectExpression:
|
|
104
|
+
return node.properties.some(property => {
|
|
105
|
+
if (property.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
|
|
106
|
+
return false;
|
|
107
|
+
const value = property.value;
|
|
108
|
+
if (isRequestSourced(value))
|
|
109
|
+
return true;
|
|
110
|
+
const key = property.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
|
|
111
|
+
? property.key.name
|
|
112
|
+
: property.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal
|
|
113
|
+
? String(property.key.value)
|
|
114
|
+
: '';
|
|
115
|
+
return URL_OPTION_KEYS.has(key.toLowerCase()) && carriesUntrustedUrl(value);
|
|
116
|
+
});
|
|
117
|
+
default:
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
43
121
|
/**
|
|
44
122
|
* AST-based check: does this node contain a validation pattern?
|
|
45
123
|
* Walks the node tree looking for known validation constructs.
|
|
@@ -139,7 +217,7 @@ exports.noSsrf = (0, eslint_devkit_1.createRule)({
|
|
|
139
217
|
type: 'suggestion',
|
|
140
218
|
docs: {
|
|
141
219
|
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-node-security/docs/rules/no-ssrf.md',
|
|
142
|
-
description: 'Flags HTTP calls whose URL argument is
|
|
220
|
+
description: 'Flags HTTP calls whose URL argument is a user-input-named identifier or reads off a request object — a heuristic prompt for code review, not a proof of SSRF',
|
|
143
221
|
cwe: 'CWE-918',
|
|
144
222
|
cvss: 9.1,
|
|
145
223
|
},
|
|
@@ -196,26 +274,17 @@ exports.noSsrf = (0, eslint_devkit_1.createRule)({
|
|
|
196
274
|
const urlArg = node.arguments[0];
|
|
197
275
|
if (!urlArg)
|
|
198
276
|
return;
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
return;
|
|
202
|
-
// Safe: template literal without expressions — fetch(`https://api.example.com`)
|
|
203
|
-
if (urlArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral &&
|
|
204
|
-
urlArg.expressions.length === 0) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
// The URL is dynamic (identifier, template with expressions, etc.)
|
|
277
|
+
// Static URLs — fetch('https://api.example.com'), fetch(`https://…`) —
|
|
278
|
+
// carry nothing untrusted and fall out at the evidence gate below.
|
|
208
279
|
// Check if there is URL validation before this call
|
|
209
280
|
if (hasValidationBefore(node)) {
|
|
210
281
|
return;
|
|
211
282
|
}
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
283
|
+
// Require evidence that untrusted data reaches the URL. Applies to
|
|
284
|
+
// every argument shape — an options object or a template literal used
|
|
285
|
+
// to bypass this gate entirely and report unconditionally.
|
|
286
|
+
if (!carriesUntrustedUrl(urlArg)) {
|
|
287
|
+
return;
|
|
219
288
|
}
|
|
220
289
|
context.report({
|
|
221
290
|
node,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/rules/no-ssrf/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAaH,4DAKkC;AAWlC,oDAAoD;AACpD,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,OAAO,EAAQ,wBAAwB;IACvC,KAAK,EAAU,MAAM;IACrB,WAAW,EAAI,aAAa;IAC5B,QAAQ,EAAO,SAAS;CACzB,CAAC,CAAC;AAEH,2DAA2D;AAC3D,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS;CACtE,CAAC,CAAC;AAEH,8CAA8C;AAC9C,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/rules/no-ssrf/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAaH,4DAKkC;AAWlC,oDAAoD;AACpD,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,OAAO,EAAQ,wBAAwB;IACvC,KAAK,EAA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CAAC,IAAI,KAAK,8BAAc,CAAC,UAAU;oBACvD,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;oBAChD,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAClD,CAAC;oBACD,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC;gBAED,IAAI,CAAC,UAAU;oBAAE,OAAO;gBAExB,qCAAqC;gBACrC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBACjC,IAAI,CAAC,MAAM;oBAAE,OAAO;gBAEpB,uEAAuE;gBACvE,mEAAmE;gBAEnE,oDAAoD;gBACpD,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC9B,OAAO;gBACT,CAAC;gBAED,mEAAmE;gBACnE,sEAAsE;gBACtE,2DAA2D;gBAC3D,IAAI,CAAC,mBAAmB,CAAC,MAAuB,CAAC,EAAE,CAAC;oBAClD,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,mBAAmB;iBAC/B,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-unsafe-buffer-alloc
|
|
8
|
+
*
|
|
9
|
+
* Detects `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()`, which hand
|
|
10
|
+
* back a buffer over memory that was never zeroed. Until every byte is
|
|
11
|
+
* overwritten the buffer contains whatever the allocator last held there —
|
|
12
|
+
* request bodies, session tokens, private keys. Reading or transmitting it
|
|
13
|
+
* before it is fully written discloses that memory (CVE-2018-7166 is the
|
|
14
|
+
* canonical instance of this class in Node itself).
|
|
15
|
+
*
|
|
16
|
+
* CWE-908: Use of Uninitialized Resource
|
|
17
|
+
* OWASP A01:2021 – Broken Access Control
|
|
18
|
+
*
|
|
19
|
+
* ## Detection method: structural-api
|
|
20
|
+
*
|
|
21
|
+
* Unconditional by design. The rule fires on the AST shape
|
|
22
|
+
* `<Buffer>.allocUnsafe(...)` / `<Buffer>.allocUnsafeSlow(...)` and performs
|
|
23
|
+
* **no dataflow or taint analysis** — it does not attempt to prove whether the
|
|
24
|
+
* buffer is fully overwritten before it is read. Rename every variable in the
|
|
25
|
+
* file and it reports identically.
|
|
26
|
+
*
|
|
27
|
+
* The single structural exemption is a same-expression `.fill()`, e.g.
|
|
28
|
+
* `Buffer.allocUnsafe(n).fill(0)`, which zeroes the allocation on the spot and
|
|
29
|
+
* is therefore equivalent to `Buffer.alloc(n)`. That is a parent-node check,
|
|
30
|
+
* not variable tracking.
|
|
31
|
+
*
|
|
32
|
+
* Consequence: a correct `allocUnsafe` immediately overwritten through a
|
|
33
|
+
* variable (`const b = Buffer.allocUnsafe(n); src.copy(b);`) is still reported.
|
|
34
|
+
* That is the documented false-positive profile and the reason the rule ships
|
|
35
|
+
* as `warn` rather than `error` in `recommended`. The complementary CWE-126
|
|
36
|
+
* read-side analysis lives in `no-buffer-overread`.
|
|
37
|
+
*
|
|
38
|
+
* @see https://cwe.mitre.org/data/definitions/908.html
|
|
39
|
+
* @see https://nodejs.org/api/buffer.html#static-method-bufferallocunsafesize
|
|
40
|
+
* @see https://nvd.nist.gov/vuln/detail/CVE-2018-7166
|
|
41
|
+
*/
|
|
42
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
43
|
+
type MessageIds = 'unsafeAlloc' | 'unsafeAllocSlow' | 'useSafeAlloc';
|
|
44
|
+
export declare const noUnsafeBufferAlloc: TSESLint.RuleModule<MessageIds, [], unknown, TSESLint.RuleListener> & {
|
|
45
|
+
name: string;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noUnsafeBufferAlloc = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
/** The two uninitialized-memory allocators on `Buffer`. */
|
|
11
|
+
const UNSAFE_ALLOCATORS = new Set(['allocUnsafe', 'allocUnsafeSlow']);
|
|
12
|
+
exports.noUnsafeBufferAlloc = (0, eslint_devkit_1.createRule)({
|
|
13
|
+
name: 'no-unsafe-buffer-alloc',
|
|
14
|
+
meta: {
|
|
15
|
+
type: 'problem',
|
|
16
|
+
hasSuggestions: true,
|
|
17
|
+
docs: {
|
|
18
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-node-security/docs/rules/no-unsafe-buffer-alloc.md',
|
|
19
|
+
description: 'Disallow `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()`, which return uninitialized memory',
|
|
20
|
+
cwe: 'CWE-908',
|
|
21
|
+
cweJustification: 'CWE-908 (Use of Uninitialized Resource) — allocUnsafe returns a view over non-zeroed heap memory; any byte not overwritten before the buffer is read or transmitted discloses prior process memory.',
|
|
22
|
+
cvss: 7.5,
|
|
23
|
+
confidence: 'high',
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
unsafeAlloc: (0, eslint_devkit_1.formatLLMMessage)({
|
|
27
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
28
|
+
issueName: 'Uninitialized Buffer Allocation',
|
|
29
|
+
cwe: 'CWE-908',
|
|
30
|
+
cvss: 7.5,
|
|
31
|
+
description: '`Buffer.allocUnsafe(size)` returns memory that has not been zeroed. Every byte not overwritten before the buffer is read or sent leaks whatever the allocator previously stored there.',
|
|
32
|
+
severity: 'HIGH',
|
|
33
|
+
fix: 'Use `Buffer.alloc(size)` (zero-filled), or keep `allocUnsafe` only where the very next statement overwrites the whole buffer — `Buffer.allocUnsafe(size).fill(0)` is accepted by this rule.',
|
|
34
|
+
documentationLink: 'https://nodejs.org/api/buffer.html#static-method-bufferallocunsafesize',
|
|
35
|
+
}),
|
|
36
|
+
unsafeAllocSlow: (0, eslint_devkit_1.formatLLMMessage)({
|
|
37
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
38
|
+
issueName: 'Uninitialized Buffer Allocation (allocUnsafeSlow)',
|
|
39
|
+
cwe: 'CWE-908',
|
|
40
|
+
cvss: 7.5,
|
|
41
|
+
description: '`Buffer.allocUnsafeSlow(size)` allocates outside the shared pool but is equally uninitialized — the returned bytes are whatever was last in that memory.',
|
|
42
|
+
severity: 'HIGH',
|
|
43
|
+
fix: 'Use `Buffer.alloc(size)`, or append `.fill(0)` to zero the allocation at the call site.',
|
|
44
|
+
documentationLink: 'https://nodejs.org/api/buffer.html#static-method-bufferallocunsafeslowsize',
|
|
45
|
+
}),
|
|
46
|
+
useSafeAlloc: 'Replace with `Buffer.alloc()` (zero-filled).',
|
|
47
|
+
},
|
|
48
|
+
schema: [],
|
|
49
|
+
},
|
|
50
|
+
defaultOptions: [],
|
|
51
|
+
create(context) {
|
|
52
|
+
/**
|
|
53
|
+
* True when the call's result is immediately zeroed in the same
|
|
54
|
+
* expression: `Buffer.allocUnsafe(n).fill(0)`. Parent-node shape only.
|
|
55
|
+
*/
|
|
56
|
+
function isFilledInPlace(node) {
|
|
57
|
+
const parent = node.parent;
|
|
58
|
+
if (parent?.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
59
|
+
parent.object !== node ||
|
|
60
|
+
parent.computed ||
|
|
61
|
+
parent.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
62
|
+
parent.property.name !== 'fill') {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
// `.fill` must actually be invoked — `f(buf.fill)` passes the method
|
|
66
|
+
// around, it does not zero anything.
|
|
67
|
+
const grandparent = parent.parent;
|
|
68
|
+
return (grandparent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
|
|
69
|
+
grandparent.callee === parent);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
CallExpression(node) {
|
|
73
|
+
const callee = node.callee;
|
|
74
|
+
if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
75
|
+
callee.computed ||
|
|
76
|
+
callee.object.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
77
|
+
callee.object.name !== 'Buffer' ||
|
|
78
|
+
callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
79
|
+
!UNSAFE_ALLOCATORS.has(callee.property.name)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (isFilledInPlace(node))
|
|
83
|
+
return;
|
|
84
|
+
context.report({
|
|
85
|
+
node,
|
|
86
|
+
messageId: callee.property.name === 'allocUnsafe'
|
|
87
|
+
? 'unsafeAlloc'
|
|
88
|
+
: 'unsafeAllocSlow',
|
|
89
|
+
suggest: [
|
|
90
|
+
{
|
|
91
|
+
messageId: 'useSafeAlloc',
|
|
92
|
+
fix: (fixer) => fixer.replaceText(callee.property, 'alloc'),
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/rules/no-unsafe-buffer-alloc/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;A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AK,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC;yBAC9C;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* MIT license that can be found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
6
|
export interface Options {
|
|
7
|
+
/**
|
|
8
|
+
* Extra property-name fragments (case-insensitive substrings) to treat as
|
|
9
|
+
* sensitive, on top of the built-in list. Default: []
|
|
10
|
+
*/
|
|
11
|
+
additionalSensitiveProperties?: string[];
|
|
7
12
|
}
|
|
8
13
|
type RuleOptions = [Options?];
|
|
9
14
|
export declare const requireSecureDeletion: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
@@ -12,6 +12,26 @@ exports.requireSecureDeletion = void 0;
|
|
|
12
12
|
* @see https://cwe.mitre.org/data/definitions/459.html
|
|
13
13
|
*/
|
|
14
14
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
15
|
+
/**
|
|
16
|
+
* Property-name fragments that mark a value as a secret whose lifetime matters.
|
|
17
|
+
*
|
|
18
|
+
* `delete` unbinds a property; it does not scrub the string, and every other
|
|
19
|
+
* reference (a spread copy, a log line, an already-serialised response body)
|
|
20
|
+
* keeps the value alive. That is the CWE-459 "incomplete cleanup" this rule is
|
|
21
|
+
* about — and it only means anything when the property actually held a secret.
|
|
22
|
+
*
|
|
23
|
+
* Matching is on the property NAME, deliberately: the value at a `delete` site
|
|
24
|
+
* is not available to a syntactic rule, so the name is the only signal there
|
|
25
|
+
* is. The cost of that is bounded by keeping this list narrow.
|
|
26
|
+
*/
|
|
27
|
+
const SENSITIVE_PROPERTY_FRAGMENTS = [
|
|
28
|
+
'password', 'passwd', 'pwd', 'passphrase',
|
|
29
|
+
'secret', 'apikey', 'api_key',
|
|
30
|
+
'token', 'jwt', 'bearer',
|
|
31
|
+
'credential', 'privatekey', 'private_key', 'signingkey', 'signing_key',
|
|
32
|
+
'sessionid', 'session_id', 'refreshtoken', 'refresh_token',
|
|
33
|
+
'ssn', 'creditcard', 'credit_card', 'cardnumber', 'card_number', 'cvv',
|
|
34
|
+
];
|
|
15
35
|
exports.requireSecureDeletion = (0, eslint_devkit_1.createRule)({
|
|
16
36
|
name: 'require-secure-deletion',
|
|
17
37
|
meta: {
|
|
@@ -25,23 +45,65 @@ exports.requireSecureDeletion = (0, eslint_devkit_1.createRule)({
|
|
|
25
45
|
messages: {
|
|
26
46
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
27
47
|
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
28
|
-
issueName: '
|
|
48
|
+
issueName: 'Incomplete Secret Cleanup',
|
|
29
49
|
cwe: 'CWE-459',
|
|
30
|
-
description: '
|
|
50
|
+
description: '`delete` on the sensitive property `{{property}}` unbinds it without scrubbing the value',
|
|
31
51
|
severity: 'MEDIUM',
|
|
32
|
-
fix: '
|
|
52
|
+
fix: 'Overwrite the value before deleting it (obj.{{property}} = undefined, or zero-fill the Buffer), and make sure no copy of the object was spread, logged, or serialised first',
|
|
33
53
|
documentationLink: 'https://cwe.mitre.org/data/definitions/459.html',
|
|
34
54
|
})
|
|
35
55
|
},
|
|
36
|
-
schema: [
|
|
56
|
+
schema: [
|
|
57
|
+
{
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
additionalSensitiveProperties: {
|
|
61
|
+
type: 'array',
|
|
62
|
+
items: { type: 'string' },
|
|
63
|
+
default: [],
|
|
64
|
+
description: 'Extra property-name fragments to treat as sensitive',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
additionalProperties: false,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
37
70
|
},
|
|
38
|
-
defaultOptions: [],
|
|
39
|
-
create(context) {
|
|
71
|
+
defaultOptions: [{ additionalSensitiveProperties: [] }],
|
|
72
|
+
create(context, [options = {}]) {
|
|
73
|
+
const { additionalSensitiveProperties = [] } = options;
|
|
74
|
+
const fragments = [
|
|
75
|
+
...SENSITIVE_PROPERTY_FRAGMENTS,
|
|
76
|
+
...additionalSensitiveProperties.map((f) => f.toLowerCase()),
|
|
77
|
+
];
|
|
78
|
+
/** The property name being deleted, or undefined if it isn't statically known. */
|
|
79
|
+
function deletedPropertyName(node) {
|
|
80
|
+
// `delete obj?.password` wraps the member expression in a ChainExpression.
|
|
81
|
+
const argument = node.type === 'ChainExpression' ? node.expression : node;
|
|
82
|
+
if (argument.type !== 'MemberExpression')
|
|
83
|
+
return undefined;
|
|
84
|
+
const property = argument.property;
|
|
85
|
+
if (!argument.computed && property.type === 'Identifier')
|
|
86
|
+
return property.name;
|
|
87
|
+
if (argument.computed && property.type === 'Literal' && typeof property.value === 'string') {
|
|
88
|
+
return property.value;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
40
92
|
return {
|
|
41
93
|
UnaryExpression(node) {
|
|
42
|
-
if (node.operator
|
|
43
|
-
|
|
44
|
-
|
|
94
|
+
if (node.operator !== 'delete')
|
|
95
|
+
return;
|
|
96
|
+
// Only a `delete` of a *named, statically known, sensitive* property is
|
|
97
|
+
// reportable. Firing on every `delete obj.prop` produced 120 findings
|
|
98
|
+
// on a 1,470-file corpus with no security content whatsoever — the rule
|
|
99
|
+
// was a `delete` detector, not a secret-cleanup detector.
|
|
100
|
+
const property = deletedPropertyName(node.argument);
|
|
101
|
+
if (!property)
|
|
102
|
+
return;
|
|
103
|
+
const normalized = property.toLowerCase().replace(/[^a-z0-9_]/g, '');
|
|
104
|
+
if (!fragments.some((fragment) => normalized.includes(fragment)))
|
|
105
|
+
return;
|
|
106
|
+
context.report({ node, messageId: 'violationDetected', data: { property } });
|
|
45
107
|
},
|
|
46
108
|
};
|
|
47
109
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/rules/require-secure-deletion/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH;;;;GAIG;AAEH,4DAAsF;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/rules/require-secure-deletion/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH;;;;GAIG;AAEH,4DAAsF;AAetF;;;;;;;;;;;GAWG;AACH,MAAM,4BAA4B,GAAG;IACnC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY;IACzC,QAAQ,EAAE,QAAQ,EAAE,SAAS;IAC7B,OAAO,EAAE,KAAK,EAAE,QAAQ;IACxB,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa;IACtE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe;IAC1D,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK;CACvE,CAAC;AAEW,QAAA,qBAAqB,GAAG,IAAA,0BAAU,EAA0B;IACvE,IAAI,EAAE,yBAAyB;IAC/B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,GAAG,EAAE,4HAA4H;YACjI,WAAW,EAAE,uCAAuC;YACpD,GAAG,EAAE,SAAS;YACd,IAAI,EAAE,CAAC;SACR;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,IAAA,gCAAgB,EAAC;gBAClC,IAAI,EAAE,4BAAY,CAAC,QAAQ;gBAC3B,SAAS,EAAE,2BAA2B;gBACtC,GAAG,EAAE,SAAS;gBACd,WAAW,EAAE,0FAA0F;gBACvG,QAAQ,EAAE,QAAQ;gBAClB,GAAG,EAAE,6KAA6K;gBAClL,iBAAiB,EAAE,iDAAiD;aACrE,CAAC;SACH;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,6BAA6B,EAAE;wBAC7B,IAAI,EAAE,O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