eslint-plugin-secure-coding 3.3.0 → 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 +29 -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/detect-weak-password-validation/index.js +1 -1
- 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 +13 -8
- package/src/rules/no-hardcoded-session-tokens/index.js +1 -1
- 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-insecure-comparison/index.js +1 -1
- 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 +13 -17
- package/src/rules/no-privilege-escalation/index.js +1 -1
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -7
- package/src/rules/no-sensitive-data-exposure/index.js +1 -1
- package/src/rules/no-template-injection/index.js +1 -1
- 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 +5 -2
- package/src/rules/require-backend-authorization/index.js +1 -1
|
@@ -8,6 +8,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.noUnsafeRegexConstruction = void 0;
|
|
9
9
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
10
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
// Inline regex-metacharacter escape, appended to the flagged expression by the
|
|
12
|
+
// `escapeUserInput` suggestion fixer. No `escapeRegExp` helper exists in user
|
|
13
|
+
// code, so the fix must be self-contained rather than calling one.
|
|
14
|
+
const INLINE_ESCAPE_SUFFIX = '.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&")';
|
|
11
15
|
/**
|
|
12
16
|
* Check if a node represents user input (variable, function call, template literal)
|
|
13
17
|
*/
|
|
@@ -192,7 +196,10 @@ exports.noUnsafeRegexConstruction = (0, eslint_devkit_2.createRule)({
|
|
|
192
196
|
},
|
|
193
197
|
],
|
|
194
198
|
create(context, [options = {}]) {
|
|
195
|
-
|
|
199
|
+
// `options` is always an object here (defaulted by the destructuring
|
|
200
|
+
// parameter above), so a second `|| {}` fallback could never fire —
|
|
201
|
+
// removed as dead code.
|
|
202
|
+
const { allowLiterals = true, maxPatternLength = 100, trustedEscapingFunctions = ['escapeRegex', 'escape', 'sanitize'], } = options;
|
|
196
203
|
const sourceCode = context.sourceCode;
|
|
197
204
|
/**
|
|
198
205
|
* Check RegExp constructor calls
|
|
@@ -252,6 +259,7 @@ exports.noUnsafeRegexConstruction = (0, eslint_devkit_2.createRule)({
|
|
|
252
259
|
}
|
|
253
260
|
// Check for user input without escaping
|
|
254
261
|
if (isUserInputValue && !isEscapedValue) {
|
|
262
|
+
const patternText = context.sourceCode.getText(patternNode);
|
|
255
263
|
context.report({
|
|
256
264
|
node: patternNode,
|
|
257
265
|
messageId: 'unsafeRegexConstruction',
|
|
@@ -263,7 +271,11 @@ exports.noUnsafeRegexConstruction = (0, eslint_devkit_2.createRule)({
|
|
|
263
271
|
suggest: [
|
|
264
272
|
{
|
|
265
273
|
messageId: 'escapeUserInput',
|
|
266
|
-
|
|
274
|
+
// Append an inline regex-metacharacter escape so special chars are neutralized.
|
|
275
|
+
// Parenthesize patternText first: it's spliced in as-is (could be any
|
|
276
|
+
// expression, e.g. a lower-precedence one), so `.replace(...)` must bind
|
|
277
|
+
// to the whole expression, not just its last operand.
|
|
278
|
+
fix: (fixer) => fixer.replaceText(patternNode, `(${patternText})${INLINE_ESCAPE_SUFFIX}`),
|
|
267
279
|
},
|
|
268
280
|
{
|
|
269
281
|
messageId: 'validatePattern',
|
|
@@ -331,11 +331,9 @@ exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
|
|
|
331
331
|
if (isRecoveryRelated(functionName)) {
|
|
332
332
|
// Check for token expiration
|
|
333
333
|
if (!hasTokenExpiration(node)) {
|
|
334
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
335
334
|
if (safetyChecker.isSafe(node, context)) {
|
|
336
335
|
return;
|
|
337
336
|
}
|
|
338
|
-
/* c8 ignore stop */
|
|
339
337
|
context.report({
|
|
340
338
|
node: node.id,
|
|
341
339
|
messageId: 'missingTokenExpiration',
|
|
@@ -347,11 +345,9 @@ exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
|
|
|
347
345
|
}
|
|
348
346
|
// Check for rate limiting (very basic check)
|
|
349
347
|
if (!functionText.includes('limit') && !functionText.includes('rate')) {
|
|
350
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
351
348
|
if (safetyChecker.isSafe(node, context)) {
|
|
352
349
|
return;
|
|
353
350
|
}
|
|
354
|
-
/* c8 ignore stop */
|
|
355
351
|
context.report({
|
|
356
352
|
node: node.id,
|
|
357
353
|
messageId: 'missingRateLimit',
|
|
@@ -410,11 +406,9 @@ exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
|
|
|
410
406
|
if (testText.includes('email') && !testText.includes('verify') &&
|
|
411
407
|
!testText.includes('token') && !testText.includes('code') &&
|
|
412
408
|
!testText.includes('otp') && !testText.includes('sms')) {
|
|
413
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
414
409
|
if (safetyChecker.isSafe(node, context)) {
|
|
415
410
|
return;
|
|
416
411
|
}
|
|
417
|
-
/* c8 ignore stop */
|
|
418
412
|
context.report({
|
|
419
413
|
node: test,
|
|
420
414
|
messageId: 'weakRecoveryVerification',
|
|
@@ -158,7 +158,7 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
|
|
|
158
158
|
],
|
|
159
159
|
create(context) {
|
|
160
160
|
const options = context.options[0] || {};
|
|
161
|
-
const { xpathFunctions = ['evaluate', 'selectSingleNode', 'selectNodes', 'xpath', 'select'],
|
|
161
|
+
const { xpathFunctions = ['evaluate', 'selectSingleNode', 'selectNodes', 'xpath', 'select'], xpathValidationFunctions = ['validateXPath', 'escapeXPath', 'sanitizeXPath', 'cleanXPath'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
|
|
162
162
|
const sourceCode = context.sourceCode;
|
|
163
163
|
const filename = context.filename;
|
|
164
164
|
// Create safety checker for false positive detection
|
|
@@ -291,21 +291,6 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
|
|
|
291
291
|
}
|
|
292
292
|
return false;
|
|
293
293
|
};
|
|
294
|
-
/**
|
|
295
|
-
* Check if XPath is constructed safely
|
|
296
|
-
*/
|
|
297
|
-
const isSafeXpathConstruction = (node) => {
|
|
298
|
-
let current = node;
|
|
299
|
-
while (current) {
|
|
300
|
-
if (current.type === 'CallExpression' &&
|
|
301
|
-
current.callee.type === 'Identifier' &&
|
|
302
|
-
safeXpathConstructors.includes(current.callee.name)) {
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
current = current.parent;
|
|
306
|
-
}
|
|
307
|
-
return false;
|
|
308
|
-
};
|
|
309
294
|
return {
|
|
310
295
|
// Check XPath function calls
|
|
311
296
|
CallExpression(node) {
|
|
@@ -437,30 +422,24 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
|
|
|
437
422
|
if (!fullText.includes('/') && !fullText.includes('[')) {
|
|
438
423
|
return;
|
|
439
424
|
}
|
|
440
|
-
// Check if
|
|
441
|
-
const
|
|
442
|
-
const
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const rightUntrusted = isUntrustedXpathInput(node.right) && !isXpathInputValidated(node.right) && !(node.right.type === 'Identifier' && validatedVariables.has(node.right.name));
|
|
448
|
-
if (leftUntrusted || rightUntrusted) {
|
|
449
|
-
// FALSE POSITIVE REDUCTION
|
|
450
|
-
if (safetyChecker.isSafe(node, context) || hasSafeAnnotationOnStatement(node)) {
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
context.report({
|
|
454
|
-
node,
|
|
455
|
-
messageId: 'xpathInjection',
|
|
456
|
-
data: {
|
|
457
|
-
filePath: filename,
|
|
458
|
-
line: String(node.loc?.start.line ?? 0),
|
|
459
|
-
severity: 'HIGH',
|
|
460
|
-
safeAlternative: 'Use parameterized XPath construction with input validation',
|
|
461
|
-
},
|
|
462
|
-
});
|
|
425
|
+
// Check if untrusted input is involved
|
|
426
|
+
const leftUntrusted = isUntrustedXpathInput(node.left) && !isXpathInputValidated(node.left) && !(node.left.type === 'Identifier' && validatedVariables.has(node.left.name));
|
|
427
|
+
const rightUntrusted = isUntrustedXpathInput(node.right) && !isXpathInputValidated(node.right) && !(node.right.type === 'Identifier' && validatedVariables.has(node.right.name));
|
|
428
|
+
if (leftUntrusted || rightUntrusted) {
|
|
429
|
+
// FALSE POSITIVE REDUCTION
|
|
430
|
+
if (safetyChecker.isSafe(node, context) || hasSafeAnnotationOnStatement(node)) {
|
|
431
|
+
return;
|
|
463
432
|
}
|
|
433
|
+
context.report({
|
|
434
|
+
node,
|
|
435
|
+
messageId: 'xpathInjection',
|
|
436
|
+
data: {
|
|
437
|
+
filePath: filename,
|
|
438
|
+
line: String(node.loc?.start.line ?? 0),
|
|
439
|
+
severity: 'HIGH',
|
|
440
|
+
safeAlternative: 'Use parameterized XPath construction with input validation',
|
|
441
|
+
},
|
|
442
|
+
});
|
|
464
443
|
}
|
|
465
444
|
},
|
|
466
445
|
// Check variable assignments with XPath expressions
|
|
@@ -496,12 +475,7 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
|
|
|
496
475
|
});
|
|
497
476
|
}
|
|
498
477
|
}
|
|
499
|
-
else if (isUntrustedXpathInput(node.init)
|
|
500
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
501
|
-
if (safetyChecker.isSafe(node.init, context)) {
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
/* c8 ignore stop */
|
|
478
|
+
else if (isUntrustedXpathInput(node.init)) {
|
|
505
479
|
context.report({
|
|
506
480
|
node: node.init,
|
|
507
481
|
messageId: 'xpathInjection',
|
|
@@ -61,7 +61,7 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
|
|
|
61
61
|
description: 'Detect XML External Entity (XXE) injection vulnerabilities',
|
|
62
62
|
url: 'https://cwe.mitre.org/data/definitions/611.html',
|
|
63
63
|
cwe: 'CWE-611',
|
|
64
|
-
cvss: 9.
|
|
64
|
+
cvss: 9.1,
|
|
65
65
|
},
|
|
66
66
|
messages: {
|
|
67
67
|
xxeInjection: (0, eslint_devkit_2.formatLLMMessage)({
|
|
@@ -125,7 +125,10 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
|
|
|
125
125
|
},
|
|
126
126
|
],
|
|
127
127
|
create(context, [options]) {
|
|
128
|
-
|
|
128
|
+
// `options` is guaranteed defined here: createRule's RuleCreator wrapper
|
|
129
|
+
// (@typescript-eslint/utils applyDefault) always seeds it from
|
|
130
|
+
// `defaultOptions` above, so it can never be undefined at runtime.
|
|
131
|
+
const { safeParserOptions = ['noent', 'resolveExternals', 'expandEntityReferences', 'entityResolver'], xmlValidationFunctions = ['validateXml', 'sanitizeXml', 'cleanXml', 'parseXmlSafe'], } = options;
|
|
129
132
|
const filename = context.filename;
|
|
130
133
|
/**
|
|
131
134
|
* Check if parser options are secure
|
|
@@ -18,7 +18,7 @@ exports.requireBackendAuthorization = (0, eslint_devkit_1.createRule)({
|
|
|
18
18
|
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/require-backend-authorization.md',
|
|
19
19
|
description: 'Require server-side authorization checks',
|
|
20
20
|
cwe: 'CWE-602',
|
|
21
|
-
cvss:
|
|
21
|
+
cvss: 6.5,
|
|
22
22
|
},
|
|
23
23
|
messages: {
|
|
24
24
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|