eslint-plugin-secure-coding 3.4.0 → 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 (64) hide show
  1. package/package.json +5 -18
  2. package/src/index.d.ts +17 -23
  3. package/src/index.js +2 -131
  4. package/src/oxlint.d.ts +17 -20
  5. package/src/oxlint.js +0 -18
  6. package/src/rules/detect-non-literal-regexp/index.js +5 -79
  7. package/src/rules/detect-object-injection/index.js +2 -221
  8. package/src/rules/detect-weak-password-validation/index.js +0 -12
  9. package/src/rules/no-directive-injection/index.js +0 -33
  10. package/src/rules/no-electron-security-issues/index.js +0 -41
  11. package/src/rules/no-format-string-injection/index.js +0 -82
  12. package/src/rules/no-graphql-injection/index.js +8 -133
  13. package/src/rules/no-hardcoded-credentials/index.js +3 -297
  14. package/src/rules/no-hardcoded-session-tokens/index.js +0 -11
  15. package/src/rules/no-improper-sanitization/index.js +0 -44
  16. package/src/rules/no-improper-type-validation/index.js +1 -51
  17. package/src/rules/no-insecure-comparison/index.js +2 -43
  18. package/src/rules/no-ldap-injection/index.js +8 -61
  19. package/src/rules/no-missing-authentication/index.js +2 -56
  20. package/src/rules/no-pii-in-logs/index.js +0 -13
  21. package/src/rules/no-privilege-escalation/index.js +2 -49
  22. package/src/rules/no-redos-vulnerable-regex/index.js +3 -49
  23. package/src/rules/no-sensitive-data-exposure/index.js +5 -29
  24. package/src/rules/no-template-injection/index.js +0 -6
  25. package/src/rules/no-unchecked-loop-condition/index.js +3 -99
  26. package/src/rules/no-unlimited-resource-allocation/index.js +2 -75
  27. package/src/rules/no-unsafe-deserialization/index.js +1 -111
  28. package/src/rules/no-unsafe-regex-construction/index.js +22 -62
  29. package/src/rules/no-weak-password-recovery/index.js +0 -43
  30. package/src/rules/no-xpath-injection/index.js +13 -75
  31. package/src/rules/no-xxe-injection/index.js +1 -47
  32. package/src/rules/require-backend-authorization/index.js +0 -10
  33. package/src/rules/require-secure-defaults/index.js +0 -10
  34. package/src/types/index.js +0 -5
  35. package/AGENTS.md +0 -131
  36. package/CHANGELOG.md +0 -379
  37. package/src/rules/detect-non-literal-regexp/index.d.ts +0 -28
  38. package/src/rules/detect-object-injection/index.d.ts +0 -35
  39. package/src/rules/detect-weak-password-validation/index.d.ts +0 -12
  40. package/src/rules/no-directive-injection/index.d.ts +0 -38
  41. package/src/rules/no-electron-security-issues/index.d.ts +0 -36
  42. package/src/rules/no-format-string-injection/index.d.ts +0 -44
  43. package/src/rules/no-graphql-injection/index.d.ts +0 -47
  44. package/src/rules/no-hardcoded-credentials/index.d.ts +0 -95
  45. package/src/rules/no-hardcoded-session-tokens/index.d.ts +0 -12
  46. package/src/rules/no-improper-sanitization/index.d.ts +0 -38
  47. package/src/rules/no-improper-type-validation/index.d.ts +0 -36
  48. package/src/rules/no-insecure-comparison/index.d.ts +0 -26
  49. package/src/rules/no-ldap-injection/index.d.ts +0 -53
  50. package/src/rules/no-missing-authentication/index.d.ts +0 -32
  51. package/src/rules/no-pii-in-logs/index.d.ts +0 -12
  52. package/src/rules/no-privilege-escalation/index.d.ts +0 -32
  53. package/src/rules/no-redos-vulnerable-regex/index.d.ts +0 -28
  54. package/src/rules/no-sensitive-data-exposure/index.d.ts +0 -30
  55. package/src/rules/no-template-injection/index.d.ts +0 -23
  56. package/src/rules/no-unchecked-loop-condition/index.d.ts +0 -38
  57. package/src/rules/no-unlimited-resource-allocation/index.d.ts +0 -38
  58. package/src/rules/no-unsafe-deserialization/index.d.ts +0 -40
  59. package/src/rules/no-unsafe-regex-construction/index.d.ts +0 -30
  60. package/src/rules/no-weak-password-recovery/index.d.ts +0 -38
  61. package/src/rules/no-xpath-injection/index.d.ts +0 -39
  62. package/src/rules/no-xxe-injection/index.d.ts +0 -36
  63. package/src/rules/require-backend-authorization/index.d.ts +0 -12
  64. 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`