eslint-plugin-secure-coding 3.4.0 → 3.4.2

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 -2
  2. package/package.json +5 -18
  3. package/src/index.d.ts +17 -23
  4. package/src/index.js +2 -131
  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 +8 -133
  14. package/src/rules/no-hardcoded-credentials/index.js +3 -297
  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 +8 -47
  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 +1 -111
  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 -379
  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 -95
  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,9 +1,4 @@
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.noLdapInjection = void 0;
9
4
  exports.containsDangerousLdapFilter = containsDangerousLdapFilter;
@@ -11,31 +6,18 @@ exports.containsLdapInterpolation = containsLdapInterpolation;
11
6
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
12
7
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
13
8
  const eslint_devkit_3 = require("@interlace/eslint-devkit");
14
- /**
15
- * Check if LDAP filter contains dangerous patterns.
16
- *
17
- * Extracted to module scope (from inside `create()`) for direct unit
18
- * testability — this function is pure and captures no closure state.
19
- */
20
9
  function containsDangerousLdapFilter(filterText) {
21
- // Dangerous LDAP filter patterns
22
10
  const dangerousPatterns = [
23
- /\*\)$/, // Ending with *) to match everything
24
- /\|\)$/, // Ending with |) for OR operations
25
- /&\)$/, // Ending with &) for AND operations
26
- /!\)$/, // Ending with !) for NOT operations
27
- /\*\|\*/, // *|* pattern for matching everything
28
- /\*&\*/, // *&* pattern
29
- /\*!/, // NOT operations that could be exploited
11
+ /\*\)$/,
12
+ /\|\)$/,
13
+ /&\)$/,
14
+ /!\)$/,
15
+ /\*\|\*/,
16
+ /\*&\*/,
17
+ /\*!/,
30
18
  ];
31
19
  return dangerousPatterns.some(pattern => pattern.test(filterText));
32
20
  }
33
- /**
34
- * Check if string contains LDAP filter interpolation.
35
- *
36
- * Extracted to module scope (from inside `create()`) for direct unit
37
- * testability — this function is pure and captures no closure state.
38
- */
39
21
  function containsLdapInterpolation(text) {
40
22
  return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
41
23
  }
@@ -191,19 +173,14 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
191
173
  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;
192
174
  const sourceCode = context.sourceCode;
193
175
  const filename = context.filename;
194
- // Create safety checker for false positive detection
195
176
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
196
177
  trustedSanitizers,
197
178
  trustedAnnotations,
198
179
  trustedOrmPatterns: [],
199
180
  strictMode,
200
181
  });
201
- /**
202
- * Check if this is an LDAP-related operation
203
- */
204
182
  const isLdapOperation = (node) => {
205
183
  const callee = node.callee;
206
- // Check for LDAP method calls
207
184
  if (callee.type === 'MemberExpression' &&
208
185
  callee.property.type === 'Identifier' &&
209
186
  ldapFunctions.includes(callee.property.name)) {
@@ -211,18 +188,13 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
211
188
  }
212
189
  return false;
213
190
  };
214
- /**
215
- * Check if LDAP input is from untrusted source
216
- */
217
191
  const isUntrustedLdapInput = (inputNode) => {
218
- // Check member expressions like req.query.name, req.params.id, etc.
219
192
  if (inputNode.type === 'MemberExpression') {
220
193
  const fullName = sourceCode.getText(inputNode).toLowerCase();
221
194
  return fullName.includes('req.') || fullName.includes('request.') ||
222
195
  fullName.includes('query.') || fullName.includes('params.') ||
223
196
  fullName.includes('body.');
224
197
  }
225
- // In test contexts, also consider certain variable names as potentially untrusted
226
198
  if (inputNode.type === 'Identifier') {
227
199
  const varName = inputNode.name.toLowerCase();
228
200
  return ['userid', 'username', 'userinput', 'input', 'term', 'name', 'search', 'query', 'param', 'password', 'id', 'dn'].includes(varName) ||
@@ -231,15 +203,11 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
231
203
  }
232
204
  return false;
233
205
  };
234
- /**
235
- * Check if LDAP input has been escaped
236
- */
237
206
  const isLdapInputEscaped = (inputNode) => {
238
207
  let current = inputNode;
239
208
  while (current) {
240
209
  if (current.type === 'CallExpression') {
241
210
  const callee = current.callee;
242
- // Check for escape function calls
243
211
  if (callee.type === 'MemberExpression' &&
244
212
  callee.property.type === 'Identifier') {
245
213
  const propertyName = callee.property.name;
@@ -248,7 +216,6 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
248
216
  return true;
249
217
  }
250
218
  }
251
- // Check for validation function calls
252
219
  if (callee.type === 'Identifier' &&
253
220
  ldapValidationFunctions.includes(callee.name)) {
254
221
  return true;
@@ -259,18 +226,15 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
259
226
  return false;
260
227
  };
261
228
  return {
262
- // Check LDAP function calls
263
229
  CallExpression(node) {
264
230
  if (!isLdapOperation(node)) {
265
231
  return;
266
232
  }
267
233
  const args = node.arguments;
268
234
  if (args.length < 2) {
269
- return; // Need at least base DN and filter/options
235
+ return;
270
236
  }
271
- // Check filter argument (usually the second argument)
272
237
  const filterArg = args[1];
273
- // Check if filter argument comes from untrusted input (like req.query.filter)
274
238
  if (isUntrustedLdapInput(filterArg)) {
275
239
  if (safetyChecker.isSafe(filterArg, context)) {
276
240
  return;
@@ -291,12 +255,6 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
291
255
  });
292
256
  }
293
257
  else if (filterArg.type === 'TemplateLiteral' && filterArg.expressions.length > 0) {
294
- // Special handling for template literals with any expressions in LDAP calls
295
- // This is a more aggressive check for LDAP injection in function calls.
296
- // NOTE: the `expressions.length > 0` guard above already guarantees at
297
- // least one interpolated expression is present, so a further
298
- // `.some(() => true)` check was always trivially true and has been
299
- // removed as provably dead code (behavior-unchanged).
300
258
  if (safetyChecker.isSafe(filterArg, context)) {
301
259
  return;
302
260
  }
@@ -316,24 +274,20 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
316
274
  });
317
275
  }
318
276
  },
319
- // Check variable declarations with LDAP filters
320
277
  VariableDeclarator(node) {
321
278
  if (!node.init || node.id.type !== 'Identifier') {
322
279
  return;
323
280
  }
324
281
  const varName = node.id.name.toLowerCase();
325
- // Check if variable name suggests LDAP-related content
326
282
  const isLdapRelated = varName.includes('filter') || varName.includes('ldap') ||
327
283
  varName.includes('query') || varName.includes('search') ||
328
284
  varName.includes('dn') || varName.includes('bind');
329
- // If not obviously LDAP-related, check if the assigned value looks like LDAP
330
285
  if (!isLdapRelated && node.init) {
331
286
  const initText = sourceCode.getText(node.init);
332
287
  if (!initText.includes('(') || !initText.includes(')')) {
333
288
  return;
334
289
  }
335
290
  }
336
- // Check if assigned value contains dangerous LDAP patterns
337
291
  if (node.init.type === 'Literal' && typeof node.init.value === 'string') {
338
292
  if (containsDangerousLdapFilter(node.init.value)) {
339
293
  if (safetyChecker.isSafe(node.init, context)) {
@@ -350,11 +304,8 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
350
304
  }
351
305
  }
352
306
  else if (node.init.type === 'TemplateLiteral') {
353
- // Handle template literals with interpolation
354
307
  const fullText = sourceCode.getText(node.init);
355
- // Check for interpolation in LDAP-like expressions
356
308
  if (containsLdapInterpolation(fullText)) {
357
- // Check if any interpolated values are untrusted
358
309
  const hasUntrustedInterpolation = node.init.expressions.some((expr) => isUntrustedLdapInput(expr) && !isLdapInputEscaped(expr));
359
310
  if (hasUntrustedInterpolation) {
360
311
  if (safetyChecker.isSafe(node.init, context)) {
@@ -376,7 +327,6 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
376
327
  });
377
328
  }
378
329
  }
379
- // Check for dangerous patterns in template literals
380
330
  if (containsDangerousLdapFilter(fullText)) {
381
331
  if (safetyChecker.isSafe(node.init, context)) {
382
332
  return;
@@ -392,11 +342,8 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
392
342
  }
393
343
  }
394
344
  else if (node.init.type === 'BinaryExpression' && node.init.operator === '+') {
395
- // Handle string concatenation
396
345
  const fullText = sourceCode.getText(node.init);
397
- // Check if this looks like LDAP filter construction
398
346
  if (fullText.includes('(') && fullText.includes(')')) {
399
- // Check if untrusted input is involved (recursive check)
400
347
  const hasUntrustedInput = (expr) => {
401
348
  if (isUntrustedLdapInput(expr) && !isLdapInputEscaped(expr)) {
402
349
  return true;
@@ -1,16 +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.noMissingAuthentication = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- /**
12
- * Common authentication middleware patterns
13
- */
14
6
  const DEFAULT_AUTH_MIDDLEWARE_PATTERNS = [
15
7
  'authenticate',
16
8
  'auth',
@@ -23,9 +15,6 @@ const DEFAULT_AUTH_MIDDLEWARE_PATTERNS = [
23
15
  'jwt',
24
16
  'session',
25
17
  ];
26
- /**
27
- * Common route handler patterns
28
- */
29
18
  const DEFAULT_ROUTE_HANDLER_PATTERNS = [
30
19
  'get',
31
20
  'post',
@@ -35,38 +24,26 @@ const DEFAULT_ROUTE_HANDLER_PATTERNS = [
35
24
  'all',
36
25
  'use',
37
26
  ];
38
- /**
39
- * Check if a node is inside an authentication middleware call
40
- */
41
27
  function isInsideAuthMiddleware(node, sourceCode, authPatterns) {
42
28
  let current = node;
43
29
  while (current) {
44
- // Check if current is an argument to a CallExpression
45
30
  if (current.parent && current.parent.type === 'CallExpression') {
46
31
  const callExpr = current.parent;
47
- // Verify that current is actually an argument of this call
48
32
  const isArgument = callExpr.arguments.some((arg) => arg === current);
49
33
  if (!isArgument) {
50
- // Not an argument (e.g. `current` is the callee of this call, as in
51
- // an IIFE) - continue traversing upward. `current.parent` is
52
- // guaranteed truthy here because the enclosing `if` above already
53
- // proved it (it matched `current.parent.type === 'CallExpression'`).
54
34
  current = current.parent;
55
35
  continue;
56
36
  }
57
37
  const callee = callExpr.callee;
58
- // Check if it's an authentication middleware call
59
38
  if (callee.type === 'Identifier') {
60
39
  const calleeName = callee.name.toLowerCase();
61
40
  if (authPatterns.some(pattern => calleeName.includes(pattern.toLowerCase()))) {
62
41
  return true;
63
42
  }
64
43
  }
65
- // Check if it's a member expression like app.use(auth())
66
44
  if (callee.type === 'MemberExpression' && callee.property.type === 'Identifier') {
67
45
  const propertyName = callee.property.name.toLowerCase();
68
46
  if (propertyName === 'use' || propertyName === 'all') {
69
- // Check if any argument is an auth middleware
70
47
  for (const arg of callExpr.arguments) {
71
48
  const argText = sourceCode.getText(arg);
72
49
  if (authPatterns.some(pattern => argText.toLowerCase().includes(pattern.toLowerCase()))) {
@@ -76,7 +53,6 @@ function isInsideAuthMiddleware(node, sourceCode, authPatterns) {
76
53
  }
77
54
  }
78
55
  }
79
- // Traverse up the AST
80
56
  if ('parent' in current && current.parent) {
81
57
  current = current.parent;
82
58
  }
@@ -86,9 +62,6 @@ function isInsideAuthMiddleware(node, sourceCode, authPatterns) {
86
62
  }
87
63
  return false;
88
64
  }
89
- /**
90
- * Check if a string matches any ignore pattern
91
- */
92
65
  function matchesIgnorePattern(text, patterns) {
93
66
  return patterns.some(pattern => {
94
67
  try {
@@ -96,7 +69,6 @@ function matchesIgnorePattern(text, patterns) {
96
69
  return regex.test(text);
97
70
  }
98
71
  catch {
99
- // Invalid regex - treat as literal string match
100
72
  return text.toLowerCase().includes(pattern.toLowerCase());
101
73
  }
102
74
  });
@@ -183,14 +155,10 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
183
155
  const testFileRegex = new RegExp(testFilePattern);
184
156
  const isTestFile = allowInTests && testFileRegex.test(filename);
185
157
  const sourceCode = context.sourceCode;
186
- /**
187
- * Find variable declaration for an identifier
188
- */
189
158
  function findVariableDeclaration(identifier) {
190
159
  const varName = identifier.name;
191
160
  let current = identifier;
192
161
  while (current) {
193
- // Search in current scope
194
162
  if (current.type === 'Program' ||
195
163
  current.type === 'FunctionDeclaration' ||
196
164
  current.type === 'FunctionExpression' ||
@@ -208,7 +176,6 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
208
176
  }
209
177
  }
210
178
  }
211
- // Traverse up
212
179
  if ('parent' in current && current.parent) {
213
180
  current = current.parent;
214
181
  }
@@ -218,47 +185,36 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
218
185
  }
219
186
  return null;
220
187
  }
221
- /**
222
- * Check if an identifier was assigned from an auth middleware call
223
- */
224
188
  function isIdentifierFromAuthMiddleware(identifier) {
225
189
  const declarator = findVariableDeclaration(identifier);
226
190
  if (!declarator || !declarator.init) {
227
191
  return false;
228
192
  }
229
- // Check if init is a CallExpression to auth middleware
230
193
  if (declarator.init.type === 'CallExpression' && declarator.init.callee.type === 'Identifier') {
231
194
  const calleeName = declarator.init.callee.name.toLowerCase();
232
195
  return authMiddlewarePatterns.some(pattern => calleeName.includes(pattern.toLowerCase()));
233
196
  }
234
197
  return false;
235
198
  }
236
- /**
237
- * Check CallExpression for route handlers without authentication
238
- */
239
199
  function checkCallExpression(node) {
240
200
  if (isTestFile) {
241
201
  return;
242
202
  }
243
- // Check if it's a route handler call (app.get, router.post, etc.)
244
203
  if (node.callee.type === 'MemberExpression') {
245
204
  const property = node.callee.property;
246
205
  const object = node.callee.object;
247
- // Only check if the object looks like an Express app/router
248
- // Must be an identifier like 'app', 'router', 'server', etc.
249
206
  if (object.type !== 'Identifier') {
250
- return; // Skip member chains like db.users.get()
207
+ return;
251
208
  }
252
209
  const objectName = object.name.toLowerCase();
253
210
  const routerLikeNames = ['app', 'router', 'server', 'route', 'express', 'fastify', 'koa', 'hapi'];
254
211
  const looksLikeRouter = routerLikeNames.some(name => objectName.includes(name));
255
212
  if (!looksLikeRouter) {
256
- return; // Skip non-router objects like stmt.get(), db.get()
213
+ return;
257
214
  }
258
215
  if (property.type === 'Identifier') {
259
216
  const methodName = property.name.toLowerCase();
260
217
  if (routeHandlerPatterns.includes(methodName)) {
261
- // Extract route path if available
262
218
  let routePath = 'unknown';
263
219
  if (node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
264
220
  routePath = String(node.arguments[0].value);
@@ -277,7 +233,6 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
277
233
  console.log('DEBUG MSG: Ignored text:', text);
278
234
  return;
279
235
  }
280
- // Check if authentication middleware is present in arguments
281
236
  let hasAuth = false;
282
237
  for (const arg of node.arguments) {
283
238
  const argText = sourceCode.getText(arg);
@@ -285,24 +240,15 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
285
240
  hasAuth = true;
286
241
  break;
287
242
  }
288
- // NOTE: a prior "is this argument a CallExpression whose callee
289
- // name matches an auth pattern" check was removed as provably
290
- // redundant: `argText` above is the full source text of `arg`,
291
- // which for a CallExpression always begins with the callee's
292
- // own text. Any pattern that matches `calleeName` therefore
293
- // already matches `argText` and is caught by the check above.
294
- // Check if argument is an identifier assigned from auth middleware
295
243
  if (arg.type === 'Identifier' && isIdentifierFromAuthMiddleware(arg)) {
296
244
  hasAuth = true;
297
245
  break;
298
246
  }
299
247
  }
300
- // Check if the handler function itself is inside an auth middleware context
301
248
  if (!hasAuth && node.arguments.length > 0) {
302
249
  const lastArg = node.arguments[node.arguments.length - 1];
303
250
  if (lastArg.type === 'ArrowFunctionExpression' ||
304
251
  lastArg.type === 'FunctionExpression') {
305
- // Check if the handler is inside an auth middleware call
306
252
  if (isInsideAuthMiddleware(lastArg, sourceCode, authMiddlewarePatterns)) {
307
253
  hasAuth = true;
308
254
  }
@@ -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.noPiiInLogs = void 0;
9
- /**
10
- * @fileoverview Prevent PII (email, SSN, credit cards) in console logs
11
- * @see https://owasp.org/www-project-mobile-top-10/
12
- * @see https://cwe.mitre.org/data/definitions/532.html
13
- */
14
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
5
  exports.noPiiInLogs = (0, eslint_devkit_1.createRule)({
16
6
  name: 'no-pii-in-logs',
@@ -45,13 +35,11 @@ exports.noPiiInLogs = (0, eslint_devkit_1.createRule)({
45
35
  }
46
36
  return {
47
37
  CallExpression(node) {
48
- // Check console.log/error/warn calls
49
38
  if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
50
39
  node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
51
40
  node.callee.object.name === 'console' &&
52
41
  node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
53
42
  ['log', 'error', 'warn', 'info'].includes(node.callee.property.name)) {
54
- // Check arguments for PII-related property access
55
43
  for (const arg of node.arguments) {
56
44
  if (arg.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
57
45
  arg.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
@@ -61,7 +49,6 @@ exports.noPiiInLogs = (0, eslint_devkit_1.createRule)({
61
49
  report(node);
62
50
  }
63
51
  }
64
- // Check string literals mentioning PII
65
52
  if (arg.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof arg.value === 'string') {
66
53
  const text = arg.value.toLowerCase();
67
54
  if (text.includes('email:') || text.includes('ssn:') || text.includes('password:')) {
@@ -1,16 +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.noPrivilegeEscalation = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- /**
12
- * Common role check patterns
13
- */
14
6
  const DEFAULT_ROLE_CHECK_PATTERNS = [
15
7
  'hasRole',
16
8
  'checkRole',
@@ -21,18 +13,12 @@ const DEFAULT_ROLE_CHECK_PATTERNS = [
21
13
  'verifyRole',
22
14
  'requireRole',
23
15
  ];
24
- /**
25
- * Common user input patterns
26
- */
27
16
  const DEFAULT_USER_INPUT_PATTERNS = [
28
17
  /\breq\.(body|query|params)\b/,
29
18
  /\brequest\.(body|query|params)\b/,
30
19
  /\buserInput\b/,
31
20
  /\binput\b/,
32
21
  ];
33
- /**
34
- * Check if a string matches any ignore pattern
35
- */
36
22
  function matchesIgnorePattern(text, patterns) {
37
23
  return patterns.some(pattern => {
38
24
  try {
@@ -40,43 +26,31 @@ function matchesIgnorePattern(text, patterns) {
40
26
  return regex.test(text);
41
27
  }
42
28
  catch {
43
- // Invalid regex - treat as literal string match
44
29
  return text.toLowerCase().includes(pattern.toLowerCase());
45
30
  }
46
31
  });
47
32
  }
48
- /**
49
- * Check if a node contains user input patterns
50
- */
51
33
  function containsUserInput(node, sourceCode, userInputPatterns) {
52
34
  const text = sourceCode.getText(node);
53
35
  return userInputPatterns.some(pattern => pattern.test(text));
54
36
  }
55
- /**
56
- * Check if a node is inside a role check call
57
- */
58
37
  function isInsideRoleCheck(node, sourceCode, roleCheckPatterns) {
59
38
  let current = node;
60
39
  while (current) {
61
- // Check if current is inside an IfStatement with role check in condition
62
40
  if (current.parent && current.parent.type === 'IfStatement') {
63
41
  const ifStmt = current.parent;
64
42
  const conditionText = sourceCode.getText(ifStmt.test);
65
- // Check if condition contains role check patterns (text-based check catches all patterns)
66
43
  if (roleCheckPatterns.some(pattern => conditionText.toLowerCase().includes(pattern.toLowerCase()))) {
67
44
  return true;
68
45
  }
69
46
  }
70
- // Check if current is inside a ConditionalExpression (ternary) with role check
71
47
  if (current.parent && current.parent.type === 'ConditionalExpression') {
72
48
  const condExpr = current.parent;
73
49
  const testText = sourceCode.getText(condExpr.test);
74
- // Check if test contains role check patterns (text-based check catches all patterns)
75
50
  if (roleCheckPatterns.some(pattern => testText.toLowerCase().includes(pattern.toLowerCase()))) {
76
51
  return true;
77
52
  }
78
53
  }
79
- // Check if current is inside a CallExpression with role check
80
54
  if (current.parent && current.parent.type === 'CallExpression') {
81
55
  const callExpr = current.parent;
82
56
  const callee = callExpr.callee;
@@ -93,7 +67,6 @@ function isInsideRoleCheck(node, sourceCode, roleCheckPatterns) {
93
67
  }
94
68
  }
95
69
  }
96
- // Traverse up the AST
97
70
  if ('parent' in current && current.parent) {
98
71
  current = current.parent;
99
72
  }
@@ -185,33 +158,23 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
185
158
  const testFileRegex = new RegExp(testFilePattern);
186
159
  const isTestFile = allowInTests && testFileRegex.test(filename);
187
160
  const sourceCode = context.sourceCode;
188
- // Combine default and additional user input patterns
189
161
  const userInputPatterns = [
190
162
  ...DEFAULT_USER_INPUT_PATTERNS,
191
163
  ...additionalUserInputPatterns.map(pattern => new RegExp(pattern, 'i')),
192
164
  ];
193
- /**
194
- * Check AssignmentExpression for privilege escalation
195
- */
196
165
  function checkAssignmentExpression(node) {
197
166
  if (isTestFile) {
198
167
  return;
199
168
  }
200
- // Check for role assignment from user input
201
- // Pattern: user.role = req.body.role
202
169
  if (node.left.type === 'MemberExpression' &&
203
170
  node.left.property.type === 'Identifier') {
204
171
  const propertyName = node.left.property.name.toLowerCase();
205
- // Check if it's a role/permission related property
206
172
  if (['role', 'permission', 'privilege', 'access', 'level'].includes(propertyName)) {
207
173
  const text = sourceCode.getText(node);
208
- // Check if it matches any ignore pattern
209
174
  if (matchesIgnorePattern(text, ignorePatterns)) {
210
175
  return;
211
176
  }
212
- // Check if right side contains user input
213
177
  if (containsUserInput(node.right, sourceCode, userInputPatterns)) {
214
- // Check if it's inside a role check
215
178
  if (!isInsideRoleCheck(node, sourceCode, roleCheckPatterns)) {
216
179
  context.report({
217
180
  node: node,
@@ -231,14 +194,10 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
231
194
  }
232
195
  }
233
196
  }
234
- /**
235
- * Check CallExpression for privilege operations with user input
236
- */
237
197
  function checkCallExpression(node) {
238
198
  if (isTestFile) {
239
199
  return;
240
200
  }
241
- // Check for privilege-related function calls with user input
242
201
  const callee = node.callee;
243
202
  let isPrivilegeOperation = false;
244
203
  let operationName = '';
@@ -258,14 +217,11 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
258
217
  }
259
218
  if (isPrivilegeOperation) {
260
219
  const text = sourceCode.getText(node);
261
- // Check if it matches any ignore pattern
262
220
  if (matchesIgnorePattern(text, ignorePatterns)) {
263
221
  return;
264
222
  }
265
- // Check if any argument contains user input
266
223
  for (const arg of node.arguments) {
267
224
  if (containsUserInput(arg, sourceCode, userInputPatterns)) {
268
- // Check if it's inside a role check
269
225
  if (!isInsideRoleCheck(node, sourceCode, roleCheckPatterns)) {
270
226
  context.report({
271
227
  node: node,
@@ -280,15 +236,12 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
280
236
  },
281
237
  ],
282
238
  });
283
- return; // Report once per call
239
+ return;
284
240
  }
285
241
  }
286
242
  }
287
243
  }
288
244
  }
289
- /**
290
- * Check ObjectExpression for role assignment in objects (e.g. arguments)
291
- */
292
245
  function checkObjectExpression(node) {
293
246
  if (isTestFile)
294
247
  return;
@@ -310,7 +263,7 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
310
263
  suggest: [
311
264
  {
312
265
  messageId: 'addRoleCheck',
313
- fix: () => null, // No auto-fix for logic
266
+ fix: () => null,
314
267
  },
315
268
  ],
316
269
  });