eslint-plugin-secure-coding 3.3.1 → 3.3.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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/rules/detect-non-literal-regexp/index.js +48 -61
- package/src/rules/detect-object-injection/index.js +32 -88
- package/src/rules/no-directive-injection/index.js +0 -16
- package/src/rules/no-electron-security-issues/index.js +0 -6
- package/src/rules/no-format-string-injection/index.js +2 -29
- package/src/rules/no-graphql-injection/index.js +10 -10
- package/src/rules/no-hardcoded-credentials/index.js +12 -7
- package/src/rules/no-improper-sanitization/index.js +1 -9
- package/src/rules/no-improper-type-validation/index.js +0 -10
- package/src/rules/no-ldap-injection/index.d.ts +14 -0
- package/src/rules/no-ldap-injection/index.js +51 -58
- package/src/rules/no-missing-authentication/index.js +12 -16
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -7
- package/src/rules/no-unchecked-loop-condition/index.js +21 -37
- package/src/rules/no-unlimited-resource-allocation/index.js +42 -79
- package/src/rules/no-unsafe-deserialization/index.js +0 -5
- package/src/rules/no-unsafe-regex-construction/index.js +14 -2
- package/src/rules/no-weak-password-recovery/index.js +0 -6
- package/src/rules/no-xpath-injection/index.js +19 -45
- package/src/rules/no-xxe-injection/index.js +4 -1
|
@@ -243,10 +243,6 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
243
243
|
if (safeMemberCallers.has(key))
|
|
244
244
|
return true;
|
|
245
245
|
}
|
|
246
|
-
// Direct function call
|
|
247
|
-
if (callee.type === 'Identifier' && safeMemberCallers.has(callee.name)) {
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
246
|
break; // Stop at first enclosing call
|
|
251
247
|
}
|
|
252
248
|
// new URL(`...`), new Error(`...`)
|
|
@@ -286,9 +282,18 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
286
282
|
* Find keyword at word boundary in text. Returns index or -1.
|
|
287
283
|
* Uses simple character checks instead of regex \b.
|
|
288
284
|
*/
|
|
285
|
+
// NOTE: this loop always terminates via one of its two internal `return`
|
|
286
|
+
// statements: `text.indexOf` eventually returns -1 for any finite input,
|
|
287
|
+
// and each successful-but-boundary-failing match only advances `pos` by 1
|
|
288
|
+
// (never past `text.length`) before the next `indexOf` call runs. There is
|
|
289
|
+
// no fallthrough path once the `while` condition becomes false, so the
|
|
290
|
+
// loop is written with `while (true)` + internal returns instead of a
|
|
291
|
+
// trailing `return -1` that static analysis (and coverage) would flag as
|
|
292
|
+
// dead code.
|
|
289
293
|
const findKeywordAtBoundary = (text, keyword, startFrom = 0) => {
|
|
290
294
|
let pos = startFrom;
|
|
291
|
-
|
|
295
|
+
// oxlint-disable-next-line no-constant-condition
|
|
296
|
+
while (true) {
|
|
292
297
|
const idx = text.indexOf(keyword, pos);
|
|
293
298
|
if (idx === -1)
|
|
294
299
|
return -1;
|
|
@@ -299,7 +304,6 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
299
304
|
return idx;
|
|
300
305
|
pos = idx + 1;
|
|
301
306
|
}
|
|
302
|
-
return -1;
|
|
303
307
|
};
|
|
304
308
|
/**
|
|
305
309
|
* AST-based: Check if a TemplateLiteral contains GraphQL syntax.
|
|
@@ -580,11 +584,9 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
580
584
|
// Check for introspection queries
|
|
581
585
|
const lowerQuery = queryText.toLowerCase();
|
|
582
586
|
if (!allowIntrospection && (lowerQuery.includes('__schema') || lowerQuery.includes('__type'))) {
|
|
583
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
584
587
|
if (safetyChecker.isSafe(node, context)) {
|
|
585
588
|
return;
|
|
586
589
|
}
|
|
587
|
-
/* c8 ignore stop */
|
|
588
590
|
context.report({
|
|
589
591
|
node,
|
|
590
592
|
messageId: 'introspectionQuery',
|
|
@@ -627,11 +629,9 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
627
629
|
return;
|
|
628
630
|
}
|
|
629
631
|
// String concatenation in GraphQL queries is dangerous
|
|
630
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
631
632
|
if (safetyChecker.isSafe(node, context)) {
|
|
632
633
|
return;
|
|
633
634
|
}
|
|
634
|
-
/* c8 ignore stop */
|
|
635
635
|
context.report({
|
|
636
636
|
node,
|
|
637
637
|
messageId: 'graphqlInjection',
|
|
@@ -274,7 +274,7 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
|
|
|
274
274
|
],
|
|
275
275
|
create(context) {
|
|
276
276
|
const options = context.options[0] || {};
|
|
277
|
-
const { ignorePatterns = [], allowInTests = false, minLength = 8, detectApiKeys = true, detectPasswords = true, detectTokens = true, detectDatabaseStrings = true, customPatterns = [], } = options
|
|
277
|
+
const { ignorePatterns = [], allowInTests = false, minLength = 8, detectApiKeys = true, detectPasswords = true, detectTokens = true, detectDatabaseStrings = true, customPatterns = [], } = options;
|
|
278
278
|
const filename = context.filename;
|
|
279
279
|
const isTestFile = allowInTests && (filename.includes('.test.') ||
|
|
280
280
|
filename.includes('.spec.') ||
|
|
@@ -413,10 +413,12 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
|
|
|
413
413
|
* secret-key style names. Anything else falls back to `other`, which
|
|
414
414
|
* the options never gate (e.g. `credentials`, `auth`).
|
|
415
415
|
*/
|
|
416
|
-
function inferCredentialTypeFromContext(
|
|
416
|
+
function inferCredentialTypeFromContext(
|
|
417
|
+
// Non-optional: the sole caller only reaches here after
|
|
418
|
+
// isCredentialContext(node, parent) has already returned true, which
|
|
419
|
+
// requires a truthy parent.
|
|
420
|
+
parent) {
|
|
417
421
|
const name = (() => {
|
|
418
|
-
if (!parent)
|
|
419
|
-
return '';
|
|
420
422
|
if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {
|
|
421
423
|
return parent.id.name.toLowerCase();
|
|
422
424
|
}
|
|
@@ -424,9 +426,10 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
|
|
|
424
426
|
const key = parent.key;
|
|
425
427
|
if (key.type === 'Identifier')
|
|
426
428
|
return key.name.toLowerCase();
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
429
|
+
// isCredentialContext's own Property check only returns true for
|
|
430
|
+
// an Identifier key (handled above) or a string-Literal key, so
|
|
431
|
+
// whatever remains here is always the latter.
|
|
432
|
+
return String(key.value).toLowerCase();
|
|
430
433
|
}
|
|
431
434
|
if (parent.type === 'AssignmentExpression') {
|
|
432
435
|
const left = parent.left;
|
|
@@ -573,6 +576,8 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
|
|
|
573
576
|
// honour the option.
|
|
574
577
|
if (!finalIsCredential && value.length >= detectionOptions.minLength &&
|
|
575
578
|
isCredentialContext(node, parent)) {
|
|
579
|
+
// isCredentialContext(node, parent) just returned true, which
|
|
580
|
+
// requires a truthy parent.
|
|
576
581
|
const ctxType = inferCredentialTypeFromContext(parent);
|
|
577
582
|
const optionAllows = (ctxType === 'password' && detectionOptions.detectPasswords) ||
|
|
578
583
|
(ctxType === 'token' && detectionOptions.detectTokens) ||
|
|
@@ -264,11 +264,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
|
|
|
264
264
|
callee.property.type === 'Identifier' &&
|
|
265
265
|
callee.property.name === 'replace') {
|
|
266
266
|
if (isIncompleteReplaceSanitization(node)) {
|
|
267
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
268
267
|
if (safetyChecker.isSafe(node, context)) {
|
|
269
268
|
return;
|
|
270
269
|
}
|
|
271
|
-
/* c8 ignore stop */
|
|
272
270
|
context.report({
|
|
273
271
|
node,
|
|
274
272
|
messageId: 'incompleteHtmlEscaping',
|
|
@@ -301,11 +299,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
|
|
|
301
299
|
}
|
|
302
300
|
}
|
|
303
301
|
if (hasUserInput) {
|
|
304
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
305
302
|
if (safetyChecker.isSafe(node, context)) {
|
|
306
303
|
return;
|
|
307
304
|
}
|
|
308
|
-
/* c8 ignore stop */
|
|
309
305
|
context.report({
|
|
310
306
|
node,
|
|
311
307
|
messageId: 'dangerousSanitizerUsage',
|
|
@@ -339,11 +335,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
|
|
|
339
335
|
rightText.includes('query') ||
|
|
340
336
|
rightText.includes('input');
|
|
341
337
|
if (hasUserInput) {
|
|
342
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
343
338
|
if (safetyChecker.isSafe(node, context)) {
|
|
344
339
|
return;
|
|
345
340
|
}
|
|
346
|
-
/* c8 ignore stop */
|
|
347
341
|
context.report({
|
|
348
342
|
node: right,
|
|
349
343
|
messageId: 'insufficientXssProtection',
|
|
@@ -380,7 +374,7 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
|
|
|
380
374
|
const left = directParent.left;
|
|
381
375
|
if (left.property.type === 'Identifier' &&
|
|
382
376
|
['innerHTML', 'outerHTML'].includes(left.property.name)) {
|
|
383
|
-
const literalValue =
|
|
377
|
+
const literalValue = node.value;
|
|
384
378
|
const hasDangerousMarkup = /<script[\s>]|<\/script>|\son\w+\s*=|javascript:/i.test(literalValue);
|
|
385
379
|
if (!hasDangerousMarkup) {
|
|
386
380
|
return;
|
|
@@ -422,11 +416,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
|
|
|
422
416
|
text.includes('"') || text.includes(''') ||
|
|
423
417
|
text.includes('&');
|
|
424
418
|
if (hasDangerousChars && !hasEscaping) {
|
|
425
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
426
419
|
if (safetyChecker.isSafe(node, context)) {
|
|
427
420
|
return;
|
|
428
421
|
}
|
|
429
|
-
/* c8 ignore stop */
|
|
430
422
|
context.report({
|
|
431
423
|
node,
|
|
432
424
|
messageId: 'unsafeReplaceSanitization',
|
|
@@ -299,11 +299,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
|
|
|
299
299
|
matchesUserInput = true;
|
|
300
300
|
}
|
|
301
301
|
if (matchesUserInput) {
|
|
302
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
303
302
|
if (safetyChecker.isSafe(node, context)) {
|
|
304
303
|
return;
|
|
305
304
|
}
|
|
306
|
-
/* c8 ignore stop */
|
|
307
305
|
context.report({
|
|
308
306
|
node: left,
|
|
309
307
|
messageId: 'unsafeTypeofCheck',
|
|
@@ -344,11 +342,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
|
|
|
344
342
|
if ((left.type === 'Identifier' && isUserInput(left.name)) ||
|
|
345
343
|
(right.type === 'Identifier' && isUserInput(right.name)) ||
|
|
346
344
|
leftText.includes('null') || rightText.includes('null')) {
|
|
347
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
348
345
|
if (safetyChecker.isSafe(node, context)) {
|
|
349
346
|
return;
|
|
350
347
|
}
|
|
351
|
-
/* c8 ignore stop */
|
|
352
348
|
context.report({
|
|
353
349
|
node: node,
|
|
354
350
|
messageId: 'looseEqualityTypeCheck',
|
|
@@ -383,11 +379,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
|
|
|
383
379
|
}
|
|
384
380
|
}
|
|
385
381
|
if (involvesUserInput) {
|
|
386
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
387
382
|
if (safetyChecker.isSafe(node, context)) {
|
|
388
383
|
return;
|
|
389
384
|
}
|
|
390
|
-
/* c8 ignore stop */
|
|
391
385
|
context.report({
|
|
392
386
|
node,
|
|
393
387
|
messageId: 'unreliableConstructorCheck',
|
|
@@ -435,11 +429,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
|
|
|
435
429
|
const test = node.test;
|
|
436
430
|
// NEW: Check for implicit truthiness check on user input
|
|
437
431
|
if (test.type === 'Identifier' && isUserInput(test.name)) {
|
|
438
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
439
432
|
if (safetyChecker.isSafe(node, context)) {
|
|
440
433
|
return;
|
|
441
434
|
}
|
|
442
|
-
/* c8 ignore stop */
|
|
443
435
|
context.report({
|
|
444
436
|
node: test,
|
|
445
437
|
messageId: 'improperTypeValidation',
|
|
@@ -460,11 +452,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
|
|
|
460
452
|
// Check if this involves user input
|
|
461
453
|
if ((test.left.type === 'Identifier' && isUserInput(test.left.name)) ||
|
|
462
454
|
(test.right.type === 'Identifier' && isUserInput(test.right.name))) {
|
|
463
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
464
455
|
if (safetyChecker.isSafe(node, context)) {
|
|
465
456
|
return;
|
|
466
457
|
}
|
|
467
|
-
/* c8 ignore stop */
|
|
468
458
|
context.report({
|
|
469
459
|
node: test,
|
|
470
460
|
messageId: 'missingNullCheck',
|
|
@@ -33,6 +33,20 @@ export interface Options extends SecurityRuleOptions {
|
|
|
33
33
|
ldapValidationFunctions?: string[];
|
|
34
34
|
}
|
|
35
35
|
type RuleOptions = [Options?];
|
|
36
|
+
/**
|
|
37
|
+
* Check if LDAP filter contains dangerous patterns.
|
|
38
|
+
*
|
|
39
|
+
* Extracted to module scope (from inside `create()`) for direct unit
|
|
40
|
+
* testability — this function is pure and captures no closure state.
|
|
41
|
+
*/
|
|
42
|
+
export declare function containsDangerousLdapFilter(filterText: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Check if string contains LDAP filter interpolation.
|
|
45
|
+
*
|
|
46
|
+
* Extracted to module scope (from inside `create()`) for direct unit
|
|
47
|
+
* testability — this function is pure and captures no closure state.
|
|
48
|
+
*/
|
|
49
|
+
export declare function containsLdapInterpolation(text: string): boolean;
|
|
36
50
|
export declare const noLdapInjection: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
37
51
|
name: string;
|
|
38
52
|
};
|
|
@@ -6,9 +6,39 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.noLdapInjection = void 0;
|
|
9
|
+
exports.containsDangerousLdapFilter = containsDangerousLdapFilter;
|
|
10
|
+
exports.containsLdapInterpolation = containsLdapInterpolation;
|
|
9
11
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
12
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
13
|
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
|
+
function containsDangerousLdapFilter(filterText) {
|
|
21
|
+
// Dangerous LDAP filter patterns
|
|
22
|
+
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
|
|
30
|
+
];
|
|
31
|
+
return dangerousPatterns.some(pattern => pattern.test(filterText));
|
|
32
|
+
}
|
|
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
|
+
function containsLdapInterpolation(text) {
|
|
40
|
+
return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
|
|
41
|
+
}
|
|
12
42
|
exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
13
43
|
name: 'no-ldap-injection',
|
|
14
44
|
meta: {
|
|
@@ -181,30 +211,6 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
181
211
|
}
|
|
182
212
|
return false;
|
|
183
213
|
};
|
|
184
|
-
/**
|
|
185
|
-
* Check if LDAP filter contains dangerous patterns
|
|
186
|
-
*/
|
|
187
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
188
|
-
const containsDangerousLdapFilter = (filterText) => {
|
|
189
|
-
// Dangerous LDAP filter patterns
|
|
190
|
-
const dangerousPatterns = [
|
|
191
|
-
/\*\)$/, // Ending with *) to match everything
|
|
192
|
-
/\|\)$/, // Ending with |) for OR operations
|
|
193
|
-
/&\)$/, // Ending with &) for AND operations
|
|
194
|
-
/!\)$/, // Ending with !) for NOT operations
|
|
195
|
-
/\*\|\*/, // *|* pattern for matching everything
|
|
196
|
-
/\*&\*/, // *&* pattern
|
|
197
|
-
/\*!/, // NOT operations that could be exploited
|
|
198
|
-
];
|
|
199
|
-
return dangerousPatterns.some(pattern => pattern.test(filterText));
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* Check if string contains LDAP filter interpolation
|
|
203
|
-
*/
|
|
204
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
205
|
-
const containsLdapInterpolation = (text) => {
|
|
206
|
-
return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
|
|
207
|
-
};
|
|
208
214
|
/**
|
|
209
215
|
* Check if LDAP input is from untrusted source
|
|
210
216
|
*/
|
|
@@ -266,11 +272,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
266
272
|
const filterArg = args[1];
|
|
267
273
|
// Check if filter argument comes from untrusted input (like req.query.filter)
|
|
268
274
|
if (isUntrustedLdapInput(filterArg)) {
|
|
269
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
270
275
|
if (safetyChecker.isSafe(filterArg, context)) {
|
|
271
276
|
return;
|
|
272
277
|
}
|
|
273
|
-
/* c8 ignore stop */
|
|
274
278
|
context.report({
|
|
275
279
|
node: filterArg,
|
|
276
280
|
messageId: 'unescapedLdapInput',
|
|
@@ -288,29 +292,28 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
288
292
|
}
|
|
289
293
|
else if (filterArg.type === 'TemplateLiteral' && filterArg.expressions.length > 0) {
|
|
290
294
|
// Special handling for template literals with any expressions in LDAP calls
|
|
291
|
-
// This is a more aggressive check for LDAP injection in function calls
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
/* c8 ignore stop */
|
|
299
|
-
context.report({
|
|
300
|
-
node: filterArg,
|
|
301
|
-
messageId: 'unescapedLdapInput',
|
|
302
|
-
data: {
|
|
303
|
-
filePath: filename,
|
|
304
|
-
line: String(node.loc?.start.line ?? 0),
|
|
305
|
-
},
|
|
306
|
-
suggest: [
|
|
307
|
-
{
|
|
308
|
-
messageId: 'useLdapEscaping',
|
|
309
|
-
fix: () => null,
|
|
310
|
-
},
|
|
311
|
-
],
|
|
312
|
-
});
|
|
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
|
+
if (safetyChecker.isSafe(filterArg, context)) {
|
|
301
|
+
return;
|
|
313
302
|
}
|
|
303
|
+
context.report({
|
|
304
|
+
node: filterArg,
|
|
305
|
+
messageId: 'unescapedLdapInput',
|
|
306
|
+
data: {
|
|
307
|
+
filePath: filename,
|
|
308
|
+
line: String(node.loc?.start.line ?? 0),
|
|
309
|
+
},
|
|
310
|
+
suggest: [
|
|
311
|
+
{
|
|
312
|
+
messageId: 'useLdapEscaping',
|
|
313
|
+
fix: () => null,
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
});
|
|
314
317
|
}
|
|
315
318
|
},
|
|
316
319
|
// Check variable declarations with LDAP filters
|
|
@@ -333,11 +336,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
333
336
|
// Check if assigned value contains dangerous LDAP patterns
|
|
334
337
|
if (node.init.type === 'Literal' && typeof node.init.value === 'string') {
|
|
335
338
|
if (containsDangerousLdapFilter(node.init.value)) {
|
|
336
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
337
339
|
if (safetyChecker.isSafe(node.init, context)) {
|
|
338
340
|
return;
|
|
339
341
|
}
|
|
340
|
-
/* c8 ignore stop */
|
|
341
342
|
context.report({
|
|
342
343
|
node: node.init,
|
|
343
344
|
messageId: 'dangerousLdapOperation',
|
|
@@ -356,11 +357,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
356
357
|
// Check if any interpolated values are untrusted
|
|
357
358
|
const hasUntrustedInterpolation = node.init.expressions.some((expr) => isUntrustedLdapInput(expr) && !isLdapInputEscaped(expr));
|
|
358
359
|
if (hasUntrustedInterpolation) {
|
|
359
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
360
360
|
if (safetyChecker.isSafe(node.init, context)) {
|
|
361
361
|
return;
|
|
362
362
|
}
|
|
363
|
-
/* c8 ignore stop */
|
|
364
363
|
context.report({
|
|
365
364
|
node: node.init,
|
|
366
365
|
messageId: 'unsafeLdapFilter',
|
|
@@ -379,11 +378,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
379
378
|
}
|
|
380
379
|
// Check for dangerous patterns in template literals
|
|
381
380
|
if (containsDangerousLdapFilter(fullText)) {
|
|
382
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
383
381
|
if (safetyChecker.isSafe(node.init, context)) {
|
|
384
382
|
return;
|
|
385
383
|
}
|
|
386
|
-
/* c8 ignore stop */
|
|
387
384
|
context.report({
|
|
388
385
|
node: node.init,
|
|
389
386
|
messageId: 'dangerousLdapOperation',
|
|
@@ -410,11 +407,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
410
407
|
return false;
|
|
411
408
|
};
|
|
412
409
|
if (hasUntrustedInput(node.init.left) || hasUntrustedInput(node.init.right)) {
|
|
413
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
414
410
|
if (safetyChecker.isSafe(node.init, context)) {
|
|
415
411
|
return;
|
|
416
412
|
}
|
|
417
|
-
/* c8 ignore stop */
|
|
418
413
|
context.report({
|
|
419
414
|
node: node.init,
|
|
420
415
|
messageId: 'ldapInjection',
|
|
@@ -435,11 +430,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
|
|
|
435
430
|
}
|
|
436
431
|
}
|
|
437
432
|
else if (isUntrustedLdapInput(node.init) && !isLdapInputEscaped(node.init)) {
|
|
438
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
439
433
|
if (safetyChecker.isSafe(node.init, context)) {
|
|
440
434
|
return;
|
|
441
435
|
}
|
|
442
|
-
/* c8 ignore stop */
|
|
443
436
|
context.report({
|
|
444
437
|
node: node.init,
|
|
445
438
|
messageId: 'ldapInjection',
|
|
@@ -47,14 +47,12 @@ function isInsideAuthMiddleware(node, sourceCode, authPatterns) {
|
|
|
47
47
|
// Verify that current is actually an argument of this call
|
|
48
48
|
const isArgument = callExpr.arguments.some((arg) => arg === current);
|
|
49
49
|
if (!isArgument) {
|
|
50
|
-
// Not an argument,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
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
|
+
current = current.parent;
|
|
55
|
+
continue;
|
|
58
56
|
}
|
|
59
57
|
const callee = callExpr.callee;
|
|
60
58
|
// Check if it's an authentication middleware call
|
|
@@ -287,14 +285,12 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
|
|
|
287
285
|
hasAuth = true;
|
|
288
286
|
break;
|
|
289
287
|
}
|
|
290
|
-
//
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
}
|
|
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.
|
|
298
294
|
// Check if argument is an identifier assigned from auth middleware
|
|
299
295
|
if (arg.type === 'Identifier' && isIdentifierFromAuthMiddleware(arg)) {
|
|
300
296
|
hasAuth = true;
|
|
@@ -299,17 +299,14 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
299
299
|
callee = node.callee;
|
|
300
300
|
}
|
|
301
301
|
else {
|
|
302
|
-
/* c8 ignore next */
|
|
303
302
|
return;
|
|
304
303
|
}
|
|
305
304
|
const isRegExp = callee.type === 'Identifier' && callee.name === 'RegExp';
|
|
306
305
|
if (!isRegExp) {
|
|
307
|
-
/* c8 ignore next */
|
|
308
306
|
return;
|
|
309
307
|
}
|
|
310
308
|
// Check if first argument is a string literal
|
|
311
309
|
if (node.arguments.length === 0) {
|
|
312
|
-
/* c8 ignore next */
|
|
313
310
|
return;
|
|
314
311
|
}
|
|
315
312
|
const firstArg = node.arguments[0];
|
|
@@ -345,23 +342,19 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
345
342
|
return;
|
|
346
343
|
}
|
|
347
344
|
if (firstArg.type !== 'Literal' || typeof firstArg.value !== 'string') {
|
|
348
|
-
/* c8 ignore next */
|
|
349
345
|
return;
|
|
350
346
|
}
|
|
351
347
|
const pattern = firstArg.value;
|
|
352
348
|
// Skip if pattern is too long (performance)
|
|
353
349
|
if (pattern.length > maxPatternLength) {
|
|
354
|
-
/* c8 ignore next */
|
|
355
350
|
return;
|
|
356
351
|
}
|
|
357
352
|
const vulnerability = hasReDoSVulnerability(pattern);
|
|
358
353
|
if (!vulnerability) {
|
|
359
|
-
/* c8 ignore next */
|
|
360
354
|
return;
|
|
361
355
|
}
|
|
362
356
|
// Allow common patterns if configured
|
|
363
357
|
if (allowCommonPatterns && (vulnerability.severity === 'medium' || vulnerability.name === 'Alternation with Quantifier')) {
|
|
364
|
-
/* c8 ignore next */
|
|
365
358
|
return;
|
|
366
359
|
}
|
|
367
360
|
const suggestions = generateFixSuggestions(vulnerability);
|