eslint-plugin-secure-coding 3.2.0 → 3.3.1

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +78 -37
  3. package/package.json +7 -3
  4. package/src/index.js +34 -9
  5. package/src/rules/detect-object-injection/index.js +178 -6
  6. package/src/rules/detect-weak-password-validation/index.js +2 -2
  7. package/src/rules/no-directive-injection/index.js +0 -1
  8. package/src/rules/no-electron-security-issues/index.js +0 -1
  9. package/src/rules/no-graphql-injection/index.js +0 -1
  10. package/src/rules/no-hardcoded-credentials/index.js +24 -2
  11. package/src/rules/no-hardcoded-session-tokens/index.js +1 -1
  12. package/src/rules/no-improper-sanitization/index.js +0 -1
  13. package/src/rules/no-improper-type-validation/index.js +0 -1
  14. package/src/rules/no-insecure-comparison/index.js +2 -2
  15. package/src/rules/no-ldap-injection/index.js +0 -1
  16. package/src/rules/no-missing-authentication/index.js +1 -1
  17. package/src/rules/no-pii-in-logs/index.js +1 -1
  18. package/src/rules/no-privilege-escalation/index.js +1 -1
  19. package/src/rules/no-sensitive-data-exposure/index.js +2 -2
  20. package/src/rules/no-template-injection/index.d.ts +23 -0
  21. package/src/rules/no-template-injection/index.js +90 -0
  22. package/src/rules/no-unchecked-loop-condition/index.js +0 -1
  23. package/src/rules/no-unlimited-resource-allocation/index.js +37 -22
  24. package/src/rules/no-unsafe-deserialization/index.js +15 -0
  25. package/src/rules/no-weak-password-recovery/index.js +0 -1
  26. package/src/rules/no-xpath-injection/index.js +0 -1
  27. package/src/rules/no-xxe-injection/index.js +1 -1
  28. package/src/rules/require-backend-authorization/index.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,118 @@
1
+ ## 3.3.1
2
+
3
+ ### Patch Changes
4
+
5
+ - [#213](https://github.com/ofri-peretz/eslint/pull/213) [`391dbe6`](https://github.com/ofri-peretz/eslint/commit/391dbe6b39f78d549379218567cb959649f8c614) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Align every security rule's `meta.docs.cvss` to the CVSS its finding actually
6
+ emits. The emitted machine-readable message sources its `CVSS:x` from
7
+ `CWE_MAPPING` via `formatLLMMessage` → `enrichFromCWE`, but the static
8
+ `meta.docs.cvss` documentation field had drifted on 45 rules across these 7
9
+ plugins — e.g. `no-hardcoded-credentials` documented `9.5` while emitting
10
+ `CVSS:9.8` (the value the published article and SARIF/LLM consumers already
11
+ read).
12
+
13
+ This corrects the **documentation metadata only** — no emitted finding changes.
14
+ Locked by `security-cvss-docs-consistency.lock.test.ts` (cross-plugin: every
15
+ security rule's `meta.docs.cvss` must equal the CVSS it emits), the
16
+ `no-hardcoded-credentials` rule lock (real ESLint `Linter` emission), and a
17
+ devkit `enrichFromCWE` contract test pinning `CWE-798 → 9.8`.
18
+
19
+ Follow-up (not in scope): 50 security rules document a CVSS that never appears
20
+ in any emitted message (their messages carry no CWE), and several rules emit the
21
+ generic CWE score where a rule-specific score may be warranted — both change
22
+ emitted output and are separate decisions.
23
+
24
+ ## 3.3.0
25
+
26
+ ### Minor Changes
27
+
28
+ - [#170](https://github.com/ofri-peretz/eslint/pull/170) [`4cbf3ed`](https://github.com/ofri-peretz/eslint/commit/4cbf3ed8aed113f6aed7cef3a2ed060601b927ce) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Add `recommended-strict` preset + quick-start in README
29
+
30
+ **New preset: `configs['recommended-strict']`**
31
+ Same 16-rule set as `recommended` but every rule promoted to `'error'`.
32
+ For teams that want CI to block on all security findings, not just
33
+ critical ones. The recommended preset stays unchanged.
34
+
35
+ ```js
36
+ // eslint.config.mjs
37
+ import securePlugin from 'eslint-plugin-secure-coding';
38
+ export default [...securePlugin.configs['recommended-strict']];
39
+ ```
40
+
41
+ **README: copy-paste quick-start block**
42
+ Added a one-line usage example immediately after `npm install` so adopters
43
+ don't have to discover the preset table buried further down the page.
44
+ Also added cross-plugin discovery links to `node-security`, `jwt`, and
45
+ `express-security` for teams that want broader coverage.
46
+
47
+ ### Patch Changes
48
+
49
+ - [#137](https://github.com/ofri-peretz/eslint/pull/137) [`a56da52`](https://github.com/ofri-peretz/eslint/commit/a56da525d90d233310c5329fdd006af5b3fd675c) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - fix(detect-object-injection): suppress ~3,470 Edge false positives via four new safe-pattern guards
50
+ - Test-file skip: rule is now silent on `*.test.*`, `*.spec.*`, `__tests__/`, and `*.fixture.*` paths
51
+ - `for...in` loop variable: keys from `for (const key in obj)` are own property names, not user input
52
+ - `Object.keys/entries` iteration: `for (const key of Object.keys(obj))` is safe by construction
53
+ - Typed-array objects (`new Float32Array/Uint8Array/Int32Array/…`): element access is numeric, not string-keyed
54
+
55
+ None of the guards widen the TP surface — dangerous properties (`__proto__`, `constructor`, `prototype`) and genuine user-input bracket access still fire. Closes the largest single source of ILB-Wild noise.
56
+
57
+ - [#144](https://github.com/ofri-peretz/eslint/pull/144) [`8843ce7`](https://github.com/ofri-peretz/eslint/commit/8843ce7fbb465caad161b97032467b3a37a49319) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - fix: ILB-Wild FP reduction + doc examples + doc-test-alignment scanner fixes
58
+
59
+ **`no-unlimited-resource-allocation` — FP reduction (430 Edge FPs)**
60
+ - Skip loop-allocation reporting when the first argument is a numeric literal (e.g. `Buffer.alloc(1024)` inside a loop is statically bounded, not a risk)
61
+ - Skip `Array.isArray`, `Array.from`, `Array.of` calls in the `alloc/Array` pattern check (these don't allocate unbounded memory)
62
+
63
+ **`no-hardcoded-credentials` — FP reduction (~280 Edge FPs)**
64
+ - Extended test-file skip to cover `.fixture.`, `.mock.`, `__mocks__/`, `/tests/`, `/fixtures/`, `/mocks/` paths
65
+ - Skip string literals that are fallback values in `process.env.X || 'fallback'` expressions — the secret lives in the environment, the string is only a dev-mode default
66
+
67
+ **Doc examples — 4 rules now have ❌ Incorrect examples**
68
+ - `lambda-security/no-missing-authorization-check`
69
+ - `lambda-security/no-overly-permissive-iam-policy`
70
+ - `node-security/prefer-native-crypto` (renamed non-standard `### ❌ Third-Party (Flagged)` to `### ❌ Incorrect`)
71
+ - `vercel-ai-security/require-tool-confirmation` (replaced placeholder with a real tested example)
72
+
73
+ **`ilb-doc-test-alignment` scanner fixes**
74
+ - Accept both `## ❌` and `### ❌` headings (docs use H3 under an H2 `## Examples` section; was only finding H2)
75
+ - Slice from end-of-line rather than end-of-regex-match (prevents `## ❌ Incorrect Code` from leaving a partial heading in the parsed section)
76
+
77
+ Result: `ilb:doc-test-alignment` → 206 ok, 0 doc has no ❌ examples (was 165 missing).
78
+
79
+ - [#141](https://github.com/ofri-peretz/eslint/pull/141) [`38ab670`](https://github.com/ofri-peretz/eslint/commit/38ab670a0221684f4fd3d5dc3c05ddec7458ca2b) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - fix: remove false `meta.fixable: 'code'` declarations from 21 rules that had no `fix()` function
80
+
81
+ Rules that declared `fixable: 'code'` in their ESLint meta without an actual `fix()` implementation would show the ⚡ auto-fix icon in editors and CI formatters but apply no change when `--fix` was run. This patch removes the misleading declaration from:
82
+ - `browser-security/no-clickjacking`
83
+ - `import-next/first`, `named`, `no-barrel-import`, `no-import-module-exports`, `no-namespace`
84
+ - `node-security/no-buffer-overread`, `no-unsafe-dynamic-require`, `no-zip-slip`
85
+ - `react-features/react-no-inline-functions`
86
+ - `reliability/no-jsdoc-terminator-in-example` (uses `suggest`, not auto-fix; corrected to `hasSuggestions: true` only)
87
+ - `secure-coding/no-directive-injection`, `no-electron-security-issues`, `no-graphql-injection`, `no-improper-sanitization`, `no-improper-type-validation`, `no-ldap-injection`, `no-unchecked-loop-condition`, `no-unlimited-resource-allocation`, `no-weak-password-recovery`, `no-xpath-injection`
88
+
89
+ - [#148](https://github.com/ofri-peretz/eslint/pull/148) [`82718c2`](https://github.com/ofri-peretz/eslint/commit/82718c282895710d42c36d4679fb24d47f1c35c7) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - feat+fix: ILB-Wild FP reduction + two new quality rules
90
+
91
+ **`no-unsafe-deserialization` FP reduction (~112 FPs)**
92
+ - Track `fs.readFileSync('literal')` calls in `literalPathFileVars` — a file read with a
93
+ hardcoded path (bundled config) is not user-controlled input for safe deserializers
94
+ (`JSON.parse`, schema-validating parsers). `eval()` still fires even on literal-path reads.
95
+
96
+ **`no-buffer-overread` FP reduction (~129 FPs)**
97
+ - Remove `b` (single-char, too broad) and `chunk` (too common for array chunks) from the
98
+ Buffer alias heuristic — `isBufferType` now only matches `buf` and `bytes` by name,
99
+ reducing false matches on non-Buffer variables.
100
+
101
+ **New rule: `modernization/prefer-template-literal`**
102
+ - Flags `"string " + variable` concatenation and suggests the equivalent template literal.
103
+ - Auto-fix produces the correct `` `string ${variable}` `` replacement.
104
+ - Pure string literal chains (`"a" + "b"`) and numeric addition are not flagged.
105
+ - Closes P2 quality FN `prob_string_concat` in the ILB-Arena-Quality bench.
106
+
107
+ **New rule: `modularity/no-mutable-exports`**
108
+ - Flags `export let` and `export var` — module exports should be immutable `const`
109
+ bindings so all importers share a stable reference.
110
+ - Auto-fix replaces `let`/`var` with `const`.
111
+ - Closes P2 quality FN `prob_mutable_export` in the ILB-Arena-Quality bench.
112
+
113
+ - Updated dependencies [[`736a5fe`](https://github.com/ofri-peretz/eslint/commit/736a5fed47e673f6157ea900b29fe2a54e4bc7df)]:
114
+ - @interlace/eslint-devkit@1.4.1
115
+
1
116
  ## 3.2.0 (Unreleased)
2
117
 
3
118
  ### Added
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <a href="https://eslint.interlace.tools" target="blank"><img src="https://eslint.interlace.tools/eslint-interlace-logo-light.svg" alt="ESLint Interlace Logo" width="120" /></a>
2
+ <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding" target="blank"><img src="https://eslint.interlace.tools/eslint-interlace-logo-light.svg" alt="ESLint Interlace Logo" width="120" /></a>
3
3
  </p>
4
4
 
5
5
  <p align="center">
@@ -14,6 +14,8 @@
14
14
  <a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
15
15
  </p>
16
16
 
17
+ > ⭐ If this plugin caught a real bug for you, [**star the repo**](https://github.com/ofri-peretz/eslint) — it's the signal that keeps these rules maintained.
18
+
17
19
  ## Description
18
20
 
19
21
  This plugin provides General secure coding practices and OWASP compliance for JavaScript/TypeScript.
@@ -24,17 +26,46 @@ This plugin provides General secure coding practices and OWASP compliance for Ja
24
26
 
25
27
  ## Getting Started
26
28
 
27
- - To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-secure-coding), visit [eslint.interlace.tools](https://eslint.interlace.tools). 📚
28
- - 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-secure-coding), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools). 📚
29
- - [가이드](https://eslint.interlace.tools/docs/security/plugin-secure-coding) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools)에서 확인하실 수 있습니다. 📚
30
- - [ガイド](https://eslint.interlace.tools/docs/security/plugin-secure-coding)は [eslint.interlace.tools](https://eslint.interlace.tools)でご確認ください。 📚
31
- - Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-secure-coding), visita [eslint.interlace.tools](https://eslint.interlace.tools). 📚
32
- - للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-secure-coding)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools). 📚
29
+ - To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding). 📚
30
+ - 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding). 📚
31
+ - [가이드](https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding)에서 확인하실 수 있습니다. 📚
32
+ - [ガイド](https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding)は [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding)でご確認ください。 📚
33
+ - Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding), visita [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding). 📚
34
+ - للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding). 📚
33
35
 
34
36
  ```bash
35
37
  npm install eslint-plugin-secure-coding --save-dev
36
38
  ```
37
39
 
40
+ **Add to your `eslint.config.mjs` — one line activates 16 security rules:**
41
+
42
+ ```js
43
+ import securePlugin from 'eslint-plugin-secure-coding';
44
+
45
+ export default [
46
+ // Balanced: catches critical issues as errors, lower-confidence rules as warnings
47
+ ...securePlugin.configs.recommended,
48
+
49
+ // Zero-tolerance: same 16 rules, all promoted to error (good for CI gates)
50
+ // ...securePlugin.configs['recommended-strict'],
51
+ ];
52
+ ```
53
+
54
+ **Or if you use a legacy `.eslintrc.json`:**
55
+
56
+ ```json
57
+ {
58
+ "extends": ["plugin:secure-coding/recommended"]
59
+ }
60
+ ```
61
+
62
+ > **Using `recommended` already?** Extend your coverage with domain-specific plugins:
63
+ > [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) (crypto, eval, buffer) ·
64
+ > [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) (JWT auth) ·
65
+ > [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) (Express middleware)
66
+
67
+ ---
68
+
38
69
  ## Benchmarks vs competitors (CWE-798 ground truth)
39
70
  `no-hardcoded-credentials` is part of the [ILB-Flagship benchmark suite](../../benchmarks/suites/ilb-flagship). On the labeled CWE-798 fixture set (Juliet-style: 2 vulnerable + 2 safe files, ground-truthed):
40
71
 
@@ -50,8 +81,9 @@ The competitor's entropy-only detection catches the high-entropy API-key shape b
50
81
  ## ⚙️ Configuration Presets
51
82
  | Preset | Description |
52
83
  | :-------------------- | :-------------------------------------------------------------- |
53
- | `recommended` | Balanced security for most projects (Web + key Mobile security) |
54
- | `strict` | Maximum security enforcement (all rules as errors) |
84
+ | `recommended` | 16 core rules — critical issues as `error`, lower-confidence as `warn` |
85
+ | `recommended-strict` | Same 16 rules as `recommended`, all promoted to `error` — for CI gates |
86
+ | `strict` | All rules as `error` — maximum coverage including experimental rules |
55
87
  | `owasp-top-10` | OWASP Top 10 Web 2021 compliance focused |
56
88
  | `owasp-mobile-top-10` | OWASP Mobile Top 10 2024 compliance focused |
57
89
 
@@ -83,33 +115,33 @@ See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md)
83
115
  <!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
84
116
  | Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
85
117
  | :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
86
- | [detect-non-literal-regexp](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/detect-non-literal-regexp) | CWE-400 | | | Detects RegExp(variable), which might allow an attacker to DOS your server with a long-running regular expr… | 🟢 | | | | | |
87
- | [detect-object-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/detect-object-injection) | CWE-915 | | | Detects variable[key] as a left- or right-hand assignment operand (prototype pollution) | 🟡 | | | | | |
88
- | [detect-weak-password-validation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/detect-weak-password-validation) | CWE-521 | A07:2021 | | Detects weak password length requirements (less than 8 characters) in validation code. | 🟢 | | | | | |
89
- | [no-directive-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-directive-injection) | CWE-94 | | | Detects directive injection vulnerabilities in template systems | 🟢 | | | | | |
90
- | [no-electron-security-issues](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-electron-security-issues) | CWE-16 | | | Detects Electron security vulnerabilities and insecure configurations | 🟢 | | | | | |
91
- | [no-format-string-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-format-string-injection) | CWE-134 | | | Detects format string injection vulnerabilities | 🟢 | | | | | |
92
- | [no-graphql-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-graphql-injection) | CWE-943 | | | Detects GraphQL injection vulnerabilities and DoS attacks | 🟢 | 💼 | | | | |
93
- | [no-hardcoded-credentials](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-hardcoded-credentials) | CWE-798 | | | Detects hardcoded passwords, API keys, tokens, and other sensitive credentials in source code | 🟢 | 💼 | | | | |
94
- | [no-hardcoded-session-tokens](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-hardcoded-session-tokens) | CWE-798 | | | This rule detects hardcoded JWT tokens (starting with eyJ), Bearer tokens, and session identifiers | 🟢 | | | | | |
95
- | [no-improper-sanitization](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-improper-sanitization) | CWE-116 | | | Detects improper sanitization of user input | 🟢 | | | | | |
96
- | [no-improper-type-validation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-improper-type-validation) | CWE-1287 | | | Detects improper type validation in user input handling | 🟢 | 💼 | | | | |
97
- | [no-insecure-comparison](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-insecure-comparison) | CWE-697 | | | Detects insecure comparison operators (==, !=) that can lead to type coercion vulnerabilities | 🟢 | 💼 | | | | |
98
- | [no-ldap-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-ldap-injection) | CWE-90 | | | Detects LDAP injection vulnerabilities | 🟢 | 💼 | | | | |
99
- | [no-missing-authentication](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-missing-authentication) | CWE-287 | | | CWE: [CWE-287](https://cwe.mitre.org/data/definitions/287.html) | 🟢 | 💼 | | | | |
100
- | [no-pii-in-logs](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-pii-in-logs) | CWE-359 | | | Prevent personally identifiable information (PII) — emails, SSNs, credit cards, phone numbers — from reachi… | 🟢 | | | | 💡 | |
101
- | [no-privilege-escalation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-privilege-escalation) | CWE-269 | | | Detects potential privilege escalation vulnerabilities where user input is used to assign roles or permissi… | 🟢 | 💼 | | | | |
102
- | [no-redos-vulnerable-regex](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-redos-vulnerable-regex) | CWE-400 | | | ESLint Rule: no-redos-vulnerable-regex | 🟢 | | | | | |
103
- | [no-sensitive-data-exposure](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-sensitive-data-exposure) | CWE-532 | | | ESLint Rule: no-sensitive-data-exposure | 🟢 | 💼 | | | | |
104
- | [no-unchecked-loop-condition](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unchecked-loop-condition) | CWE-400 | | | Detects unchecked loop conditions that could cause DoS | 🟢 | | | | | |
105
- | [no-unlimited-resource-allocation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unlimited-resource-allocation) | CWE-770 | | | Detects unlimited resource allocation that could cause DoS | 🟢 | | | | | |
106
- | [no-unsafe-deserialization](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unsafe-deserialization) | CWE-502 | | | Detects unsafe deserialization of untrusted data | 🟢 | 💼 | | | | |
107
- | [no-unsafe-regex-construction](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unsafe-regex-construction) | CWE-400 | | | ESLint Rule: no-unsafe-regex-construction with LLM-optimized suggestions and auto-fix capabilities | 🟢 | | | | | |
108
- | [no-weak-password-recovery](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-weak-password-recovery) | CWE-640 | | | ESLint Rule: no-weak-password-recovery with LLM-optimized suggestions and auto-fix capabilities | 🟢 | 💼 | | | | |
109
- | [no-xpath-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-xpath-injection) | CWE-643 | | | Detects XPath injection vulnerabilities | 🟢 | 💼 | | | | |
110
- | [no-xxe-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-xxe-injection) | CWE-611 | | | Detects XML External Entity (XXE) injection vulnerabilities | 🟢 | 💼 | | | | |
111
- | [require-backend-authorization](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/require-backend-authorization) | CWE-602 | | | CWE: [CWE-602](https://cwe.mitre.org/data/definitions/602.html) | 🟢 | | | | | |
112
- | [require-secure-defaults](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/require-secure-defaults) | CWE-1188 | | | CWE: [CWE-1188](https://cwe.mitre.org/data/definitions/1188.html) | 🟢 | | | | | |
118
+ | [detect-non-literal-regexp](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/detect-non-literal-regexp?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-400 | | | Detects RegExp(variable), which might allow an attacker to DOS your server with a long-running regular expr… | 🟢 | | | | | |
119
+ | [detect-object-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/detect-object-injection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-915 | | | Detects variable[key] as a left- or right-hand assignment operand (prototype pollution) | 🟡 | | | | | |
120
+ | [detect-weak-password-validation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/detect-weak-password-validation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-521 | A07:2021 | | Detects weak password length requirements (less than 8 characters) in validation code. | 🟢 | | | | | |
121
+ | [no-directive-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-directive-injection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-94 | | | Detects directive injection vulnerabilities in template systems | 🟢 | | | | | |
122
+ | [no-electron-security-issues](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-electron-security-issues?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-16 | | | Detects Electron security vulnerabilities and insecure configurations | 🟢 | | | | | |
123
+ | [no-format-string-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-format-string-injection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-134 | | | Detects format string injection vulnerabilities | 🟢 | | | | | |
124
+ | [no-graphql-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-graphql-injection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-943 | | | Detects GraphQL injection vulnerabilities and DoS attacks | 🟢 | 💼 | | | | |
125
+ | [no-hardcoded-credentials](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-hardcoded-credentials?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-798 | | | Detects hardcoded passwords, API keys, tokens, and other sensitive credentials in source code | 🟢 | 💼 | | | | |
126
+ | [no-hardcoded-session-tokens](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-hardcoded-session-tokens?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-798 | | | This rule detects hardcoded JWT tokens (starting with eyJ), Bearer tokens, and session identifiers | 🟢 | | | | | |
127
+ | [no-improper-sanitization](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-improper-sanitization?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-116 | | | Detects improper sanitization of user input | 🟢 | | | | | |
128
+ | [no-improper-type-validation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-improper-type-validation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-1287 | | | Detects improper type validation in user input handling | 🟢 | 💼 | | | | |
129
+ | [no-insecure-comparison](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-insecure-comparison?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-697 | | | Detects insecure comparison operators (==, !=) that can lead to type coercion vulnerabilities | 🟢 | 💼 | | | | |
130
+ | [no-ldap-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-ldap-injection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-90 | | | Detects LDAP injection vulnerabilities | 🟢 | 💼 | | | | |
131
+ | [no-missing-authentication](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-missing-authentication?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-287 | | | CWE: [CWE-287](https://cwe.mitre.org/data/definitions/287.html) | 🟢 | 💼 | | | | |
132
+ | [no-pii-in-logs](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-pii-in-logs?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-359 | | | Prevent personally identifiable information (PII) — emails, SSNs, credit cards, phone numbers — from reachi… | 🟢 | | | | 💡 | |
133
+ | [no-privilege-escalation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-privilege-escalation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-269 | | | Detects potential privilege escalation vulnerabilities where user input is used to assign roles or permissi… | 🟢 | 💼 | | | | |
134
+ | [no-redos-vulnerable-regex](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-redos-vulnerable-regex?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-400 | | | ESLint Rule: no-redos-vulnerable-regex | 🟢 | | | | | |
135
+ | [no-sensitive-data-exposure](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-sensitive-data-exposure?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-532 | | | ESLint Rule: no-sensitive-data-exposure | 🟢 | 💼 | | | | |
136
+ | [no-unchecked-loop-condition](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unchecked-loop-condition?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-400 | | | Detects unchecked loop conditions that could cause DoS | 🟢 | | | | | |
137
+ | [no-unlimited-resource-allocation](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unlimited-resource-allocation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-770 | | | Detects unlimited resource allocation that could cause DoS | 🟢 | | | | | |
138
+ | [no-unsafe-deserialization](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unsafe-deserialization?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-502 | | | Detects unsafe deserialization of untrusted data | 🟢 | 💼 | | | | |
139
+ | [no-unsafe-regex-construction](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-unsafe-regex-construction?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-400 | | | ESLint Rule: no-unsafe-regex-construction with LLM-optimized suggestions and auto-fix capabilities | 🟢 | | | | | |
140
+ | [no-weak-password-recovery](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-weak-password-recovery?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-640 | | | ESLint Rule: no-weak-password-recovery with LLM-optimized suggestions and auto-fix capabilities | 🟢 | 💼 | | | | |
141
+ | [no-xpath-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-xpath-injection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-643 | | | Detects XPath injection vulnerabilities | 🟢 | 💼 | | | | |
142
+ | [no-xxe-injection](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/no-xxe-injection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-611 | | | Detects XML External Entity (XXE) injection vulnerabilities | 🟢 | 💼 | | | | |
143
+ | [require-backend-authorization](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/require-backend-authorization?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-602 | | | CWE: [CWE-602](https://cwe.mitre.org/data/definitions/602.html) | 🟢 | | | | | |
144
+ | [require-secure-defaults](https://eslint.interlace.tools/docs/security/plugin-secure-coding/rules/require-secure-defaults?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding) | CWE-1188 | | | CWE: [CWE-1188](https://cwe.mitre.org/data/definitions/1188.html) | 🟢 | | | | | |
113
145
  <!-- AUTO-GENERATED:RULES_TABLE:END -->
114
146
  ## 🔗 Related ESLint Plugins
115
147
 
@@ -129,10 +161,19 @@ Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with L
129
161
  | [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-vercel-ai-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security hardening. |
130
162
  | [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-import-next.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-import-next) | Next-gen import sorting & architecture. |
131
163
 
164
+ <!-- INTERLACE:STAR_CTA:START -->
165
+ ## ⭐ Support & follow
166
+
167
+ If this plugin caught a real bug for you, **[star the repo](https://github.com/ofri-peretz/eslint)** — stars are the signal that keeps the Interlace ESLint ecosystem maintained — and **[follow the writeups on Dev.to](https://dev.to/ofri-peretz)** for the benchmarks and security research behind these rules.
168
+
169
+ [![GitHub stars](https://img.shields.io/github/stars/ofri-peretz/eslint?style=social)](https://github.com/ofri-peretz/eslint)
170
+
171
+ <!-- INTERLACE:STAR_CTA:END -->
172
+
132
173
  ## 📄 License
133
174
 
134
175
  MIT © [Ofri Peretz](https://github.com/ofri-peretz)
135
176
 
136
177
  <p align="center">
137
- <a href="https://eslint.interlace.tools/docs/security/plugin-secure-coding"><img src="https://eslint.interlace.tools/images/og-secure-coding.png" alt="ESLint Interlace Plugin" width="100%" /></a>
178
+ <a href="https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding"><img src="https://eslint.interlace.tools/images/og-secure-coding.png" alt="ESLint Interlace Plugin" width="100%" /></a>
138
179
  </p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-secure-coding",
3
- "version": "3.2.0",
3
+ "version": "3.3.1",
4
4
  "description": "Security-focused ESLint plugin with 89 AI-parseable rules for detecting and preventing vulnerabilities. OWASP Top 10 2021 + Mobile Top 10 2024 coverage, CWE references, and AI-assisted fix guidance.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "author": "Ofri Peretz <ofriperetzdev@gmail.com>",
23
23
  "license": "MIT",
24
- "homepage": "https://github.com/ofri-peretz/eslint/tree/main/packages/eslint-plugin-secure-coding#readme",
24
+ "homepage": "https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding",
25
25
  "repository": {
26
26
  "type": "git",
27
27
  "url": "https://github.com/ofri-peretz/eslint",
@@ -81,7 +81,7 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "tslib": "^2.3.0",
84
- "@interlace/eslint-devkit": "^1.2.1",
84
+ "@interlace/eslint-devkit": "^1.4.1",
85
85
  "scslre": "^0.3.0",
86
86
  "@eslint-community/regexpp": "^4.10.0"
87
87
  },
@@ -91,5 +91,9 @@
91
91
  },
92
92
  "peerDependencies": {
93
93
  "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0"
94
+ },
95
+ "funding": {
96
+ "type": "github",
97
+ "url": "https://github.com/ofri-peretz/eslint"
94
98
  }
95
99
  }
package/src/index.js CHANGED
@@ -27,6 +27,7 @@ const no_xpath_injection_1 = require("./rules/no-xpath-injection");
27
27
  const no_ldap_injection_1 = require("./rules/no-ldap-injection");
28
28
  const no_directive_injection_1 = require("./rules/no-directive-injection");
29
29
  const no_format_string_injection_1 = require("./rules/no-format-string-injection");
30
+ const no_template_injection_1 = require("./rules/no-template-injection");
30
31
  // Security rules - Regex
31
32
  const detect_non_literal_regexp_1 = require("./rules/detect-non-literal-regexp");
32
33
  const no_redos_vulnerable_regex_1 = require("./rules/no-redos-vulnerable-regex");
@@ -67,6 +68,7 @@ exports.rules = {
67
68
  'no-ldap-injection': no_ldap_injection_1.noLdapInjection,
68
69
  'no-directive-injection': no_directive_injection_1.noDirectiveInjection,
69
70
  'no-format-string-injection': no_format_string_injection_1.noFormatStringInjection,
71
+ 'no-template-injection': no_template_injection_1.noTemplateInjection,
70
72
  // Regex Safety & Stability (3 rules)
71
73
  'detect-non-literal-regexp': detect_non_literal_regexp_1.detectNonLiteralRegexp,
72
74
  'no-redos-vulnerable-regex': no_redos_vulnerable_regex_1.noRedosVulnerableRegex,
@@ -101,7 +103,7 @@ exports.rules = {
101
103
  exports.plugin = {
102
104
  meta: {
103
105
  name: 'eslint-plugin-secure-coding',
104
- version: '3.2.0',
106
+ version: '3.3.1',
105
107
  },
106
108
  rules: exports.rules,
107
109
  };
@@ -123,19 +125,23 @@ const recommendedRules = {
123
125
  // High - Regex vulnerabilities
124
126
  'secure-coding/detect-non-literal-regexp': 'warn',
125
127
  // Demoted 2026-05-09 — 91% Edge ratio.
126
- 'secure-coding/no-redos-vulnerable-regex': 'warn',
127
- 'secure-coding/no-unsafe-regex-construction': 'warn',
128
+ 'secure-coding/no-redos-vulnerable-regex': 'error',
129
+ 'secure-coding/no-unsafe-regex-construction': 'error',
128
130
  // High - Prototype pollution
129
131
  'secure-coding/detect-object-injection': 'warn',
130
132
  // Critical - Credentials
131
133
  'secure-coding/no-hardcoded-credentials': 'error',
132
134
  'secure-coding/no-insecure-comparison': 'warn',
135
+ // Critical - Template injection
136
+ 'secure-coding/no-template-injection': 'error',
133
137
  // Critical - Data integrity
134
138
  'secure-coding/no-improper-sanitization': 'error',
135
139
  // High - Logic
136
- 'secure-coding/no-missing-authentication': 'warn',
140
+ // NOTE: no-missing-authentication and require-backend-authorization are deprecated in
141
+ // secure-coding — they assume Express route handler context and belong in express-security.
142
+ // Kept in the rules registry for backwards compat; removed from flagship config.
137
143
  'secure-coding/no-privilege-escalation': 'warn',
138
- 'secure-coding/no-weak-password-recovery': 'error',
144
+ 'secure-coding/no-weak-password-recovery': 'warn', // naming heuristic — demoted
139
145
  // High - Exposure
140
146
  'secure-coding/no-sensitive-data-exposure': 'warn',
141
147
  // Medium - Resource & DoS
@@ -172,10 +178,27 @@ exports.configs = {
172
178
  },
173
179
  rules: recommendedRules,
174
180
  },
181
+ /**
182
+ * Recommended-strict configuration
183
+ *
184
+ * Same rule set as `recommended` but every rule is promoted to `'error'`.
185
+ * Use this when you want CI to block on all security findings rather than
186
+ * only warning on lower-confidence rules.
187
+ *
188
+ * This is the configuration independently chosen by production teams who
189
+ * audit `recommended` and decide they want zero tolerance on all 16 rules.
190
+ */
191
+ 'recommended-strict': {
192
+ plugins: {
193
+ 'secure-coding': exports.plugin,
194
+ },
195
+ rules: Object.fromEntries(Object.keys(recommendedRules).map((rule) => [rule, 'error'])),
196
+ },
175
197
  /**
176
198
  * Strict security configuration
177
199
  *
178
- * All security rules set to 'error' for maximum protection.
200
+ * ALL rules (including experimental and opinionated ones) set to 'error'.
201
+ * Prefer `recommended-strict` unless you specifically need full coverage.
179
202
  */
180
203
  strict: {
181
204
  plugins: {
@@ -194,11 +217,13 @@ exports.configs = {
194
217
  },
195
218
  rules: {
196
219
  // A01:2021 – Broken Access Control
197
- 'secure-coding/no-missing-authentication': 'error',
198
- 'secure-coding/no-privilege-escalation': 'error',
220
+ // no-missing-authentication removed: Express-specific, use express-security plugin instead
221
+ 'secure-coding/no-privilege-escalation': 'warn',
199
222
  // A02:2021 – Cryptographic Failures
200
223
  'secure-coding/no-hardcoded-credentials': 'error',
201
- 'secure-coding/no-sensitive-data-exposure': 'error',
224
+ // Demoted from 'error': naming-heuristic detection (fires on variable names
225
+ // that sound sensitive). Cannot be enforcement-grade per I3 invariant.
226
+ 'secure-coding/no-sensitive-data-exposure': 'warn',
202
227
  // A03:2021 – Injection
203
228
  'secure-coding/no-graphql-injection': 'error',
204
229
  'secure-coding/no-xxe-injection': 'error',
@@ -22,6 +22,13 @@ exports.detectObjectInjection = void 0;
22
22
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
23
23
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
24
24
  const eslint_devkit_3 = require("@interlace/eslint-devkit");
25
+ const TYPED_ARRAY_CTORS = new Set([
26
+ 'Int8Array', 'Uint8Array', 'Uint8ClampedArray',
27
+ 'Int16Array', 'Uint16Array',
28
+ 'Int32Array', 'Uint32Array',
29
+ 'Float32Array', 'Float64Array',
30
+ 'BigInt64Array', 'BigUint64Array',
31
+ ]);
25
32
  const OBJECT_INJECTION_PATTERNS = [
26
33
  {
27
34
  pattern: '__proto__',
@@ -220,6 +227,17 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
220
227
  src.startsWith('@typescript-eslint/'));
221
228
  });
222
229
  })();
230
+ // Test-file skip — bracket access in tests is universally safe (fixture data,
231
+ // assertion helpers, mock objects). This closes the largest class of
232
+ // ILB-Wild FPs without any precision loss on real application code.
233
+ const isTestFile = (() => {
234
+ const f = context.filename;
235
+ return (/\.test\.[mc]?[jt]sx?$/.test(f) ||
236
+ /\.spec\.[mc]?[jt]sx?$/.test(f) ||
237
+ /\/__tests__\//.test(f) ||
238
+ /\/test\//.test(f) ||
239
+ /\.fixture\.[mc]?[jt]sx?$/.test(f));
240
+ })();
223
241
  // Check if TypeScript parser services are available for type-aware checking
224
242
  const hasTypeInfo = (0, eslint_devkit_2.hasParserServices)(context);
225
243
  const parserServices = hasTypeInfo ? (0, eslint_devkit_2.getParserServices)(context) : null;
@@ -419,6 +437,24 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
419
437
  return false;
420
438
  }
421
439
  }
440
+ // SAFE: SCREAMING_SNAKE_CASE identifiers are TypeScript module-level constants
441
+ // (e.g. PATH_METADATA, METHOD_METADATA, PARAMTYPES_METADATA, BRANCH_EFFECT).
442
+ // They are compile-time string/symbol values defined in the codebase, never
443
+ // derived from user input — prototype pollution via a constant key is impossible.
444
+ // Pattern: at least 3 chars, ALL_CAPS letters, digits, underscores only.
445
+ if (propertyNode.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
446
+ const name = propertyNode.name;
447
+ if (/^[A-Z][A-Z0-9_]{2,}$/.test(name)) {
448
+ return false;
449
+ }
450
+ // SAFE: camelCase identifiers whose suffix implies a typed/enumerated value.
451
+ // HTTP status codes, version numbers, type discriminants, mode flags — these
452
+ // are never raw user input. Examples: errorHttpStatusCode, uuidVersion, reqType.
453
+ if (/^[a-z]/.test(name) &&
454
+ /(?:Code|Status|Version|Kind|Mode|Type|Stage|Level|Phase|Step|Flag|Num|Count)$/.test(name)) {
455
+ return false;
456
+ }
457
+ }
422
458
  // Check if it's a literal string first
423
459
  if (isLiteralString(propertyNode)) {
424
460
  const propName = String(propertyNode.value);
@@ -539,12 +575,20 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
539
575
  if (isPrototypelessObject(node.left.object)) {
540
576
  return false;
541
577
  }
578
+ // SAFE: typed-array element assignment is numeric, not a string-key injection
579
+ if (isTypedArrayObject(node.left.object)) {
580
+ return false;
581
+ }
542
582
  const { propertyNode } = extractPropertyAccess(node);
543
583
  // SAFE: numeric keys can't pollute Object prototypes (typed-array
544
584
  // / numeric-array assignment is structurally safe).
545
585
  if (isNumericKey(propertyNode)) {
546
586
  return false;
547
587
  }
588
+ // SAFE: key originates from for..in or Object.keys/entries iteration
589
+ if (isForInOrObjectKeysKey(propertyNode)) {
590
+ return false;
591
+ }
548
592
  // Skip if the key has been validated (e.g., includes() or hasOwnProperty check)
549
593
  if (hasPrecedingValidation(propertyNode, node)) {
550
594
  return false;
@@ -552,6 +596,30 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
552
596
  // Check for dangerous property access in assignment
553
597
  return isDangerousPropertyAccess(propertyNode);
554
598
  };
599
+ /**
600
+ * Returns true if the object being indexed is the result of a Reflect.*
601
+ * method call (e.g. Reflect.getMetadata, Reflect.ownKeys).
602
+ * Reflect metadata objects contain known framework-managed keys; they are
603
+ * not populated from user input and cannot be exploited for prototype
604
+ * pollution. This closes FPs from NestJS decorator metadata access patterns:
605
+ * Reflect.getMetadata(PARAMTYPES_METADATA, target, key!)?.[index!]
606
+ */
607
+ const isReflectResultAccess = (objectNode) => {
608
+ // Direct call: Reflect.getMetadata(...)
609
+ if (objectNode.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
610
+ const callee = objectNode.callee;
611
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
612
+ callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
613
+ callee.object.name === 'Reflect') {
614
+ return true;
615
+ }
616
+ }
617
+ // Optional chain: Reflect.getMetadata(...)?.[key]
618
+ if (objectNode.type === eslint_devkit_1.AST_NODE_TYPES.ChainExpression) {
619
+ return isReflectResultAccess(objectNode.expression);
620
+ }
621
+ return false;
622
+ };
555
623
  /**
556
624
  * Determine if this is a high-risk member access
557
625
  */
@@ -560,6 +628,14 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
560
628
  if (!node.computed) {
561
629
  return false;
562
630
  }
631
+ // SAFE: accessing result of Reflect.* call (framework-managed metadata)
632
+ if (isReflectResultAccess(node.object)) {
633
+ return false;
634
+ }
635
+ // SAFE: typed-array element read is numeric, not a string-key injection
636
+ if (isTypedArrayObject(node.object)) {
637
+ return false;
638
+ }
563
639
  const { propertyNode } = extractPropertyAccess(node);
564
640
  // Numeric keys cannot pollute Object prototypes — typed-array and
565
641
  // numeric-array access (`arr[0]`, `arr[i]` where i is a for-loop
@@ -570,6 +646,10 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
570
646
  if (isNumericKey(propertyNode)) {
571
647
  return false;
572
648
  }
649
+ // SAFE: key originates from for..in or Object.keys/entries iteration
650
+ if (isForInOrObjectKeysKey(propertyNode)) {
651
+ return false;
652
+ }
573
653
  // Skip if the key has been validated (e.g., includes() or hasOwnProperty check)
574
654
  if (hasPrecedingValidation(propertyNode, node)) {
575
655
  return false;
@@ -643,6 +723,74 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
643
723
  }
644
724
  return false;
645
725
  };
726
+ /**
727
+ * Returns true if the identifier is the iteration variable of a `for...in`
728
+ * statement or a `for...of Object.keys()/Object.entries()` statement. Keys
729
+ * from these loops are guaranteed to be actual property names on the object
730
+ * (not user-controlled inputs), so `obj[key]` inside such a loop is safe
731
+ * from prototype-pollution injection. Closes the bulk of ILB-Wild FPs on
732
+ * utility and serialisation code.
733
+ */
734
+ const isForInOrObjectKeysKey = (node) => {
735
+ if (node.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
736
+ return false;
737
+ const scope = context.sourceCode.getScope(node);
738
+ const variable = scope.references.find((r) => r.identifier === node)?.resolved;
739
+ if (!variable || variable.defs.length === 0)
740
+ return false;
741
+ const def = variable.defs[0];
742
+ const varDecl = def.node?.parent;
743
+ const loopStmt = varDecl?.parent;
744
+ if (!varDecl || varDecl.type !== eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration)
745
+ return false;
746
+ // for (const key in obj) { ... obj[key] ... }
747
+ if (loopStmt?.type === eslint_devkit_1.AST_NODE_TYPES.ForInStatement && loopStmt.left === varDecl) {
748
+ return true;
749
+ }
750
+ // for (const key of Object.keys(obj)) / Object.entries(obj)
751
+ if (loopStmt?.type === eslint_devkit_1.AST_NODE_TYPES.ForOfStatement && loopStmt.left === varDecl) {
752
+ const right = loopStmt.right;
753
+ return (right.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
754
+ right.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
755
+ !right.callee.computed &&
756
+ right.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
757
+ right.callee.object.name === 'Object' &&
758
+ right.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
759
+ (right.callee.property.name === 'keys' || right.callee.property.name === 'entries'));
760
+ }
761
+ return false;
762
+ };
763
+ /**
764
+ * Returns true if the object being indexed was declared as a typed array
765
+ * (Int8Array…Float64Array, BigInt64Array, BigUint64Array). Typed-array
766
+ * element access is numeric by construction; string-keyed prototype
767
+ * pollution is impossible. This closes FPs on geometry, audio, image, and
768
+ * buffer-heavy code (Three.js, WebGL, wasm adapters, etc.).
769
+ */
770
+ const isTypedArrayObject = (objectNode) => {
771
+ if (objectNode.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
772
+ return false;
773
+ const varName = objectNode.name;
774
+ let scope = context.sourceCode.getScope(objectNode);
775
+ while (scope) {
776
+ const variable = scope.variables.find((v) => v.name === varName);
777
+ if (variable) {
778
+ for (const def of variable.defs) {
779
+ const init = def.node.init;
780
+ if (init?.type === eslint_devkit_1.AST_NODE_TYPES.NewExpression &&
781
+ init.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
782
+ TYPED_ARRAY_CTORS.has(init.callee.name)) {
783
+ return true;
784
+ }
785
+ }
786
+ break;
787
+ }
788
+ if (!scope.upper)
789
+ break;
790
+ scope = scope.upper;
791
+ }
792
+ return false;
793
+ };
646
794
  /**
647
795
  * Determine risk level based on the pattern and context
648
796
  */
@@ -663,9 +811,20 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
663
811
  if (!isHighRiskAssignment(node)) {
664
812
  return;
665
813
  }
666
- // Mark the MemberExpression as handled to avoid double-reporting
814
+ // Mark the entire left-side MemberExpression chain as handled.
815
+ // For chained access like `a[b][c] = val`, the rule reports on the
816
+ // AssignmentExpression (outer), then the MemberExpression visitor
817
+ // would fire again for the INNER `a[b]` access. We walk the object
818
+ // chain and mark every intermediate computed MemberExpression so the
819
+ // MemberExpression visitor skips them — preventing exact duplicates.
667
820
  if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
668
- handledMemberExpressions.add(node.left);
821
+ let me = node.left;
822
+ handledMemberExpressions.add(me);
823
+ // Walk into chained computed accesses: a[b][c] → also mark a[b]
824
+ while (me.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && me.object.computed) {
825
+ me = me.object;
826
+ handledMemberExpressions.add(me);
827
+ }
669
828
  }
670
829
  const { object, property, isAssignment, pattern } = extractPropertyAccess(node);
671
830
  const riskLevel = determineRiskLevel(pattern, isAssignment);
@@ -713,9 +872,18 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
713
872
  if (handledMemberExpressions.has(node)) {
714
873
  return;
715
874
  }
875
+ // Skip inner chained computed accesses — report only the OUTERMOST MemberExpression.
876
+ // For `a[b][c]`, both `a[b]` and `a[b][c]` start at the same source position, so
877
+ // reporting both produces exact duplicate findings. Skip the inner `a[b]` here;
878
+ // the outer `a[b][c]` will be reported by a subsequent call to this handler.
879
+ const parent = node.parent;
880
+ if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
881
+ parent.computed &&
882
+ parent.object === node) {
883
+ return;
884
+ }
716
885
  // Also check parent - if it's an AssignmentExpression and this node is the left side, skip
717
886
  // (This handles cases where WeakSet check didn't work due to visitor order)
718
- const parent = node.parent;
719
887
  if (parent && parent.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression && parent.left === node) {
720
888
  return;
721
889
  }
@@ -779,16 +947,20 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
779
947
  };
780
948
  return {
781
949
  AssignmentExpression: (node) => {
782
- if (isInCodemodContext)
950
+ if (isInCodemodContext || isTestFile)
783
951
  return;
784
952
  return checkAssignmentExpression(node);
785
953
  },
786
954
  MemberExpression: (node) => {
787
- if (isInCodemodContext)
955
+ if (isInCodemodContext || isTestFile)
788
956
  return;
789
957
  return checkMemberExpression(node);
790
958
  },
791
- CallExpression: checkObjectAssignSpread,
959
+ CallExpression: (node) => {
960
+ if (isInCodemodContext || isTestFile)
961
+ return;
962
+ return checkObjectAssignSpread(node);
963
+ },
792
964
  };
793
965
  },
794
966
  });
@@ -13,12 +13,12 @@ const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
13
  exports.detectWeakPasswordValidation = (0, eslint_devkit_1.createRule)({
14
14
  name: 'detect-weak-password-validation',
15
15
  meta: {
16
- type: 'problem',
16
+ type: 'suggestion',
17
17
  docs: {
18
18
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/detect-weak-password-validation.md',
19
19
  description: 'Identify weak password requirements',
20
20
  cwe: 'CWE-521',
21
- cvss: 9.5,
21
+ cvss: 5.3,
22
22
  },
23
23
  messages: {
24
24
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -18,7 +18,6 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects directive injection vulnerabilities in templates',
19
19
  cwe: 'CWE-96',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  directiveInjection: (0, eslint_devkit_2.formatLLMMessage)({
@@ -18,7 +18,6 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects Electron security vulnerabilities and insecure configurations',
19
19
  cwe: 'CWE-16',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  electronSecurityIssue: (0, eslint_devkit_2.formatLLMMessage)({
@@ -18,7 +18,6 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects GraphQL injection vulnerabilities and DoS attacks',
19
19
  cwe: 'CWE-89',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  graphqlInjection: (0, eslint_devkit_2.formatLLMMessage)({
@@ -130,7 +130,7 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
130
130
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-hardcoded-credentials.md',
131
131
  description: 'Detects hardcoded passwords, API keys, tokens, and other sensitive credentials',
132
132
  cwe: 'CWE-798',
133
- cvss: 9.5,
133
+ cvss: 9.8,
134
134
  confidence: 'medium',
135
135
  },
136
136
  fixable: 'code',
@@ -278,8 +278,14 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
278
278
  const filename = context.filename;
279
279
  const isTestFile = allowInTests && (filename.includes('.test.') ||
280
280
  filename.includes('.spec.') ||
281
+ filename.includes('.fixture.') ||
282
+ filename.includes('.mock.') ||
281
283
  filename.includes('__tests__') ||
282
- filename.includes('/test/'));
284
+ filename.includes('__mocks__') ||
285
+ filename.includes('/test/') ||
286
+ filename.includes('/tests/') ||
287
+ filename.includes('/fixtures/') ||
288
+ filename.includes('/mocks/'));
283
289
  // Compile ignore patterns to regex
284
290
  const compiledIgnorePatterns = ignorePatterns.map((pattern) => new RegExp(pattern));
285
291
  const detectionOptions = {
@@ -521,6 +527,22 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
521
527
  if (isTestFile) {
522
528
  return;
523
529
  }
530
+ // Skip fallback in `process.env.X || 'value'` — the string is only
531
+ // used when the env var is absent (dev-mode default). The real secret
532
+ // lives in the environment, not the source file.
533
+ if (parent?.type === 'LogicalExpression' &&
534
+ parent.operator === '||' &&
535
+ parent.right === node) {
536
+ const left = parent.left;
537
+ if (left.type === 'MemberExpression' &&
538
+ left.object.type === 'MemberExpression' &&
539
+ left.object.object.type === 'Identifier' &&
540
+ left.object.object.name === 'process' &&
541
+ left.object.property.type === 'Identifier' &&
542
+ left.object.property.name === 'env') {
543
+ return; // safe — fallback to process.env value
544
+ }
545
+ }
524
546
  // Skip if used as a UI label / HTML attribute value (form-field name,
525
547
  // type tag, ARIA label, i18n key) — these aren't credentials.
526
548
  if (isLabelContext(node, parent)) {
@@ -18,7 +18,7 @@ exports.noHardcodedSessionTokens = (0, eslint_devkit_1.createRule)({
18
18
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-hardcoded-session-tokens.md',
19
19
  description: 'Detect hardcoded session/JWT tokens',
20
20
  cwe: 'CWE-798',
21
- cvss: 9.5,
21
+ cvss: 9.8,
22
22
  },
23
23
  messages: {
24
24
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -18,7 +18,6 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects improper sanitization of user input',
19
19
  cwe: 'CWE-116',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  improperSanitization: (0, eslint_devkit_2.formatLLMMessage)({
@@ -18,7 +18,6 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects improper type validation in user input handling',
19
19
  cwe: 'CWE-1287',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  improperTypeValidation: (0, eslint_devkit_2.formatLLMMessage)({
@@ -13,12 +13,12 @@ exports.noInsecureComparison = (0, eslint_devkit_2.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  deprecated: true,
16
- replacedBy: ['@see eslint-plugin-crypto/no-timing-unsafe-compare'],
16
+ replacedBy: ['node-security/no-timing-unsafe-compare'],
17
17
  docs: {
18
18
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-insecure-comparison.md',
19
19
  description: 'Detects insecure comparison operators (==, !=) that can lead to type coercion vulnerabilities',
20
20
  cwe: 'CWE-697',
21
- cvss: 7.5,
21
+ cvss: 5.3,
22
22
  },
23
23
  fixable: 'code',
24
24
  hasSuggestions: true,
@@ -18,7 +18,6 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects LDAP injection vulnerabilities',
19
19
  cwe: 'CWE-90',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  ldapInjection: (0, eslint_devkit_2.formatLLMMessage)({
@@ -111,7 +111,7 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
111
111
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-missing-authentication.md',
112
112
  description: 'Detects missing authentication checks in route handlers',
113
113
  cwe: 'CWE-287',
114
- cvss: 9.5,
114
+ cvss: 9.8,
115
115
  },
116
116
  hasSuggestions: true,
117
117
  messages: {
@@ -15,7 +15,7 @@ const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
15
  exports.noPiiInLogs = (0, eslint_devkit_1.createRule)({
16
16
  name: 'no-pii-in-logs',
17
17
  meta: {
18
- type: 'problem',
18
+ type: 'suggestion',
19
19
  docs: {
20
20
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-pii-in-logs.md',
21
21
  description: 'Prevent PII (email, SSN, credit cards) in console logs',
@@ -111,7 +111,7 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
111
111
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-privilege-escalation.md',
112
112
  description: 'Detects potential privilege escalation vulnerabilities',
113
113
  cwe: 'CWE-269',
114
- cvss: 7.5,
114
+ cvss: 8.8,
115
115
  },
116
116
  hasSuggestions: true,
117
117
  messages: {
@@ -30,12 +30,12 @@ function containsSensitiveData(text, patterns) {
30
30
  exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
31
31
  name: 'no-sensitive-data-exposure',
32
32
  meta: {
33
- type: 'problem',
33
+ type: 'suggestion',
34
34
  docs: {
35
35
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-sensitive-data-exposure.md',
36
36
  description: 'Detects PII/credentials in logs, responses, or error messages',
37
37
  cwe: 'CWE-532',
38
- cvss: 7.5,
38
+ cvss: 5.3,
39
39
  },
40
40
  hasSuggestions: true,
41
41
  messages: {
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * ESLint Rule: no-template-injection
7
+ * CWE-94: Improper Control of Generation of Code (Code Injection via Templates)
8
+ *
9
+ * Detects server-side template engine calls where the template argument is
10
+ * dynamic (not a string literal). An attacker who controls the template
11
+ * string can execute arbitrary server-side code.
12
+ *
13
+ * Detection: structural-api.
14
+ * Handlebars.compile(userInput) — fires (dynamic first arg)
15
+ * Handlebars.compile('<h1>{{t}}</h1>') — silent (string literal)
16
+ *
17
+ * Covered engines: Handlebars, EJS, Pug/Jade, Mustache, Nunjucks, Swig,
18
+ * Dust, doT, and their common aliases.
19
+ */
20
+ import type { TSESLint } from '@interlace/eslint-devkit';
21
+ export declare const noTemplateInjection: TSESLint.RuleModule<"templateInjection", [], unknown, TSESLint.RuleListener> & {
22
+ name: string;
23
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.noTemplateInjection = void 0;
8
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
9
+ const TEMPLATE_COMPILE_METHODS = new Set([
10
+ 'compile', 'precompile', 'create', 'parse', 'template',
11
+ ]);
12
+ const TEMPLATE_RENDER_METHODS = new Set([
13
+ 'render', 'renderFile', 'renderString', 'renderToString', 'renderTemplate',
14
+ ]);
15
+ const ALL_TEMPLATE_METHODS = new Set([
16
+ ...TEMPLATE_COMPILE_METHODS,
17
+ ...TEMPLATE_RENDER_METHODS,
18
+ ]);
19
+ const TEMPLATE_ENGINE_OBJECTS = new Set([
20
+ 'Handlebars', 'handlebars',
21
+ 'ejs',
22
+ 'pug', 'jade',
23
+ 'mustache', 'Mustache',
24
+ 'nunjucks',
25
+ 'swig',
26
+ 'dust', 'Dust',
27
+ 'doT',
28
+ 'consolidate',
29
+ ]);
30
+ exports.noTemplateInjection = (0, eslint_devkit_1.createRule)({
31
+ name: 'no-template-injection',
32
+ meta: {
33
+ type: 'problem',
34
+ docs: {
35
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-template-injection.md',
36
+ description: 'Disallow dynamic strings as template arguments to server-side template engines (CWE-94)',
37
+ cwe: 'CWE-94',
38
+ cvss: 9.8,
39
+ },
40
+ messages: {
41
+ templateInjection: (0, eslint_devkit_1.formatLLMMessage)({
42
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
43
+ issueName: 'Template Injection (CWE-94)',
44
+ cwe: 'CWE-94',
45
+ description: '{{engine}}.{{method}}() receives a dynamic string. An attacker who controls the template can execute arbitrary server-side code.',
46
+ severity: 'CRITICAL',
47
+ fix: 'Pass only string literals as templates. If the template must vary, load it from a trusted file system path, never from user input.',
48
+ documentationLink: 'https://portswigger.net/web-security/server-side-template-injection',
49
+ }),
50
+ },
51
+ schema: [],
52
+ },
53
+ defaultOptions: [],
54
+ create(context) {
55
+ return {
56
+ CallExpression(node) {
57
+ const { callee, arguments: args } = node;
58
+ if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
59
+ return;
60
+ const { object, property } = callee;
61
+ if (object.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
62
+ return;
63
+ if (property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
64
+ return;
65
+ const engineName = object.name;
66
+ const methodName = property.name;
67
+ if (!TEMPLATE_ENGINE_OBJECTS.has(engineName))
68
+ return;
69
+ if (!ALL_TEMPLATE_METHODS.has(methodName))
70
+ return;
71
+ const firstArg = args[0];
72
+ if (!firstArg)
73
+ return;
74
+ // String literal → safe (static template, no injection surface)
75
+ if (firstArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
76
+ typeof firstArg.value === 'string')
77
+ return;
78
+ // Template literal with NO expressions → safe (equivalent to a string literal)
79
+ if (firstArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral &&
80
+ firstArg.expressions.length === 0)
81
+ return;
82
+ context.report({
83
+ node: firstArg,
84
+ messageId: 'templateInjection',
85
+ data: { engine: engineName, method: methodName },
86
+ });
87
+ },
88
+ };
89
+ },
90
+ });
@@ -18,7 +18,6 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects unchecked loop conditions that could cause DoS',
19
19
  cwe: 'CWE-400',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  uncheckedLoopCondition: (0, eslint_devkit_2.formatLLMMessage)({
@@ -18,7 +18,6 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects unlimited resource allocation that could cause DoS',
19
19
  cwe: 'CWE-770',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  unlimitedResourceAllocation: (0, eslint_devkit_2.formatLLMMessage)({
@@ -510,28 +509,40 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
510
509
  calleeText.includes('Buffer') ||
511
510
  calleeText.includes('readFile') ||
512
511
  calleeText.includes('writeFile')) {
513
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
514
- if (safetyChecker.isSafe(node, context)) {
515
- return;
512
+ // SAFE: Array.isArray / Array.from / Array.of are not allocation hazards.
513
+ if (calleeText === 'Array.isArray' ||
514
+ calleeText === 'Array.from' ||
515
+ calleeText === 'Array.of') {
516
+ // Array.from / Array.of are fine; allocation comes from their args, not size
516
517
  }
517
- /* c8 ignore stop */
518
- // Skip if this is an assignment to an array element (pre-allocated pattern)
519
- const parent = node.parent;
520
- if (parent && parent.type === 'AssignmentExpression' &&
521
- parent.left.type === 'MemberExpression' &&
522
- parent.left.object.type === 'Identifier') {
523
- // This is assigning to an array element, likely pre-allocated
524
- return;
518
+ else {
519
+ /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
520
+ if (safetyChecker.isSafe(node, context)) {
521
+ return;
522
+ }
523
+ /* c8 ignore stop */
524
+ // SAFE: first arg is a numeric literal — size is statically bounded.
525
+ const firstArg = node.arguments[0];
526
+ if (firstArg?.type === 'Literal' && typeof firstArg.value === 'number') {
527
+ return;
528
+ }
529
+ // Skip if this is an assignment to an array element (pre-allocated pattern)
530
+ const parent = node.parent;
531
+ if (parent && parent.type === 'AssignmentExpression' &&
532
+ parent.left.type === 'MemberExpression' &&
533
+ parent.left.object.type === 'Identifier') {
534
+ return;
535
+ }
536
+ // Report resourceAllocationInLoop - this can be in addition to user input errors
537
+ context.report({
538
+ node,
539
+ messageId: 'resourceAllocationInLoop',
540
+ data: {
541
+ filePath: filename,
542
+ line: String(node.loc?.start.line ?? 0),
543
+ },
544
+ });
525
545
  }
526
- // Report resourceAllocationInLoop - this can be in addition to user input errors
527
- context.report({
528
- node,
529
- messageId: 'resourceAllocationInLoop',
530
- data: {
531
- filePath: filename,
532
- line: String(node.loc?.start.line ?? 0),
533
- },
534
- });
535
546
  }
536
547
  }
537
548
  },
@@ -622,7 +633,6 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
622
633
  }
623
634
  // Check for resource allocation inside loops
624
635
  if ((0, eslint_devkit_3.isInsideLoop)(node)) {
625
- // Check if this allocates resources
626
636
  const newCalleeText = sourceCode.getText(callee);
627
637
  if (newCalleeText.includes('Buffer') ||
628
638
  newCalleeText.includes('Array') ||
@@ -633,6 +643,11 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
633
643
  return;
634
644
  }
635
645
  /* c8 ignore stop */
646
+ // SAFE: first arg is a numeric literal — size is statically bounded.
647
+ const firstArg = node.arguments[0];
648
+ if (firstArg?.type === 'Literal' && typeof firstArg.value === 'number') {
649
+ return;
650
+ }
636
651
  context.report({
637
652
  node,
638
653
  messageId: 'resourceAllocationInLoop',
@@ -182,6 +182,10 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
182
182
  const validatedVariables = new Set();
183
183
  // Track variables that contain untrusted data
184
184
  const untrustedVariables = new Set();
185
+ // Variables read from a literal-string file path (e.g. fs.readFileSync('config.json')).
186
+ // These are still "untrusted" for eval/Function but safe for JSON.parse and other
187
+ // schema-validating parsers because the file content is statically bundled.
188
+ const literalPathFileVars = new Set();
185
189
  /**
186
190
  * Check if this is a dangerous deserialization function
187
191
  */
@@ -370,6 +374,11 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
370
374
  if (arg.type === 'Identifier' && validatedVariables.has(arg.name)) {
371
375
  return false;
372
376
  }
377
+ // SAFE for JSON.parse/schema parsers: if the input came from a
378
+ // literal-path file read (bundled config), it is not user-controlled.
379
+ if (arg.type === 'Identifier' && literalPathFileVars.has(arg.name)) {
380
+ return false;
381
+ }
373
382
  return isUntrustedInput(arg) && !isInputValidated(arg);
374
383
  });
375
384
  if (hasUntrustedInput) {
@@ -414,6 +423,12 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
414
423
  callee.property.type === 'Identifier' &&
415
424
  ['readFile', 'readFileSync'].includes(callee.property.name)) {
416
425
  untrustedVariables.add(declarator.id.name);
426
+ // Track whether the path is a literal — used downstream to skip
427
+ // safe deserializers (JSON.parse) on known-static files.
428
+ const pathArg = declarator.init.arguments[0];
429
+ if (pathArg?.type === 'Literal' && typeof pathArg.value === 'string') {
430
+ literalPathFileVars.add(declarator.id.name);
431
+ }
417
432
  }
418
433
  }
419
434
  }
@@ -18,7 +18,6 @@ exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects weak password recovery mechanisms',
19
19
  cwe: 'CWE-640',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  weakPasswordRecovery: (0, eslint_devkit_2.formatLLMMessage)({
@@ -18,7 +18,6 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
18
18
  description: 'Detects XPath injection vulnerabilities',
19
19
  cwe: 'CWE-643',
20
20
  },
21
- fixable: 'code',
22
21
  hasSuggestions: true,
23
22
  messages: {
24
23
  xpathInjection: (0, eslint_devkit_2.formatLLMMessage)({
@@ -61,7 +61,7 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
61
61
  description: 'Detect XML External Entity (XXE) injection vulnerabilities',
62
62
  url: 'https://cwe.mitre.org/data/definitions/611.html',
63
63
  cwe: 'CWE-611',
64
- cvss: 9.5,
64
+ cvss: 9.1,
65
65
  },
66
66
  messages: {
67
67
  xxeInjection: (0, eslint_devkit_2.formatLLMMessage)({
@@ -18,7 +18,7 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
18
18
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/require-backend-authorization.md',
19
19
  description: 'Require server-side authorization checks',
20
20
  cwe: 'CWE-602',
21
- cvss: 9.5,
21
+ cvss: 6.5,
22
22
  },
23
23
  messages: {
24
24
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({