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,14 +1,8 @@
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.detectNonLiteralRegexp = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- // Type guard for regex literal nodes
12
6
  const isRegExpLiteral = (node) => {
13
7
  return node.type === 'Literal' && Object.prototype.hasOwnProperty.call(node, 'regex');
14
8
  };
@@ -32,7 +26,6 @@ const REGEXP_PATTERNS = [
32
26
  safeAlternative: 'Static RegExp literals or validated patterns',
33
27
  example: {
34
28
  bad: 'RegExp(userPattern)',
35
- // oxlint-disable-next-line no-template-curly-in-string
36
29
  good: 'const safePattern = userPattern.replace(/[.*+?^${}()|[\\]\\\\]/g, \'\\\\$&\'); new RegExp(`^${safePattern}$`)'
37
30
  },
38
31
  effort: '15-20 minutes',
@@ -44,8 +37,8 @@ const REGEXP_PATTERNS = [
44
37
  vulnerability: 'redos',
45
38
  safeAlternative: 'Avoid nested quantifiers, use atomic groups',
46
39
  example: {
47
- bad: '/(a+)+b/', // ReDoS vulnerable
48
- good: '/(?>a+)b/', // Atomic group (if supported) or restructure
40
+ bad: '/(a+)+b/',
41
+ good: '/(?>a+)b/',
49
42
  },
50
43
  effort: '20-30 minutes',
51
44
  riskLevel: 'critical'
@@ -61,7 +54,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
61
54
  cwe: 'CWE-400',
62
55
  },
63
56
  messages: {
64
- // 🎯 Token optimization: 41% reduction (51→30 tokens) - compact template variables
65
57
  regexpReDoS: (0, eslint_devkit_1.formatLLMMessage)({
66
58
  icon: eslint_devkit_1.MessageIcons.WARNING,
67
59
  issueName: 'ReDoS vulnerability',
@@ -107,9 +99,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
107
99
  icon: eslint_devkit_1.MessageIcons.INFO,
108
100
  issueName: 'Escape Input',
109
101
  description: 'Escape special regex characters',
110
- // oxlint-disable-next-line no-template-curly-in-string
111
102
  severity: 'LOW',
112
- // oxlint-disable-next-line no-template-curly-in-string
113
103
  fix: 'input.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&")',
114
104
  documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping',
115
105
  })
@@ -149,35 +139,20 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
149
139
  ],
150
140
  create(context) {
151
141
  const options = context.options[0] || {};
152
- // `options` is always an object here (defaulted just above), so a
153
- // second `|| {}` fallback could never fire — removed as dead code.
154
142
  const { allowLiterals = false, maxPatternLength = 100, } = options;
155
- /**
156
- * Check if a node is a literal string (potentially safe)
157
- * Includes template literals without expressions
158
- */
159
- // oxlint-disable-next-line consistent-function-scoping
160
143
  const isLiteralString = (node) => {
161
144
  if (node.type === 'Literal' && typeof node.value === 'string') {
162
145
  return true;
163
146
  }
164
- // Template literals without expressions are also static/safe
165
147
  if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {
166
148
  return true;
167
149
  }
168
150
  return false;
169
151
  };
170
- /**
171
- * Check if a regex pattern contains dangerous ReDoS patterns
172
- * Only flag truly dangerous patterns like nested quantifiers: (a+)+, (a*)*
173
- */
174
- // oxlint-disable-next-line consistent-function-scoping
175
152
  const hasReDoSPatterns = (pattern) => {
176
- // Detect truly dangerous nested quantifier patterns that cause exponential backtracking
177
- // Pattern like (a+)+, (a*)+, (a+)*, (a*)*, ([a-z]+)+
178
153
  const nestedQuantifierPatterns = [
179
- /\([^)]*[+*]\)[+*]/, // (something+)+ or (something*)* patterns
180
- /\([^)]*[+*]\)\{[0-9,]+\}/, // (something+){n,m} patterns
154
+ /\([^)]*[+*]\)[+*]/,
155
+ /\([^)]*[+*]\)\{[0-9,]+\}/,
181
156
  ];
182
157
  for (const dangerousPattern of nestedQuantifierPatterns) {
183
158
  if (dangerousPattern.test(pattern)) {
@@ -186,17 +161,12 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
186
161
  }
187
162
  return false;
188
163
  };
189
- /**
190
- * Extract regex pattern from RegExp construction
191
- */
192
164
  const extractPattern = (node) => {
193
165
  const sourceCode = context.sourceCode;
194
- // Determine constructor type
195
166
  let constructor = 'RegExp';
196
167
  if (node.type === 'NewExpression' && node.callee.type === 'Identifier') {
197
168
  constructor = `new ${node.callee.name}`;
198
169
  }
199
- // First argument is the pattern
200
170
  const patternNode = node.arguments.length > 0 ? node.arguments[0] : null;
201
171
  const pattern = patternNode ? sourceCode.getText(patternNode) : '';
202
172
  const isDynamic = patternNode ? !isLiteralString(patternNode) : false;
@@ -204,18 +174,13 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
204
174
  String(patternNode.value).length : pattern.length;
205
175
  return { pattern, patternNode, constructor, isDynamic, length };
206
176
  };
207
- /**
208
- * Detect the specific vulnerability pattern
209
- */
210
177
  const detectVulnerability = (pattern, isDynamic) => {
211
- // Check for dynamic construction first (highest risk)
212
178
  if (isDynamic) {
213
179
  for (const vuln of REGEXP_PATTERNS) {
214
180
  if (new RegExp(vuln.pattern, 'i').test(pattern)) {
215
181
  return vuln;
216
182
  }
217
183
  }
218
- // Generic dynamic RegExp construction
219
184
  return {
220
185
  pattern: 'dynamic',
221
186
  dangerous: true,
@@ -229,7 +194,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
229
194
  riskLevel: 'high'
230
195
  };
231
196
  }
232
- // Check for ReDoS patterns in literal regex
233
197
  if (hasReDoSPatterns(pattern)) {
234
198
  return {
235
199
  pattern: 'redos-literal',
@@ -238,7 +202,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
238
202
  safeAlternative: 'Restructure regex to avoid nested quantifiers',
239
203
  example: {
240
204
  bad: pattern,
241
- good: pattern.replace(/(a+)\+/g, '$1') // Simplified example
205
+ good: pattern.replace(/(a+)\+/g, '$1')
242
206
  },
243
207
  effort: '20-30 minutes',
244
208
  riskLevel: 'high'
@@ -246,10 +210,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
246
210
  }
247
211
  return null;
248
212
  };
249
- /**
250
- * Generate refactoring steps based on the vulnerability
251
- */
252
- // oxlint-disable-next-line consistent-function-scoping
253
213
  const generateRefactoringSteps = (vulnerability) => {
254
214
  if (vulnerability.pattern === 'dynamic') {
255
215
  return [
@@ -269,12 +229,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
269
229
  ' 5. Consider alternatives like string methods'
270
230
  ].join('\n');
271
231
  }
272
- // Every `RegExpPattern` constructed in this module has
273
- // `vulnerability: 'redos'` (see REGEXP_PATTERNS above and the two
274
- // object literals returned from `detectVulnerability`) — there is no
275
- // code path that ever produces `'injection'` or another value, so
276
- // this is the only reachable case. Kept as a direct return (not a
277
- // switch) to avoid unreachable branches that no test could ever hit.
278
232
  return [
279
233
  ' 1. Avoid nested quantifiers and backreferences',
280
234
  ' 2. Use possessive quantifiers: *+, ++, ?+',
@@ -283,44 +237,25 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
283
237
  ' 5. Consider safe-regex library validation'
284
238
  ].join('\n');
285
239
  };
286
- /**
287
- * Determine overall risk level
288
- */
289
- // Every `RegExpPattern` ever constructed in this module (REGEXP_PATTERNS
290
- // entries, and the two object literals in `detectVulnerability`) sets
291
- // `riskLevel` to only `'high'` or `'critical'` — never `'medium'` or
292
- // `'low'` — so those two branches are the only reachable outcomes.
293
240
  const determineRiskLevel = (vulnerability, pattern) => {
294
241
  if (vulnerability.riskLevel === 'critical' || hasReDoSPatterns(pattern)) {
295
242
  return 'CRITICAL';
296
243
  }
297
244
  return 'HIGH';
298
245
  };
299
- /**
300
- * Check RegExp constructor calls for vulnerabilities
301
- */
302
246
  const checkRegExpCall = (node) => {
303
- // Check for RegExp constructor calls
304
247
  const isRegExpCall = node.callee.type === 'Identifier' && node.callee.name === 'RegExp';
305
248
  const isNewRegExp = node.type === 'NewExpression' && node.callee.type === 'Identifier' && node.callee.name === 'RegExp';
306
249
  if (!isRegExpCall && !isNewRegExp) {
307
250
  return;
308
251
  }
309
252
  const { pattern, patternNode, isDynamic, length } = extractPattern(node);
310
- // Allow literals if configured and pattern is reasonable length
311
253
  if (allowLiterals && patternNode && isLiteralString(patternNode) && length <= maxPatternLength) {
312
- // Still check for ReDoS patterns even in literals
313
254
  if (!hasReDoSPatterns(pattern)) {
314
255
  return;
315
256
  }
316
257
  }
317
258
  const vulnerability = detectVulnerability(pattern, isDynamic);
318
- // `detectVulnerability` always returns non-null when `isDynamic` is
319
- // true (either a matched REGEXP_PATTERNS entry or its own generic
320
- // "dynamic" object), so `vulnerability` can only be null when
321
- // `isDynamic` is false — meaning a synthetic `isDynamic ? {...} :
322
- // null` fallback here could never construct the object literal it
323
- // used to; it always reduced to `null`. Removed as dead code.
324
259
  const effectiveVulnerability = vulnerability;
325
260
  if (!effectiveVulnerability) {
326
261
  return;
@@ -362,20 +297,11 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
362
297
  ]
363
298
  });
364
299
  };
365
- /**
366
- * Check literal regex patterns for ReDoS vulnerabilities
367
- */
368
300
  const checkLiteralRegExp = (node) => {
369
301
  if (!isRegExpLiteral(node)) {
370
302
  return;
371
303
  }
372
304
  const pattern = node.regex.pattern;
373
- // Check for ReDoS patterns. `detectVulnerability(pattern, false)`
374
- // re-tests the identical `hasReDoSPatterns(pattern)` condition just
375
- // checked above (see its `isDynamic === false` branch) and always
376
- // returns non-null when that's true — so `vulnerability` here can
377
- // never be null. No `if (vulnerability)` guard, to avoid an
378
- // unreachable false branch.
379
305
  if (hasReDoSPatterns(pattern)) {
380
306
  const vulnerability = detectVulnerability(pattern, false);
381
307
  const riskLevel = determineRiskLevel(vulnerability, pattern);