eslint-plugin-secure-coding 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +13 -45
  2. package/README.md +77 -55
  3. package/package.json +18 -3
  4. package/src/index.js +39 -6
  5. package/src/oxlint.d.ts +20 -0
  6. package/src/oxlint.js +21 -0
  7. package/src/rules/detect-non-literal-regexp/index.js +9 -1
  8. package/src/rules/detect-object-injection/index.js +169 -3
  9. package/src/rules/detect-weak-password-validation/index.js +3 -0
  10. package/src/rules/no-directive-injection/index.js +7 -3
  11. package/src/rules/no-electron-security-issues/index.js +6 -1
  12. package/src/rules/no-format-string-injection/index.js +32 -23
  13. package/src/rules/no-graphql-injection/index.js +8 -2
  14. package/src/rules/no-hardcoded-credentials/index.js +343 -51
  15. package/src/rules/no-hardcoded-session-tokens/index.js +3 -0
  16. package/src/rules/no-improper-sanitization/index.js +31 -3
  17. package/src/rules/no-improper-type-validation/index.js +6 -3
  18. package/src/rules/no-insecure-comparison/index.js +38 -2
  19. package/src/rules/no-ldap-injection/index.js +6 -2
  20. package/src/rules/no-missing-authentication/index.js +5 -2
  21. package/src/rules/no-pii-in-logs/index.js +3 -0
  22. package/src/rules/no-privilege-escalation/index.js +5 -2
  23. package/src/rules/no-redos-vulnerable-regex/index.js +79 -0
  24. package/src/rules/no-sensitive-data-exposure/index.js +3 -0
  25. package/src/rules/no-unchecked-loop-condition/index.js +5 -2
  26. package/src/rules/no-unlimited-resource-allocation/index.js +9 -8
  27. package/src/rules/no-unsafe-deserialization/index.js +7 -5
  28. package/src/rules/no-unsafe-regex-construction/index.js +10 -3
  29. package/src/rules/no-weak-password-recovery/index.js +5 -2
  30. package/src/rules/no-xpath-injection/index.js +6 -2
  31. package/src/rules/no-xxe-injection/index.js +48 -46
  32. package/src/rules/require-backend-authorization/index.js +6 -3
  33. package/src/rules/require-secure-defaults/index.js +3 -0
@@ -14,7 +14,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-ldap-injection.md',
17
18
  description: 'Detects LDAP injection vulnerabilities',
19
+ cwe: 'CWE-90',
18
20
  },
19
21
  fixable: 'code',
20
22
  hasSuggestions: true,
@@ -158,8 +160,8 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
158
160
  create(context) {
159
161
  const options = context.options[0] || {};
160
162
  const { ldapFunctions = ['search', 'bind', 'modify', 'add', 'delete', 'compare', 'searchAsync'], ldapEscapeFunctions = ['escape.filterValue', 'escape.dnValue', 'filterEscape', 'dnEscape'], ldapValidationFunctions = ['validateLdapInput', 'sanitizeLdapFilter', 'cleanLdapValue', 'checkLdapFilter'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
161
- const sourceCode = context.sourceCode || context.sourceCode;
162
- const filename = context.filename || context.filename;
163
+ const sourceCode = context.sourceCode;
164
+ const filename = context.filename;
163
165
  // Create safety checker for false positive detection
164
166
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
165
167
  trustedSanitizers,
@@ -183,6 +185,7 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
183
185
  /**
184
186
  * Check if LDAP filter contains dangerous patterns
185
187
  */
188
+ // oxlint-disable-next-line consistent-function-scoping
186
189
  const containsDangerousLdapFilter = (filterText) => {
187
190
  // Dangerous LDAP filter patterns
188
191
  const dangerousPatterns = [
@@ -199,6 +202,7 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
199
202
  /**
200
203
  * Check if string contains LDAP filter interpolation
201
204
  */
205
+ // oxlint-disable-next-line consistent-function-scoping
202
206
  const containsLdapInterpolation = (text) => {
203
207
  return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
204
208
  };
@@ -108,7 +108,10 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
108
108
  meta: {
109
109
  type: 'problem',
110
110
  docs: {
111
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-missing-authentication.md',
111
112
  description: 'Detects missing authentication checks in route handlers',
113
+ cwe: 'CWE-287',
114
+ cvss: 9.5,
112
115
  },
113
116
  hasSuggestions: true,
114
117
  messages: {
@@ -178,10 +181,10 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
178
181
  ],
179
182
  create(context, [options = {}]) {
180
183
  const { allowInTests = false, testFilePattern = '\\.(test|spec)\\.(ts|tsx|js|jsx)$', authMiddlewarePatterns = DEFAULT_AUTH_MIDDLEWARE_PATTERNS, routeHandlerPatterns = DEFAULT_ROUTE_HANDLER_PATTERNS, ignorePatterns = [], } = options;
181
- const filename = context.getFilename();
184
+ const filename = context.filename;
182
185
  const testFileRegex = new RegExp(testFilePattern);
183
186
  const isTestFile = allowInTests && testFileRegex.test(filename);
184
- const sourceCode = context.sourceCode || context.sourceCode;
187
+ const sourceCode = context.sourceCode;
185
188
  /**
186
189
  * Find variable declaration for an identifier
187
190
  */
@@ -17,7 +17,10 @@ exports.noPiiInLogs = (0, eslint_devkit_1.createRule)({
17
17
  meta: {
18
18
  type: 'problem',
19
19
  docs: {
20
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-pii-in-logs.md',
20
21
  description: 'Prevent PII (email, SSN, credit cards) in console logs',
22
+ cwe: 'CWE-359',
23
+ cvss: 7.5,
21
24
  },
22
25
  messages: {
23
26
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -108,7 +108,10 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
108
108
  meta: {
109
109
  type: 'problem',
110
110
  docs: {
111
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-privilege-escalation.md',
111
112
  description: 'Detects potential privilege escalation vulnerabilities',
113
+ cwe: 'CWE-269',
114
+ cvss: 7.5,
112
115
  },
113
116
  hasSuggestions: true,
114
117
  messages: {
@@ -178,10 +181,10 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
178
181
  ],
179
182
  create(context, [options = {}]) {
180
183
  const { allowInTests = false, testFilePattern = '\\.(test|spec)\\.(ts|tsx|js|jsx)$', roleCheckPatterns = DEFAULT_ROLE_CHECK_PATTERNS, userInputPatterns: additionalUserInputPatterns = [], ignorePatterns = [], } = options;
181
- const filename = context.getFilename();
184
+ const filename = context.filename;
182
185
  const testFileRegex = new RegExp(testFilePattern);
183
186
  const isTestFile = allowInTests && testFileRegex.test(filename);
184
- const sourceCode = context.sourceCode || context.sourceCode;
187
+ const sourceCode = context.sourceCode;
185
188
  // Combine default and additional user input patterns
186
189
  const userInputPatterns = [
187
190
  ...DEFAULT_USER_INPUT_PATTERNS,
@@ -8,6 +8,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.noRedosVulnerableRegex = void 0;
9
9
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
10
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ const regexpp_1 = require("@eslint-community/regexpp");
12
+ const scslre_1 = require("scslre");
13
+ // Module-level parser; cheap to reuse.
14
+ const REGEXPP_PARSER = new regexpp_1.RegExpParser();
11
15
  // Type guard for regex literal nodes
12
16
  const isRegExpLiteral = (node) => {
13
17
  return node.type === 'Literal' && Object.prototype.hasOwnProperty.call(node, 'regex');
@@ -127,7 +131,9 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
127
131
  meta: {
128
132
  type: 'problem',
129
133
  docs: {
134
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-redos-vulnerable-regex.md',
130
135
  description: 'Detects ReDoS-vulnerable regex patterns in literal regex patterns',
136
+ cwe: 'CWE-400',
131
137
  },
132
138
  hasSuggestions: true,
133
139
  messages: {
@@ -201,6 +207,43 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
201
207
  ],
202
208
  create(context, [options = {}]) {
203
209
  const { allowCommonPatterns = false, maxPatternLength = 500 } = options || {};
210
+ /**
211
+ * NFA-based ReDoS detection via scslre — the same library used by
212
+ * eslint-plugin-regexp. Catches patterns that the heuristic regex
213
+ * pattern matching can't see (cross-quantifier "trade" issues, deep
214
+ * nested loops, etc.). Heuristic detection runs as a fallback for
215
+ * cases where parsing fails or the pattern is exotic.
216
+ */
217
+ function checkWithScslre(node, pattern, flags) {
218
+ try {
219
+ const ast = REGEXPP_PARSER.parsePattern(pattern, 0, pattern.length, { unicode: flags.includes('u'), unicodeSets: flags.includes('v') });
220
+ const result = (0, scslre_1.analyse)({ pattern: ast, flags: { ignoreCase: flags.includes('i'), unicode: flags.includes('u'), dotAll: flags.includes('s'), multiline: flags.includes('m') } }, { reportTypes: { Move: false } });
221
+ if (result.reports.length === 0)
222
+ return false;
223
+ for (const report of result.reports) {
224
+ const isExp = report.exponential;
225
+ context.report({
226
+ node,
227
+ messageId: 'redosVulnerable',
228
+ data: {
229
+ vulnerabilityName: report.type === 'Self'
230
+ ? `Self-loop quantifier (${isExp ? 'exponential' : 'polynomial'} backtracking)`
231
+ : `Cross-quantifier trade (${isExp ? 'exponential' : 'polynomial'} backtracking)`,
232
+ description: report.type === 'Self'
233
+ ? `A quantifier reaches itself via the parent loop. An attacker can craft input that triggers ${isExp ? 'exponential' : 'polynomial'} backtracking.`
234
+ : `Two quantifiers can exchange characters, enabling ${isExp ? 'exponential' : 'polynomial'} backtracking on crafted input.`,
235
+ severity: isExp ? 'CRITICAL' : 'HIGH',
236
+ fix: 'Atomic group, possessive quantifier, or rewrite to eliminate the ambiguity. The scslre auto-suggested fix may be available.',
237
+ },
238
+ });
239
+ }
240
+ return true;
241
+ }
242
+ catch {
243
+ // Fall through to heuristic check
244
+ return false;
245
+ }
246
+ }
204
247
  /**
205
248
  * Check literal regex patterns for ReDoS vulnerabilities
206
249
  */
@@ -209,10 +252,15 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
209
252
  return;
210
253
  }
211
254
  const pattern = node.regex.pattern;
255
+ const flags = node.regex.flags || '';
212
256
  // Skip if pattern is too long (performance)
213
257
  if (pattern.length > maxPatternLength) {
214
258
  return;
215
259
  }
260
+ // NFA-based detection first — catches what heuristics miss.
261
+ if (checkWithScslre(node, pattern, flags)) {
262
+ return;
263
+ }
216
264
  const vulnerability = hasReDoSVulnerability(pattern);
217
265
  if (!vulnerability) {
218
266
  return;
@@ -265,6 +313,37 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
265
313
  return;
266
314
  }
267
315
  const firstArg = node.arguments[0];
316
+ // Template literal with interpolation — runtime-built pattern.
317
+ // Closes the audit FN where `new RegExp(\`^(\${pattern}+)+$\`)` was
318
+ // bypassing detection. We can't fully analyse the resulting regex
319
+ // (the interpolated parts are user-controlled), but we CAN detect
320
+ // the nested-quantifier signature `+)+`/`+)*`/`*)+`/`*)*` in the
321
+ // static template text — that shape is catastrophic regardless of
322
+ // what the interpolation injects. See benchmarks/AUDIT_PATTERNS.md
323
+ // §3.5 ("Runtime-built patterns").
324
+ if (firstArg.type === 'TemplateLiteral' && firstArg.expressions.length > 0) {
325
+ const concatenated = firstArg.quasis
326
+ .map((q) => q.value.cooked ?? q.value.raw)
327
+ .join(''); // sentinel between static parts
328
+ // Look for the nested-quantifier signature on either side of an
329
+ // interpolation: `+)+`, `+)*`, `*)+`, `*)*`, `})+` etc.
330
+ const hasNestedQuantifier = /[+*}](?:\)\s*[+*]|\)\s*\{\s*\d+\s*,?\s*\d*\s*\}|\s*[+*])/.test(concatenated) ||
331
+ /[+*].*\)[+*]/.test(concatenated) ||
332
+ /\([+*]\)[+*]/.test(concatenated);
333
+ if (hasNestedQuantifier) {
334
+ context.report({
335
+ node,
336
+ messageId: 'redosVulnerable',
337
+ data: {
338
+ vulnerabilityName: 'Runtime-built nested quantifier',
339
+ description: 'Template-literal pattern interpolation places user input inside a nested-quantifier shape (`(...+)+` / `(...*)*`); this is catastrophic regardless of what the interpolation injects.',
340
+ severity: 'HIGH',
341
+ fix: 'Avoid runtime-built nested quantifiers. Build the pattern at module load time and validate; or constrain the interpolated section to a non-quantifier region.',
342
+ },
343
+ });
344
+ }
345
+ return;
346
+ }
268
347
  if (firstArg.type !== 'Literal' || typeof firstArg.value !== 'string') {
269
348
  /* c8 ignore next */
270
349
  return;
@@ -32,7 +32,10 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
32
32
  meta: {
33
33
  type: 'problem',
34
34
  docs: {
35
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-sensitive-data-exposure.md',
35
36
  description: 'Detects PII/credentials in logs, responses, or error messages',
37
+ cwe: 'CWE-532',
38
+ cvss: 7.5,
36
39
  },
37
40
  hasSuggestions: true,
38
41
  messages: {
@@ -14,7 +14,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-unchecked-loop-condition.md',
17
18
  description: 'Detects unchecked loop conditions that could cause DoS',
19
+ cwe: 'CWE-400',
18
20
  },
19
21
  fixable: 'code',
20
22
  hasSuggestions: true,
@@ -141,8 +143,8 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
141
143
  create(context) {
142
144
  const options = context.options[0] || {};
143
145
  const { maxStaticIterations = 10000, userInputVariables = ['req', 'request', 'body', 'query', 'params', 'input', 'data'], allowWhileTrueWithBreak = true, maxRecursionDepth = 10, trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
144
- const sourceCode = context.sourceCode || context.sourceCode;
145
- const filename = context.filename || context.getFilename();
146
+ const sourceCode = context.sourceCode;
147
+ const filename = context.filename;
146
148
  // Create safety checker for false positive detection
147
149
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
148
150
  trustedSanitizers,
@@ -322,6 +324,7 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
322
324
  /**
323
325
  * Estimate loop iterations from static analysis
324
326
  */
327
+ // oxlint-disable-next-line consistent-function-scoping
325
328
  const estimateIterations = (loop) => {
326
329
  if (loop.type === 'ForStatement') {
327
330
  // Try to parse for loop bounds
@@ -14,7 +14,9 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-unlimited-resource-allocation.md',
17
18
  description: 'Detects unlimited resource allocation that could cause DoS',
19
+ cwe: 'CWE-770',
18
20
  },
19
21
  fixable: 'code',
20
22
  hasSuggestions: true,
@@ -199,8 +201,8 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
199
201
  create(context) {
200
202
  const options = context.options[0] || {};
201
203
  const { maxResourceSize = 1048576, userInputVariables = ['req', 'request', 'body', 'query', 'params', 'input', 'data'], safeResourceFunctions = ['validateSize', 'checkLimits', 'limitResource', 'safeAlloc'], requireResourceValidation = true, trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
202
- const sourceCode = context.sourceCode || context.sourceCode;
203
- const filename = context.filename || context.getFilename();
204
+ const sourceCode = context.sourceCode;
205
+ const filename = context.filename;
204
206
  // Create safety checker for false positive detection
205
207
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
206
208
  trustedSanitizers,
@@ -502,7 +504,6 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
502
504
  /* c8 ignore stop */
503
505
  // Check for resource allocation inside loops
504
506
  if ((0, eslint_devkit_3.isInsideLoop)(node)) {
505
- const calleeText = sourceCode.getText(callee);
506
507
  // Check if this allocates resources
507
508
  if (calleeText.includes('alloc') ||
508
509
  calleeText.includes('Array') ||
@@ -621,12 +622,12 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
621
622
  }
622
623
  // Check for resource allocation inside loops
623
624
  if ((0, eslint_devkit_3.isInsideLoop)(node)) {
624
- const calleeText = sourceCode.getText(callee);
625
625
  // Check if this allocates resources
626
- if (calleeText.includes('Buffer') ||
627
- calleeText.includes('Array') ||
628
- calleeText.includes('Map') ||
629
- calleeText.includes('Set')) {
626
+ const newCalleeText = sourceCode.getText(callee);
627
+ if (newCalleeText.includes('Buffer') ||
628
+ newCalleeText.includes('Array') ||
629
+ newCalleeText.includes('Map') ||
630
+ newCalleeText.includes('Set')) {
630
631
  /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
631
632
  if (safetyChecker.isSafe(node, context)) {
632
633
  return;
@@ -14,7 +14,9 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-unsafe-deserialization.md',
17
18
  description: 'Detects unsafe deserialization of untrusted data',
19
+ cwe: 'CWE-502',
18
20
  },
19
21
  fixable: 'code',
20
22
  hasSuggestions: true,
@@ -167,8 +169,8 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
167
169
  create(context) {
168
170
  const options = context.options[0] || {};
169
171
  const { dangerousFunctions = ['eval', 'Function', 'setTimeout', 'setInterval', 'unserialize', 'deserialize', 'parseUnsafe'], validationFunctions = ['validateInput', 'sanitizeData', 'checkSchema', 'validateSchema'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
170
- const sourceCode = context.sourceCode || context.sourceCode;
171
- const filename = context.filename || context.getFilename();
172
+ const sourceCode = context.sourceCode;
173
+ const filename = context.filename;
172
174
  // Create safety checker for false positive detection
173
175
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
174
176
  trustedSanitizers,
@@ -277,6 +279,7 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
277
279
  /**
278
280
  * Check if this is a safe deserialization library
279
281
  */
282
+ // oxlint-disable-next-line consistent-function-scoping
280
283
  const isSafeLibrary = (node) => {
281
284
  const callee = node.callee;
282
285
  if (callee.type === 'MemberExpression') {
@@ -309,7 +312,7 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
309
312
  node,
310
313
  messageId: 'dangerousFunctionConstructor',
311
314
  data: {
312
- filePath: context.getFilename(),
315
+ filePath: context.filename,
313
316
  line: String(node.loc?.start.line ?? 0),
314
317
  severity: 'HIGH',
315
318
  safeAlternative: 'Avoid dynamic function creation',
@@ -324,7 +327,6 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
324
327
  const hasUntrustedInput = args.some((arg) => isUntrustedInput(arg));
325
328
  // Check if explicit validation is present
326
329
  const isSafe = isSafeLibrary(node);
327
- const filename = context.getFilename();
328
330
  if (!isSafe && hasUntrustedInput) {
329
331
  // Basic safety check
330
332
  const safe = safetyChecker.isSafe(node, context);
@@ -381,7 +383,7 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
381
383
  node,
382
384
  messageId: 'untrustedDeserializationInput',
383
385
  data: {
384
- filePath: context.getFilename(),
386
+ filePath: context.filename,
385
387
  line: String(node.loc?.start.line ?? 0),
386
388
  },
387
389
  suggest: [
@@ -48,11 +48,14 @@ function isEscaped(node, trustedFunctions, sourceCode) {
48
48
  return true;
49
49
  }
50
50
  }
51
- // Also check if it's wrapped in a trusted function call (for complex cases)
51
+ // Also check if it's wrapped in a trusted function call (for complex cases).
52
+ // `current` is only assigned from `node` (truthy on entry) or `parent` after
53
+ // an explicit `if (!parent) break;`, so it's never null at the loop check
54
+ // (CodeQL: `js/useless-conditional` on the `current &&` test).
52
55
  let current = node;
53
56
  let depth = 0;
54
57
  const maxDepth = 5; // Prevent infinite loops
55
- while (current && depth < maxDepth) {
58
+ while (depth < maxDepth) {
56
59
  const parent = sourceCode.getNodeByRangeIndex?.(current.range[0] - 1) ||
57
60
  current.parent;
58
61
  if (!parent)
@@ -105,7 +108,10 @@ exports.noUnsafeRegexConstruction = (0, eslint_devkit_2.createRule)({
105
108
  meta: {
106
109
  type: 'problem',
107
110
  docs: {
111
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-unsafe-regex-construction.md',
108
112
  description: 'Detects unsafe regex construction patterns (user input without escaping, dynamic flags)',
113
+ cwe: 'CWE-400',
114
+ cvss: 7.5,
109
115
  },
110
116
  hasSuggestions: true,
111
117
  messages: {
@@ -123,6 +129,7 @@ exports.noUnsafeRegexConstruction = (0, eslint_devkit_2.createRule)({
123
129
  issueName: 'Escape User Input',
124
130
  description: 'Escape user input for regex',
125
131
  severity: 'LOW',
132
+ // oxlint-disable-next-line no-template-curly-in-string
126
133
  fix: 'input.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&")',
127
134
  documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping',
128
135
  }),
@@ -186,7 +193,7 @@ exports.noUnsafeRegexConstruction = (0, eslint_devkit_2.createRule)({
186
193
  ],
187
194
  create(context, [options = {}]) {
188
195
  const { allowLiterals = true, maxPatternLength = 100, trustedEscapingFunctions = ['escapeRegex', 'escape', 'sanitize'], } = options || {};
189
- const sourceCode = context.sourceCode || context.sourceCode;
196
+ const sourceCode = context.sourceCode;
190
197
  /**
191
198
  * Check RegExp constructor calls
192
199
  */
@@ -14,7 +14,9 @@ exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-weak-password-recovery.md',
17
18
  description: 'Detects weak password recovery mechanisms',
19
+ cwe: 'CWE-640',
18
20
  },
19
21
  fixable: 'code',
20
22
  hasSuggestions: true,
@@ -217,8 +219,8 @@ exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
217
219
  create(context) {
218
220
  const options = context.options[0] || {};
219
221
  const { secureTokenFunctions = ['crypto.randomBytes', 'crypto.randomUUID', 'randomBytes', 'generateSecureToken'], trustedSanitizers = [], trustedAnnotations = ['secure-recovery', 'rate-limited'], strictMode = false, } = options;
220
- const sourceCode = context.sourceCode || context.sourceCode;
221
- const filename = context.filename || context.getFilename();
222
+ const sourceCode = context.sourceCode;
223
+ const filename = context.filename;
222
224
  // Create safety checker for false positive detection
223
225
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
224
226
  trustedSanitizers,
@@ -233,6 +235,7 @@ exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
233
235
  * 1. Have password/forgot in the name
234
236
  * 2. AND have reset/recovery/forgot in the name
235
237
  */
238
+ // oxlint-disable-next-line consistent-function-scoping
236
239
  const isRecoveryRelated = (text) => {
237
240
  const lowerText = text.toLowerCase();
238
241
  // Require BOTH a password keyword AND a recovery action keyword
@@ -14,7 +14,9 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-xpath-injection.md',
17
18
  description: 'Detects XPath injection vulnerabilities',
19
+ cwe: 'CWE-643',
18
20
  },
19
21
  fixable: 'code',
20
22
  hasSuggestions: true,
@@ -158,8 +160,8 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
158
160
  create(context) {
159
161
  const options = context.options[0] || {};
160
162
  const { xpathFunctions = ['evaluate', 'selectSingleNode', 'selectNodes', 'xpath', 'select'], safeXpathConstructors = ['buildXPath', 'createXPath', 'safeXPath', 'xpathBuilder'], xpathValidationFunctions = ['validateXPath', 'escapeXPath', 'sanitizeXPath', 'cleanXPath'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
161
- const sourceCode = context.sourceCode || context.sourceCode;
162
- const filename = context.filename || context.getFilename();
163
+ const sourceCode = context.sourceCode;
164
+ const filename = context.filename;
163
165
  // Create safety checker for false positive detection
164
166
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
165
167
  trustedSanitizers,
@@ -189,6 +191,7 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
189
191
  /**
190
192
  * Check if XPath expression contains dangerous patterns
191
193
  */
194
+ // oxlint-disable-next-line consistent-function-scoping
192
195
  const containsDangerousXpath = (xpathText) => {
193
196
  // Dangerous XPath patterns that allow traversal or injection
194
197
  const dangerousPatterns = [
@@ -205,6 +208,7 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
205
208
  /**
206
209
  * Check if string contains XPath interpolation
207
210
  */
211
+ // oxlint-disable-next-line consistent-function-scoping
208
212
  const containsXpathInterpolation = (text) => {
209
213
  return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
210
214
  };
@@ -8,6 +8,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.noXxeInjection = void 0;
9
9
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
10
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ /**
12
+ * Check if this is an XML parsing operation
13
+ */
14
+ const isXmlParsingCall = (node) => {
15
+ const callee = node.callee;
16
+ // Check for XML library method calls
17
+ if (callee.type === 'MemberExpression' &&
18
+ callee.property.type === 'Identifier' &&
19
+ ['parse', 'parseFromString', 'parseString', 'parseXmlString', 'parseXML'].includes(callee.property.name)) {
20
+ return true;
21
+ }
22
+ // Check for constructor calls
23
+ if (callee.type === 'Identifier' &&
24
+ ['DOMParser', 'XMLHttpRequest', 'ActiveXObject'].includes(callee.name)) {
25
+ return true;
26
+ }
27
+ return false;
28
+ };
29
+ /**
30
+ * Check if parser options enable dangerous features
31
+ */
32
+ const hasDangerousParserOptions = (optionsNode) => {
33
+ if (optionsNode.type !== 'ObjectExpression') {
34
+ return false;
35
+ }
36
+ // Check for dangerous options
37
+ for (const prop of optionsNode.properties) {
38
+ if (prop.type === 'Property' &&
39
+ prop.key.type === 'Identifier' &&
40
+ ['resolveExternals', 'expandEntityReferences', 'noent'].includes(prop.key.name)) {
41
+ // Check if the value enables dangerous features
42
+ if (prop.value.type === 'Literal' && prop.value.value === true) {
43
+ return true;
44
+ }
45
+ }
46
+ }
47
+ return false;
48
+ };
49
+ /**
50
+ * Check if XML contains dangerous entity declarations
51
+ */
52
+ const containsDangerousEntities = (xmlText) => {
53
+ return /<!ENTITY/i.test(xmlText) &&
54
+ /SYSTEM\s+["']/i.test(xmlText);
55
+ };
11
56
  exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
12
57
  name: 'no-xxe-injection',
13
58
  meta: {
@@ -15,6 +60,8 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
15
60
  docs: {
16
61
  description: 'Detect XML External Entity (XXE) injection vulnerabilities',
17
62
  url: 'https://cwe.mitre.org/data/definitions/611.html',
63
+ cwe: 'CWE-611',
64
+ cvss: 9.5,
18
65
  },
19
66
  messages: {
20
67
  xxeInjection: (0, eslint_devkit_2.formatLLMMessage)({
@@ -79,25 +126,7 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
79
126
  ],
80
127
  create(context, [options]) {
81
128
  const { safeParserOptions = ['noent', 'resolveExternals', 'expandEntityReferences', 'entityResolver'], xmlValidationFunctions = ['validateXml', 'sanitizeXml', 'cleanXml', 'parseXmlSafe'], } = options || {};
82
- const filename = context.filename || context.getFilename();
83
- /**
84
- * Check if this is an XML parsing operation
85
- */
86
- const isXmlParsingCall = (node) => {
87
- const callee = node.callee;
88
- // Check for XML library method calls
89
- if (callee.type === 'MemberExpression' &&
90
- callee.property.type === 'Identifier' &&
91
- ['parse', 'parseFromString', 'parseString', 'parseXmlString', 'parseXML'].includes(callee.property.name)) {
92
- return true;
93
- }
94
- // Check for constructor calls
95
- if (callee.type === 'Identifier' &&
96
- ['DOMParser', 'XMLHttpRequest', 'ActiveXObject'].includes(callee.name)) {
97
- return true;
98
- }
99
- return false;
100
- };
129
+ const filename = context.filename;
101
130
  /**
102
131
  * Check if parser options are secure
103
132
  */
@@ -121,26 +150,6 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
121
150
  }
122
151
  return false;
123
152
  };
124
- /**
125
- * Check if parser options enable dangerous features
126
- */
127
- const hasDangerousParserOptions = (optionsNode) => {
128
- if (optionsNode.type !== 'ObjectExpression') {
129
- return false;
130
- }
131
- // Check for dangerous options
132
- for (const prop of optionsNode.properties) {
133
- if (prop.type === 'Property' &&
134
- prop.key.type === 'Identifier' &&
135
- ['resolveExternals', 'expandEntityReferences', 'noent'].includes(prop.key.name)) {
136
- // Check if the value enables dangerous features
137
- if (prop.value.type === 'Literal' && prop.value.value === true) {
138
- return true;
139
- }
140
- }
141
- }
142
- return false;
143
- };
144
153
  /**
145
154
  * Check if input has been validated
146
155
  */
@@ -157,13 +166,6 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
157
166
  }
158
167
  return false;
159
168
  };
160
- /**
161
- * Check if XML contains dangerous entity declarations
162
- */
163
- const containsDangerousEntities = (xmlText) => {
164
- return /<!ENTITY/i.test(xmlText) &&
165
- /SYSTEM\s+["']/i.test(xmlText);
166
- };
167
169
  /**
168
170
  * Check if input source is untrusted
169
171
  */
@@ -15,7 +15,10 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
15
15
  meta: {
16
16
  type: 'problem',
17
17
  docs: {
18
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/require-backend-authorization.md',
18
19
  description: 'Require server-side authorization checks',
20
+ cwe: 'CWE-602',
21
+ cvss: 9.5,
19
22
  },
20
23
  messages: {
21
24
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -35,7 +38,7 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
35
38
  function report(node) {
36
39
  context.report({ node, messageId: 'violationDetected' });
37
40
  }
38
- const authProperties = ['role', 'isAdmin', 'isAuthenticated', 'permissions', 'admin'];
41
+ const authProperties = new Set(['role', 'isAdmin', 'isAuthenticated', 'permissions', 'admin']);
39
42
  return {
40
43
  IfStatement(node) {
41
44
  // Detect role-based access in client-side if statements
@@ -43,7 +46,7 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
43
46
  const checkMember = (expr) => {
44
47
  if (expr.type === 'MemberExpression' &&
45
48
  expr.property.type === 'Identifier' &&
46
- authProperties.includes(expr.property.name)) {
49
+ authProperties.has(expr.property.name)) {
47
50
  return true;
48
51
  }
49
52
  return false;
@@ -56,7 +59,7 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
56
59
  // Check for user.role or user.isAdmin access
57
60
  if (node.test.type === 'MemberExpression' &&
58
61
  node.test.property.type === 'Identifier' &&
59
- authProperties.includes(node.test.property.name)) {
62
+ authProperties.has(node.test.property.name)) {
60
63
  report(node);
61
64
  }
62
65
  },
@@ -17,7 +17,10 @@ exports.requireSecureDefaults = (0, eslint_devkit_1.createRule)({
17
17
  meta: {
18
18
  type: 'problem',
19
19
  docs: {
20
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/require-secure-defaults.md',
20
21
  description: 'Ensure secure default configurations',
22
+ cwe: 'CWE-1188',
23
+ cvss: 5,
21
24
  },
22
25
  messages: {
23
26
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({