eslint-plugin-secure-coding 3.3.4 → 3.4.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 (65) hide show
  1. package/README.md +4 -4
  2. package/package.json +30 -37
  3. package/src/index.d.ts +17 -23
  4. package/src/index.js +2 -113
  5. package/src/oxlint.d.ts +17 -20
  6. package/src/oxlint.js +0 -18
  7. package/src/rules/detect-non-literal-regexp/index.js +5 -79
  8. package/src/rules/detect-object-injection/index.js +2 -221
  9. package/src/rules/detect-weak-password-validation/index.js +0 -12
  10. package/src/rules/no-directive-injection/index.js +0 -33
  11. package/src/rules/no-electron-security-issues/index.js +0 -41
  12. package/src/rules/no-format-string-injection/index.js +0 -82
  13. package/src/rules/no-graphql-injection/index.js +86 -151
  14. package/src/rules/no-hardcoded-credentials/index.js +142 -184
  15. package/src/rules/no-hardcoded-session-tokens/index.js +0 -11
  16. package/src/rules/no-improper-sanitization/index.js +0 -44
  17. package/src/rules/no-improper-type-validation/index.js +1 -51
  18. package/src/rules/no-insecure-comparison/index.js +39 -35
  19. package/src/rules/no-ldap-injection/index.js +8 -61
  20. package/src/rules/no-missing-authentication/index.js +2 -56
  21. package/src/rules/no-pii-in-logs/index.js +0 -13
  22. package/src/rules/no-privilege-escalation/index.js +2 -49
  23. package/src/rules/no-redos-vulnerable-regex/index.js +3 -49
  24. package/src/rules/no-sensitive-data-exposure/index.js +5 -29
  25. package/src/rules/no-template-injection/index.js +0 -6
  26. package/src/rules/no-unchecked-loop-condition/index.js +3 -99
  27. package/src/rules/no-unlimited-resource-allocation/index.js +2 -75
  28. package/src/rules/no-unsafe-deserialization/index.js +55 -66
  29. package/src/rules/no-unsafe-regex-construction/index.js +22 -62
  30. package/src/rules/no-weak-password-recovery/index.js +0 -43
  31. package/src/rules/no-xpath-injection/index.js +13 -75
  32. package/src/rules/no-xxe-injection/index.js +1 -47
  33. package/src/rules/require-backend-authorization/index.js +0 -10
  34. package/src/rules/require-secure-defaults/index.js +0 -10
  35. package/src/types/index.js +0 -5
  36. package/AGENTS.md +0 -131
  37. package/CHANGELOG.md +0 -311
  38. package/src/rules/detect-non-literal-regexp/index.d.ts +0 -28
  39. package/src/rules/detect-object-injection/index.d.ts +0 -35
  40. package/src/rules/detect-weak-password-validation/index.d.ts +0 -12
  41. package/src/rules/no-directive-injection/index.d.ts +0 -38
  42. package/src/rules/no-electron-security-issues/index.d.ts +0 -36
  43. package/src/rules/no-format-string-injection/index.d.ts +0 -44
  44. package/src/rules/no-graphql-injection/index.d.ts +0 -47
  45. package/src/rules/no-hardcoded-credentials/index.d.ts +0 -44
  46. package/src/rules/no-hardcoded-session-tokens/index.d.ts +0 -12
  47. package/src/rules/no-improper-sanitization/index.d.ts +0 -38
  48. package/src/rules/no-improper-type-validation/index.d.ts +0 -36
  49. package/src/rules/no-insecure-comparison/index.d.ts +0 -26
  50. package/src/rules/no-ldap-injection/index.d.ts +0 -53
  51. package/src/rules/no-missing-authentication/index.d.ts +0 -32
  52. package/src/rules/no-pii-in-logs/index.d.ts +0 -12
  53. package/src/rules/no-privilege-escalation/index.d.ts +0 -32
  54. package/src/rules/no-redos-vulnerable-regex/index.d.ts +0 -28
  55. package/src/rules/no-sensitive-data-exposure/index.d.ts +0 -30
  56. package/src/rules/no-template-injection/index.d.ts +0 -23
  57. package/src/rules/no-unchecked-loop-condition/index.d.ts +0 -38
  58. package/src/rules/no-unlimited-resource-allocation/index.d.ts +0 -38
  59. package/src/rules/no-unsafe-deserialization/index.d.ts +0 -40
  60. package/src/rules/no-unsafe-regex-construction/index.d.ts +0 -30
  61. package/src/rules/no-weak-password-recovery/index.d.ts +0 -38
  62. package/src/rules/no-xpath-injection/index.d.ts +0 -39
  63. package/src/rules/no-xxe-injection/index.d.ts +0 -36
  64. package/src/rules/require-backend-authorization/index.d.ts +0 -12
  65. package/src/rules/require-secure-defaults/index.d.ts +0 -12
@@ -1,44 +1,29 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noXxeInjection = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- /**
12
- * Check if this is an XML parsing operation
13
- */
14
6
  const isXmlParsingCall = (node) => {
15
7
  const callee = node.callee;
16
- // Check for XML library method calls
17
8
  if (callee.type === 'MemberExpression' &&
18
9
  callee.property.type === 'Identifier' &&
19
10
  ['parse', 'parseFromString', 'parseString', 'parseXmlString', 'parseXML'].includes(callee.property.name)) {
20
11
  return true;
21
12
  }
22
- // Check for constructor calls
23
13
  if (callee.type === 'Identifier' &&
24
14
  ['DOMParser', 'XMLHttpRequest', 'ActiveXObject'].includes(callee.name)) {
25
15
  return true;
26
16
  }
27
17
  return false;
28
18
  };
29
- /**
30
- * Check if parser options enable dangerous features
31
- */
32
19
  const hasDangerousParserOptions = (optionsNode) => {
33
20
  if (optionsNode.type !== 'ObjectExpression') {
34
21
  return false;
35
22
  }
36
- // Check for dangerous options
37
23
  for (const prop of optionsNode.properties) {
38
24
  if (prop.type === 'Property' &&
39
25
  prop.key.type === 'Identifier' &&
40
26
  ['resolveExternals', 'expandEntityReferences', 'noent'].includes(prop.key.name)) {
41
- // Check if the value enables dangerous features
42
27
  if (prop.value.type === 'Literal' && prop.value.value === true) {
43
28
  return true;
44
29
  }
@@ -46,9 +31,6 @@ const hasDangerousParserOptions = (optionsNode) => {
46
31
  }
47
32
  return false;
48
33
  };
49
- /**
50
- * Check if XML contains dangerous entity declarations
51
- */
52
34
  const containsDangerousEntities = (xmlText) => {
53
35
  return /<!ENTITY/i.test(xmlText) &&
54
36
  /SYSTEM\s+["']/i.test(xmlText);
@@ -125,24 +107,16 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
125
107
  },
126
108
  ],
127
109
  create(context, [options]) {
128
- // `options` is guaranteed defined here: createRule's RuleCreator wrapper
129
- // (@typescript-eslint/utils applyDefault) always seeds it from
130
- // `defaultOptions` above, so it can never be undefined at runtime.
131
110
  const { safeParserOptions = ['noent', 'resolveExternals', 'expandEntityReferences', 'entityResolver'], xmlValidationFunctions = ['validateXml', 'sanitizeXml', 'cleanXml', 'parseXmlSafe'], } = options;
132
111
  const filename = context.filename;
133
- /**
134
- * Check if parser options are secure
135
- */
136
112
  const hasSecureParserOptions = (optionsNode) => {
137
113
  if (optionsNode.type !== 'ObjectExpression') {
138
114
  return false;
139
115
  }
140
- // Check for secure options
141
116
  for (const prop of optionsNode.properties) {
142
117
  if (prop.type === 'Property' &&
143
118
  prop.key.type === 'Identifier' &&
144
119
  safeParserOptions.includes(prop.key.name)) {
145
- // Check if the value is secure
146
120
  if (prop.value.type === 'Literal' && prop.value.value === false) {
147
121
  return true;
148
122
  }
@@ -153,11 +127,7 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
153
127
  }
154
128
  return false;
155
129
  };
156
- /**
157
- * Check if input has been validated
158
- */
159
130
  const isXmlInputValidated = (xmlSource) => {
160
- // Check if the input comes from a validation function
161
131
  let current = xmlSource;
162
132
  while (current) {
163
133
  if (current.type === 'CallExpression' &&
@@ -169,34 +139,27 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
169
139
  }
170
140
  return false;
171
141
  };
172
- /**
173
- * Check if input source is untrusted
174
- */
175
142
  const isUntrustedXmlSource = (xmlSource) => {
176
- // Check for user input sources
177
143
  if (xmlSource.type === 'Identifier') {
178
144
  const varName = xmlSource.name.toLowerCase();
179
- // Consider variables with safe/validated names as trusted
180
145
  if (['clean', 'safe', 'validated', 'sanitized', 'validatedxml', 'sanitizedxml'].some(safe => varName.includes(safe))) {
181
146
  return false;
182
147
  }
183
148
  return ['req', 'request', 'body', 'query', 'params', 'input', 'xml', 'data'].some(keyword => varName.includes(keyword));
184
149
  }
185
- // Check for file system reads (potentially untrusted)
186
150
  let current = xmlSource;
187
151
  while (current) {
188
152
  if (current.type === 'CallExpression' &&
189
153
  current.callee.type === 'MemberExpression' &&
190
154
  current.callee.property.type === 'Identifier' &&
191
155
  ['readFileSync', 'readFile', 'createReadStream'].includes(current.callee.property.name)) {
192
- return true; // File input is potentially untrusted
156
+ return true;
193
157
  }
194
158
  current = current.parent;
195
159
  }
196
160
  return false;
197
161
  };
198
162
  return {
199
- // Check XML parsing calls
200
163
  CallExpression(node) {
201
164
  if (!isXmlParsingCall(node)) {
202
165
  return;
@@ -205,13 +168,10 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
205
168
  if (args.length === 0) {
206
169
  return;
207
170
  }
208
- // Check XML input source
209
171
  const xmlInput = args[0];
210
172
  const isUntrusted = isUntrustedXmlSource(xmlInput);
211
173
  const isValidated = isXmlInputValidated(xmlInput);
212
- // Check if this parser call uses secure options
213
174
  const hasSecureOptions = args.length >= 2 && hasSecureParserOptions(args[1]);
214
- // CRITICAL: Untrusted XML input without validation (only if parser is not secure)
215
175
  if (isUntrusted && !isValidated && !hasSecureOptions) {
216
176
  context.report({
217
177
  node: xmlInput,
@@ -222,7 +182,6 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
222
182
  },
223
183
  });
224
184
  }
225
- // Check for dangerous parser options
226
185
  if (args.length >= 2) {
227
186
  const optionsArg = args[1];
228
187
  if (hasDangerousParserOptions(optionsArg)) {
@@ -236,18 +195,14 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
236
195
  });
237
196
  return;
238
197
  }
239
- // DOMParser method safety is covered by constructor detection
240
- // No need to report unsafeXmlParser for individual method calls
241
198
  }
242
199
  },
243
- // Check XML parser constructor calls
244
200
  NewExpression(node) {
245
201
  const callee = node.callee;
246
202
  if (callee.type !== 'Identifier' ||
247
203
  !['DOMParser', 'XMLHttpRequest', 'ActiveXObject'].includes(callee.name)) {
248
204
  return;
249
205
  }
250
- // Constructor calls for XML parsers are considered unsafe
251
206
  context.report({
252
207
  node,
253
208
  messageId: 'unsafeXmlParser',
@@ -257,7 +212,6 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
257
212
  },
258
213
  });
259
214
  },
260
- // Check for dangerous XML literals
261
215
  Literal(node) {
262
216
  if (typeof node.value === 'string' && containsDangerousEntities(node.value)) {
263
217
  context.report({
@@ -1,14 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.requireBackendAuthorization = void 0;
9
- /**
10
- * @fileoverview Require server-side authorization checks
11
- */
12
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
5
  exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
14
6
  name: 'require-backend-authorization',
@@ -41,7 +33,6 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
41
33
  const authProperties = new Set(['role', 'isAdmin', 'isAuthenticated', 'permissions', 'admin']);
42
34
  return {
43
35
  IfStatement(node) {
44
- // Detect role-based access in client-side if statements
45
36
  if (node.test.type === 'BinaryExpression') {
46
37
  const checkMember = (expr) => {
47
38
  if (expr.type === 'MemberExpression' &&
@@ -56,7 +47,6 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
56
47
  report(node);
57
48
  }
58
49
  }
59
- // Check for user.role or user.isAdmin access
60
50
  if (node.test.type === 'MemberExpression' &&
61
51
  node.test.property.type === 'Identifier' &&
62
52
  authProperties.has(node.test.property.name)) {
@@ -1,16 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.requireSecureDefaults = void 0;
9
- /**
10
- * @fileoverview Ensure secure default configurations
11
- * @see https://owasp.org/www-project-mobile-top-10/
12
- * @see https://cwe.mitre.org/data/definitions/453.html
13
- */
14
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
5
  exports.requireSecureDefaults = (0, eslint_devkit_1.createRule)({
16
6
  name: 'require-secure-defaults',
@@ -1,7 +1,2 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
package/AGENTS.md DELETED
@@ -1,131 +0,0 @@
1
- # AGENTS.md
2
-
3
- > Context for AI coding agents working on eslint-plugin-secure-coding
4
-
5
- ## Setup Commands
6
-
7
- ```bash
8
- # Install dependencies (from monorepo root)
9
- npm install
10
-
11
- # Build this package
12
- nx build eslint-plugin-secure-coding
13
-
14
- # Run tests
15
- nx test eslint-plugin-secure-coding
16
-
17
- # Run tests with coverage
18
- nx test eslint-plugin-secure-coding --coverage
19
-
20
- # Lint this package
21
- nx lint eslint-plugin-secure-coding
22
- ```
23
-
24
- ## Code Style
25
-
26
- - TypeScript strict mode with `@interlace/eslint-devkit` types
27
- - Use `AST_NODE_TYPES` constants, never string literals for node types
28
- - Use `formatLLMMessage()` for all rule error messages
29
- - Include CWE, CVSS, OWASP in every security message
30
- - Use `c8 ignore` comments with documented reasons for untestable code
31
- - Single-pass AST traversal patterns (O(n) complexity)
32
-
33
- ## Testing Instructions
34
-
35
- - Tests use `@typescript-eslint/rule-tester` with Vitest
36
- - Each rule has `index.ts` (implementation) and `*.test.ts` (tests) in same directory
37
- - Run specific rule test: `nx test eslint-plugin-secure-coding --testPathPattern="no-sql-injection"`
38
- - Coverage target: ≥90% lines, ≥95% functions
39
- - All tests must pass before committing
40
-
41
- ## Project Structure
42
-
43
- ```
44
- src/
45
- ├── index.ts # Plugin entry, 4 configs
46
- └── rules/ # 89 rule directories organized by category
47
- └── [category]/
48
- └── [rule-name]/
49
- ├── index.ts # Rule implementation
50
- └── *.test.ts # Rule tests
51
- ```
52
-
53
- ## Plugin Purpose
54
-
55
- Security-focused ESLint plugin with **89 LLM-optimized rules** for detecting vulnerabilities. Framework-agnostic security covering OWASP Web Top 10 2021 and Mobile Top 10 2024.
56
-
57
- ## Available Presets
58
-
59
- | Preset | Rules | Description |
60
- | -------------- | --------------- | ----------------------------------- |
61
- | `recommended` | 89 (mixed) | Balanced security (Web + Mobile) |
62
- | `strict` | 89 (all errors) | Maximum security enforcement |
63
- | `owasp-top-10` | 32 rules | OWASP Top 10 2021 compliance |
64
- | `owasp-mobile` | 40 rules | OWASP Mobile Top 10 2024 compliance |
65
-
66
- ## Rule Categories
67
-
68
- ### Injection Prevention (11 rules)
69
-
70
- - `no-sql-injection` - CWE-89
71
- - `database-injection` - CWE-89
72
- - `detect-eval-with-expression` - CWE-95
73
- - `detect-child-process` - CWE-78
74
- - `no-graphql-injection` - CWE-943
75
- - `no-xxe-injection` - CWE-611
76
- - `no-xpath-injection` - CWE-643
77
- - `no-ldap-injection` - CWE-90
78
-
79
- ### Path & File Security (3 rules)
80
-
81
- - `detect-non-literal-fs-filename` - CWE-22
82
- - `no-zip-slip` - CWE-22
83
- - `no-toctou-vulnerability` - CWE-367
84
-
85
- ### Cryptography (6 rules)
86
-
87
- - `no-hardcoded-credentials` - CWE-798
88
- - `no-weak-crypto` - CWE-327
89
- - `no-insufficient-random` - CWE-330
90
- - `no-timing-attack` - CWE-208
91
- - `no-insecure-comparison` - CWE-697
92
- - `no-insecure-jwt` - CWE-347
93
-
94
- ### Mobile Security (30 rules)
95
-
96
- - `no-http-urls` - CWE-319
97
- - `no-credentials-in-storage-api` - CWE-522
98
- - `no-pii-in-logs` - CWE-532
99
- - `require-https-only` - CWE-319
100
- - And 26 more...
101
-
102
- ## Error Message Format
103
-
104
- All rules produce LLM-optimized 2-line structured messages:
105
-
106
- ```
107
- Line 1: [Icon] [CWE] [OWASP] [CVSS] | [Description] | [SEVERITY] [Compliance]
108
- Line 2: Fix: [instruction] | [doc-link]
109
- ```
110
-
111
- ## Key Features
112
-
113
- | Feature | Value |
114
- | -------------------- | -------------------------------- |
115
- | **Total Rules** | 89 |
116
- | **CWE Coverage** | 100% (all rules include CWE IDs) |
117
- | **OWASP Top 10** | Full Web (2021) + Mobile (2024) |
118
- | **AI Auto-Fix Rate** | 60-80% |
119
- | **Performance** | <10ms overhead per file |
120
- | **Privacy** | 100% local, no cloud calls |
121
-
122
- ## FAQ
123
-
124
- **Q: How do I enable all security rules?**
125
- A: Use `secureCoding.configs.strict`
126
-
127
- **Q: How do I configure a specific rule?**
128
- A: `'secure-coding/no-sql-injection': ['error', { strategy: 'parameterize' }]`
129
-
130
- **Q: How do I disable a rule inline?**
131
- A: `// eslint-disable-next-line secure-coding/no-sql-injection`
package/CHANGELOG.md DELETED
@@ -1,311 +0,0 @@
1
- ## 3.3.4
2
-
3
- ### Patch Changes
4
-
5
- - [#269](https://github.com/ofri-peretz/eslint/pull/269) [`7028fe2`](https://github.com/ofri-peretz/eslint/commit/7028fe2668a42266d831014184dcef70e73101ad) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - docs: dual-logo README header (Interlace mark + ESLint mark side by side) and closing Interlace footer — refreshes the README rendered on npmjs.com. No runtime changes.
6
-
7
- - Updated dependencies [[`7028fe2`](https://github.com/ofri-peretz/eslint/commit/7028fe2668a42266d831014184dcef70e73101ad)]:
8
- - @interlace/eslint-devkit@1.4.2
9
-
10
- ## 3.3.3
11
-
12
- ### Patch Changes
13
-
14
- - [#252](https://github.com/ofri-peretz/eslint/pull/252) [`d67e395`](https://github.com/ofri-peretz/eslint/commit/d67e3953c2748ad36e6aebe0f24b1d04e518b4d0) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Fix Codecov badge showing "unknown" — switch from flag to component URL format
15
-
16
- ## 3.3.2
17
-
18
- ### Patch Changes
19
-
20
- - [#225](https://github.com/ofri-peretz/eslint/pull/225) [`34ff5a8`](https://github.com/ofri-peretz/eslint/commit/34ff5a8e6f5126c5d1c0a524759e0af2b5476b46) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - CI-only: pin all coverage thresholds at 100% (integration target, merges last).
21
-
22
- ## 3.3.1
23
-
24
- ### Patch Changes
25
-
26
- - [#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
27
- emits. The emitted machine-readable message sources its `CVSS:x` from
28
- `CWE_MAPPING` via `formatLLMMessage` → `enrichFromCWE`, but the static
29
- `meta.docs.cvss` documentation field had drifted on 45 rules across these 7
30
- plugins — e.g. `no-hardcoded-credentials` documented `9.5` while emitting
31
- `CVSS:9.8` (the value the published article and SARIF/LLM consumers already
32
- read).
33
-
34
- This corrects the **documentation metadata only** — no emitted finding changes.
35
- Locked by `security-cvss-docs-consistency.lock.test.ts` (cross-plugin: every
36
- security rule's `meta.docs.cvss` must equal the CVSS it emits), the
37
- `no-hardcoded-credentials` rule lock (real ESLint `Linter` emission), and a
38
- devkit `enrichFromCWE` contract test pinning `CWE-798 → 9.8`.
39
-
40
- Follow-up (not in scope): 50 security rules document a CVSS that never appears
41
- in any emitted message (their messages carry no CWE), and several rules emit the
42
- generic CWE score where a rule-specific score may be warranted — both change
43
- emitted output and are separate decisions.
44
-
45
- ## 3.3.0
46
-
47
- ### Minor Changes
48
-
49
- - [#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
50
-
51
- **New preset: `configs['recommended-strict']`**
52
- Same 16-rule set as `recommended` but every rule promoted to `'error'`.
53
- For teams that want CI to block on all security findings, not just
54
- critical ones. The recommended preset stays unchanged.
55
-
56
- ```js
57
- // eslint.config.mjs
58
- import securePlugin from 'eslint-plugin-secure-coding';
59
- export default [...securePlugin.configs['recommended-strict']];
60
- ```
61
-
62
- **README: copy-paste quick-start block**
63
- Added a one-line usage example immediately after `npm install` so adopters
64
- don't have to discover the preset table buried further down the page.
65
- Also added cross-plugin discovery links to `node-security`, `jwt`, and
66
- `express-security` for teams that want broader coverage.
67
-
68
- ### Patch Changes
69
-
70
- - [#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
71
- - Test-file skip: rule is now silent on `*.test.*`, `*.spec.*`, `__tests__/`, and `*.fixture.*` paths
72
- - `for...in` loop variable: keys from `for (const key in obj)` are own property names, not user input
73
- - `Object.keys/entries` iteration: `for (const key of Object.keys(obj))` is safe by construction
74
- - Typed-array objects (`new Float32Array/Uint8Array/Int32Array/…`): element access is numeric, not string-keyed
75
-
76
- 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.
77
-
78
- - [#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
79
-
80
- **`no-unlimited-resource-allocation` — FP reduction (430 Edge FPs)**
81
- - 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)
82
- - Skip `Array.isArray`, `Array.from`, `Array.of` calls in the `alloc/Array` pattern check (these don't allocate unbounded memory)
83
-
84
- **`no-hardcoded-credentials` — FP reduction (~280 Edge FPs)**
85
- - Extended test-file skip to cover `.fixture.`, `.mock.`, `__mocks__/`, `/tests/`, `/fixtures/`, `/mocks/` paths
86
- - 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
87
-
88
- **Doc examples — 4 rules now have ❌ Incorrect examples**
89
- - `lambda-security/no-missing-authorization-check`
90
- - `lambda-security/no-overly-permissive-iam-policy`
91
- - `node-security/prefer-native-crypto` (renamed non-standard `### ❌ Third-Party (Flagged)` to `### ❌ Incorrect`)
92
- - `vercel-ai-security/require-tool-confirmation` (replaced placeholder with a real tested example)
93
-
94
- **`ilb-doc-test-alignment` scanner fixes**
95
- - Accept both `## ❌` and `### ❌` headings (docs use H3 under an H2 `## Examples` section; was only finding H2)
96
- - Slice from end-of-line rather than end-of-regex-match (prevents `## ❌ Incorrect Code` from leaving a partial heading in the parsed section)
97
-
98
- Result: `ilb:doc-test-alignment` → 206 ok, 0 doc has no ❌ examples (was 165 missing).
99
-
100
- - [#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
101
-
102
- 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:
103
- - `browser-security/no-clickjacking`
104
- - `import-next/first`, `named`, `no-barrel-import`, `no-import-module-exports`, `no-namespace`
105
- - `node-security/no-buffer-overread`, `no-unsafe-dynamic-require`, `no-zip-slip`
106
- - `react-features/react-no-inline-functions`
107
- - `reliability/no-jsdoc-terminator-in-example` (uses `suggest`, not auto-fix; corrected to `hasSuggestions: true` only)
108
- - `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`
109
-
110
- - [#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
111
-
112
- **`no-unsafe-deserialization` FP reduction (~112 FPs)**
113
- - Track `fs.readFileSync('literal')` calls in `literalPathFileVars` — a file read with a
114
- hardcoded path (bundled config) is not user-controlled input for safe deserializers
115
- (`JSON.parse`, schema-validating parsers). `eval()` still fires even on literal-path reads.
116
-
117
- **`no-buffer-overread` FP reduction (~129 FPs)**
118
- - Remove `b` (single-char, too broad) and `chunk` (too common for array chunks) from the
119
- Buffer alias heuristic — `isBufferType` now only matches `buf` and `bytes` by name,
120
- reducing false matches on non-Buffer variables.
121
-
122
- **New rule: `modernization/prefer-template-literal`**
123
- - Flags `"string " + variable` concatenation and suggests the equivalent template literal.
124
- - Auto-fix produces the correct `` `string ${variable}` `` replacement.
125
- - Pure string literal chains (`"a" + "b"`) and numeric addition are not flagged.
126
- - Closes P2 quality FN `prob_string_concat` in the ILB-Arena-Quality bench.
127
-
128
- **New rule: `modularity/no-mutable-exports`**
129
- - Flags `export let` and `export var` — module exports should be immutable `const`
130
- bindings so all importers share a stable reference.
131
- - Auto-fix replaces `let`/`var` with `const`.
132
- - Closes P2 quality FN `prob_mutable_export` in the ILB-Arena-Quality bench.
133
-
134
- - Updated dependencies [[`736a5fe`](https://github.com/ofri-peretz/eslint/commit/736a5fed47e673f6157ea900b29fe2a54e4bc7df)]:
135
- - @interlace/eslint-devkit@1.4.1
136
-
137
- ## 3.2.0 (Unreleased)
138
-
139
- ### Added
140
-
141
- - New `./oxlint` sub-export for use with [oxlint](https://oxc.rs/docs/guide/usage/linter)'s JS plugin API. Wire it via `{ "jsPlugins": ["eslint-plugin-secure-coding/oxlint"] }` in `.oxlintrc.json`. Exposes the same rule set as the main entry; rules degrade gracefully when type information is unavailable (oxlint's JS plugin context does not provide `parserServices`). The default ESLint entry (`./`) is unchanged.
142
-
143
- ## 3.1.3 (2026-02-09)
144
-
145
- This was a version bump only for eslint-plugin-secure-coding to align it with other projects, there were no code changes.
146
-
147
- # Changelog
148
-
149
- All notable changes to this project will be documented in this file.
150
-
151
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
152
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
153
-
154
- ## [3.1.1] - 2026-02-09
155
-
156
- This was a version bump only for eslint-plugin-secure-coding to align it with other projects, there were no code changes.
157
-
158
- ## [3.1.0] - 2026-02-09
159
-
160
- This was a version bump only for eslint-plugin-secure-coding to align it with other projects, there were no code changes.
161
-
162
- ## [3.0.3] - 2026-02-09
163
-
164
- This was a version bump only for eslint-plugin-secure-coding to align it with other projects, there were no code changes.
165
-
166
- ## [3.0.2] - 2025-12-20
167
-
168
- ### Performance
169
-
170
- - **detect-object-injection**: Replaced `getText()` + regex with AST-based validation (~4x faster)
171
- - **detect-non-literal-fs-filename**: Replaced `getText()` + regex with AST-based validation
172
- - **no-timing-attack**: Set-based O(1) lookups for sensitive variables and auth patterns
173
- - **no-buffer-overread**: Set-based O(1) lookups for buffer methods and user-controlled keywords
174
- - **no-missing-csrf-protection**: Set-based O(1) lookups for protected HTTP methods
175
- - **detect-child-process**: Set-based O(1) lookups for dangerous child_process methods
176
-
177
- ## [3.0.1] - 2025-12-20
178
-
179
- ### Fixed444
180
-
181
- - **detect-object-injection**: Reduced false positives by detecting validation patterns:
182
- - `includes()` checks in enclosing if-blocks
183
- - `hasOwnProperty()` / `Object.hasOwn()` / `in` operator checks
184
- - Preceding guard clauses with early exit (`if (!valid) throw`)
185
- - Numeric index access (`items[0]`, `items[1]`) now recognized as safe
186
- - **detect-non-literal-fs-filename**: Allow safe path patterns:
187
- - `path.join(__dirname, ...literals)` with all literal arguments
188
- - Paths validated with `startsWith()` checks (both inside if-blocks and after guard clauses)
189
- - **no-timing-attack**: Skip false positives in timing-safe contexts:
190
- - Length comparisons before `crypto.timingSafeEqual()`
191
- - Early returns inside functions using `timingSafeEqual`
192
- - Fixed file-level sensitive variable detection to be function-scoped
193
- - **no-unsanitized-html**: Track sanitized variables:
194
- - Variables assigned from `DOMPurify.sanitize()` now recognized as safe
195
- - **no-unlimited-resource-allocation**: Allow safe static paths:
196
- - `fs.readFileSync(path.join(__dirname, ...literals))` patterns now recognized as safe
197
-
198
- ## [3.0.0] - 2025-12-14
199
-
200
- ### Added
201
-
202
- - **OWASP Mobile Top 10 Coverage**: Added 40 new rules targeting mobile security risks (M1-M10).
203
- - **New Presets**:
204
- - `owasp-mobile-top-10`: Comprehensive mobile security ruleset.
205
- - **Documentation**:
206
- - Full "Mobile Security" table in README with CVSS scores and fixable icons.
207
- - Updated `AGENTS.md` with complete rule catalog for AI assistants.
208
-
209
- ### Changed
210
-
211
- - **Recommended Config**: Now includes critical mobile security rules for hybrid web/mobile apps.
212
- - **Rule Improvements**: Refined AST detection for `no-clickjacking` and `no-unvalidated-deeplinks` to reduce false positives.
213
-
214
- ## [1.0.0] - 2025-01-01
215
-
216
- ### Added
217
-
218
- - Initial release with 48 security-focused ESLint rules
219
- - LLM-optimized error messages with [CWE](https://cwe.mitre.org/) references and [OWASP](https://owasp.org/Top10/) mapping
220
- - Three preset configurations: `recommended`, `strict`, `owasp-top-10`
221
- - Full ESLint 9 flat config support
222
- - TypeScript support
223
-
224
- ### Security Rules
225
-
226
- #### Injection Prevention (11 rules)
227
-
228
- - `no-sql-injection` - SQL injection prevention
229
- - `database-injection` - Comprehensive SQL/NoSQL/ORM injection
230
- - `detect-eval-with-expression` - Dynamic eval() detection
231
- - `detect-child-process` - Command injection detection
232
- - `no-unsafe-dynamic-require` - Dynamic require() prevention
233
- - `no-graphql-injection` - GraphQL injection prevention
234
- - `no-xxe-injection` - XXE injection prevention
235
- - `no-xpath-injection` - XPath injection prevention
236
- - `no-ldap-injection` - LDAP injection prevention
237
- - `no-directive-injection` - Template injection prevention
238
- - `no-format-string-injection` - Format string injection prevention
239
-
240
- #### Path & File Security (3 rules)
241
-
242
- - `detect-non-literal-fs-filename` - Path traversal detection
243
- - `no-zip-slip` - Zip slip vulnerability prevention
244
- - `no-toctou-vulnerability` - TOCTOU race condition detection
245
-
246
- #### Regex Security (3 rules)
247
-
248
- - `detect-non-literal-regexp` - ReDoS detection in RegExp
249
- - `no-redos-vulnerable-regex` - ReDoS pattern detection
250
- - `no-unsafe-regex-construction` - Unsafe regex prevention
251
-
252
- #### Object & Prototype (2 rules)
253
-
254
- - `detect-object-injection` - Prototype pollution detection
255
- - `no-unsafe-deserialization` - Unsafe deserialization prevention
256
-
257
- #### Cryptography (6 rules)
258
-
259
- - `no-hardcoded-credentials` - Hardcoded secrets detection
260
- - `no-weak-crypto` - Weak algorithm detection
261
- - `no-insufficient-random` - Weak randomness detection
262
- - `no-timing-attack` - Timing attack prevention
263
- - `no-insecure-comparison` - Insecure comparison detection
264
- - `no-insecure-jwt` - JWT security issues detection
265
-
266
- #### Input Validation & XSS (5 rules)
267
-
268
- - `no-unvalidated-user-input` - Input validation enforcement
269
- - `no-unsanitized-html` - XSS via innerHTML prevention
270
- - `no-unescaped-url-parameter` - URL parameter XSS prevention
271
- - `no-improper-sanitization` - Output encoding enforcement
272
- - `no-improper-type-validation` - Type confusion prevention
273
-
274
- #### Authentication & Authorization (3 rules)
275
-
276
- - `no-missing-authentication` - Auth check enforcement
277
- - `no-privilege-escalation` - Privilege escalation detection
278
- - `no-weak-password-recovery` - Secure password reset enforcement
279
-
280
- #### Session & Cookies (3 rules)
281
-
282
- - `no-insecure-cookie-settings` - Cookie security enforcement
283
- - `no-missing-csrf-protection` - CSRF protection enforcement
284
- - `no-document-cookie` - Direct cookie access detection
285
-
286
- #### Network & Headers (5 rules)
287
-
288
- - `no-missing-cors-check` - CORS validation enforcement
289
- - `no-missing-security-headers` - Security header enforcement
290
- - `no-insecure-redirects` - Open redirect prevention
291
- - `no-unencrypted-transmission` - HTTPS enforcement
292
- - `no-clickjacking` - Clickjacking prevention
293
-
294
- #### Data Exposure (2 rules)
295
-
296
- - `no-exposed-sensitive-data` - Data exposure prevention
297
- - `no-sensitive-data-exposure` - Log sanitization enforcement
298
-
299
- #### Buffer & Memory (1 rule)
300
-
301
- - `no-buffer-overread` - Buffer safety enforcement
302
-
303
- #### DoS & Resource (2 rules)
304
-
305
- - `no-unlimited-resource-allocation` - Resource limit enforcement
306
- - `no-unchecked-loop-condition` - Infinite loop prevention
307
-
308
- #### Platform-Specific (2 rules)
309
-
310
- - `no-electron-security-issues` - Electron security enforcement
311
- - `no-insufficient-postmessage-validation` - postMessage validation