eslint-plugin-secure-coding 3.4.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -18
- package/src/index.d.ts +17 -23
- package/src/index.js +2 -131
- package/src/oxlint.d.ts +17 -20
- package/src/oxlint.js +0 -18
- package/src/rules/detect-non-literal-regexp/index.js +5 -79
- package/src/rules/detect-object-injection/index.js +2 -221
- package/src/rules/detect-weak-password-validation/index.js +0 -12
- package/src/rules/no-directive-injection/index.js +0 -33
- package/src/rules/no-electron-security-issues/index.js +0 -41
- package/src/rules/no-format-string-injection/index.js +0 -82
- package/src/rules/no-graphql-injection/index.js +8 -133
- package/src/rules/no-hardcoded-credentials/index.js +3 -297
- package/src/rules/no-hardcoded-session-tokens/index.js +0 -11
- package/src/rules/no-improper-sanitization/index.js +0 -44
- package/src/rules/no-improper-type-validation/index.js +1 -51
- package/src/rules/no-insecure-comparison/index.js +2 -43
- package/src/rules/no-ldap-injection/index.js +8 -61
- package/src/rules/no-missing-authentication/index.js +2 -56
- package/src/rules/no-pii-in-logs/index.js +0 -13
- package/src/rules/no-privilege-escalation/index.js +2 -49
- package/src/rules/no-redos-vulnerable-regex/index.js +3 -49
- package/src/rules/no-sensitive-data-exposure/index.js +5 -29
- package/src/rules/no-template-injection/index.js +0 -6
- package/src/rules/no-unchecked-loop-condition/index.js +3 -99
- package/src/rules/no-unlimited-resource-allocation/index.js +2 -75
- package/src/rules/no-unsafe-deserialization/index.js +1 -111
- package/src/rules/no-unsafe-regex-construction/index.js +22 -62
- package/src/rules/no-weak-password-recovery/index.js +0 -43
- package/src/rules/no-xpath-injection/index.js +13 -75
- package/src/rules/no-xxe-injection/index.js +1 -47
- package/src/rules/require-backend-authorization/index.js +0 -10
- package/src/rules/require-secure-defaults/index.js +0 -10
- package/src/types/index.js +0 -5
- package/AGENTS.md +0 -131
- package/CHANGELOG.md +0 -379
- package/src/rules/detect-non-literal-regexp/index.d.ts +0 -28
- package/src/rules/detect-object-injection/index.d.ts +0 -35
- package/src/rules/detect-weak-password-validation/index.d.ts +0 -12
- package/src/rules/no-directive-injection/index.d.ts +0 -38
- package/src/rules/no-electron-security-issues/index.d.ts +0 -36
- package/src/rules/no-format-string-injection/index.d.ts +0 -44
- package/src/rules/no-graphql-injection/index.d.ts +0 -47
- package/src/rules/no-hardcoded-credentials/index.d.ts +0 -95
- package/src/rules/no-hardcoded-session-tokens/index.d.ts +0 -12
- package/src/rules/no-improper-sanitization/index.d.ts +0 -38
- package/src/rules/no-improper-type-validation/index.d.ts +0 -36
- package/src/rules/no-insecure-comparison/index.d.ts +0 -26
- package/src/rules/no-ldap-injection/index.d.ts +0 -53
- package/src/rules/no-missing-authentication/index.d.ts +0 -32
- package/src/rules/no-pii-in-logs/index.d.ts +0 -12
- package/src/rules/no-privilege-escalation/index.d.ts +0 -32
- package/src/rules/no-redos-vulnerable-regex/index.d.ts +0 -28
- package/src/rules/no-sensitive-data-exposure/index.d.ts +0 -30
- package/src/rules/no-template-injection/index.d.ts +0 -23
- package/src/rules/no-unchecked-loop-condition/index.d.ts +0 -38
- package/src/rules/no-unlimited-resource-allocation/index.d.ts +0 -38
- package/src/rules/no-unsafe-deserialization/index.d.ts +0 -40
- package/src/rules/no-unsafe-regex-construction/index.d.ts +0 -30
- package/src/rules/no-weak-password-recovery/index.d.ts +0 -38
- package/src/rules/no-xpath-injection/index.d.ts +0 -39
- package/src/rules/no-xxe-injection/index.d.ts +0 -36
- package/src/rules/require-backend-authorization/index.d.ts +0 -12
- package/src/rules/require-secure-defaults/index.d.ts +0 -12
|
@@ -1,18 +1,11 @@
|
|
|
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.noRedosVulnerableRegex = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
6
|
const regexpp_1 = require("@eslint-community/regexpp");
|
|
12
7
|
const scslre_1 = require("scslre");
|
|
13
|
-
// Module-level parser; cheap to reuse.
|
|
14
8
|
const REGEXPP_PARSER = new regexpp_1.RegExpParser();
|
|
15
|
-
// Type guard for regex literal nodes
|
|
16
9
|
const isRegExpLiteral = (node) => {
|
|
17
10
|
return node.type === 'Literal' && Object.prototype.hasOwnProperty.call(node, 'regex');
|
|
18
11
|
};
|
|
@@ -73,17 +66,12 @@ const REDOS_PATTERNS = [
|
|
|
73
66
|
severity: 'high'
|
|
74
67
|
}
|
|
75
68
|
];
|
|
76
|
-
/**
|
|
77
|
-
* Check if a regex pattern contains ReDoS vulnerabilities
|
|
78
|
-
*/
|
|
79
69
|
function hasReDoSVulnerability(pattern) {
|
|
80
70
|
for (const redosPattern of REDOS_PATTERNS) {
|
|
81
71
|
if (redosPattern.pattern.test(pattern)) {
|
|
82
72
|
return redosPattern;
|
|
83
73
|
}
|
|
84
74
|
}
|
|
85
|
-
// Additional checks for common ReDoS patterns
|
|
86
|
-
// Nested quantifiers: (a+)+, (a*)*, (a?)?
|
|
87
75
|
if (/(\([^)]*[+*?][^)]*\)[+*?])/.test(pattern)) {
|
|
88
76
|
return {
|
|
89
77
|
pattern: /\([^)]*[+*?][^)]*\)[+*?]/,
|
|
@@ -99,9 +87,6 @@ function hasReDoSVulnerability(pattern) {
|
|
|
99
87
|
}
|
|
100
88
|
return null;
|
|
101
89
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Generate fix suggestions based on the vulnerability
|
|
104
|
-
*/
|
|
105
90
|
function generateFixSuggestions(vulnerability) {
|
|
106
91
|
const suggestions = [];
|
|
107
92
|
if (vulnerability.severity === 'critical' || vulnerability.name.includes('Nested')) {
|
|
@@ -207,13 +192,6 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
207
192
|
],
|
|
208
193
|
create(context, [options = {}]) {
|
|
209
194
|
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
195
|
function checkWithScslre(node, pattern, flags) {
|
|
218
196
|
try {
|
|
219
197
|
const ast = REGEXPP_PARSER.parsePattern(pattern, 0, pattern.length, { unicode: flags.includes('u'), unicodeSets: flags.includes('v') });
|
|
@@ -240,24 +218,18 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
240
218
|
return true;
|
|
241
219
|
}
|
|
242
220
|
catch {
|
|
243
|
-
// Fall through to heuristic check
|
|
244
221
|
return false;
|
|
245
222
|
}
|
|
246
223
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Check literal regex patterns for ReDoS vulnerabilities
|
|
249
|
-
*/
|
|
250
224
|
function checkLiteralRegExp(node) {
|
|
251
225
|
if (!isRegExpLiteral(node)) {
|
|
252
226
|
return;
|
|
253
227
|
}
|
|
254
228
|
const pattern = node.regex.pattern;
|
|
255
229
|
const flags = node.regex.flags || '';
|
|
256
|
-
// Skip if pattern is too long (performance)
|
|
257
230
|
if (pattern.length > maxPatternLength) {
|
|
258
231
|
return;
|
|
259
232
|
}
|
|
260
|
-
// NFA-based detection first — catches what heuristics miss.
|
|
261
233
|
if (checkWithScslre(node, pattern, flags)) {
|
|
262
234
|
return;
|
|
263
235
|
}
|
|
@@ -265,7 +237,6 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
265
237
|
if (!vulnerability) {
|
|
266
238
|
return;
|
|
267
239
|
}
|
|
268
|
-
// Allow common patterns if configured
|
|
269
240
|
if (allowCommonPatterns && (vulnerability.severity === 'medium' || vulnerability.name === 'Alternation with Quantifier')) {
|
|
270
241
|
return;
|
|
271
242
|
}
|
|
@@ -282,15 +253,11 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
282
253
|
},
|
|
283
254
|
suggest: suggestions.map(suggestion => ({
|
|
284
255
|
messageId: suggestion.messageId,
|
|
285
|
-
fix: () => null,
|
|
256
|
+
fix: () => null,
|
|
286
257
|
})),
|
|
287
258
|
});
|
|
288
259
|
}
|
|
289
|
-
/**
|
|
290
|
-
* Check new RegExp() calls for ReDoS vulnerabilities
|
|
291
|
-
*/
|
|
292
260
|
function checkNewRegExp(node) {
|
|
293
|
-
// Check for new RegExp(pattern) or RegExp(pattern)
|
|
294
261
|
let callee;
|
|
295
262
|
if (node.type === 'NewExpression') {
|
|
296
263
|
callee = node.callee;
|
|
@@ -305,25 +272,14 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
305
272
|
if (!isRegExp) {
|
|
306
273
|
return;
|
|
307
274
|
}
|
|
308
|
-
// Check if first argument is a string literal
|
|
309
275
|
if (node.arguments.length === 0) {
|
|
310
276
|
return;
|
|
311
277
|
}
|
|
312
278
|
const firstArg = node.arguments[0];
|
|
313
|
-
// Template literal with interpolation — runtime-built pattern.
|
|
314
|
-
// Closes the audit FN where `new RegExp(\`^(\${pattern}+)+$\`)` was
|
|
315
|
-
// bypassing detection. We can't fully analyse the resulting regex
|
|
316
|
-
// (the interpolated parts are user-controlled), but we CAN detect
|
|
317
|
-
// the nested-quantifier signature `+)+`/`+)*`/`*)+`/`*)*` in the
|
|
318
|
-
// static template text — that shape is catastrophic regardless of
|
|
319
|
-
// what the interpolation injects. See benchmarks/AUDIT_PATTERNS.md
|
|
320
|
-
// §3.5 ("Runtime-built patterns").
|
|
321
279
|
if (firstArg.type === 'TemplateLiteral' && firstArg.expressions.length > 0) {
|
|
322
280
|
const concatenated = firstArg.quasis
|
|
323
281
|
.map((q) => q.value.cooked ?? q.value.raw)
|
|
324
|
-
.join('');
|
|
325
|
-
// Look for the nested-quantifier signature on either side of an
|
|
326
|
-
// interpolation: `+)+`, `+)*`, `*)+`, `*)*`, `})+` etc.
|
|
282
|
+
.join('');
|
|
327
283
|
const hasNestedQuantifier = /[+*}](?:\)\s*[+*]|\)\s*\{\s*\d+\s*,?\s*\d*\s*\}|\s*[+*])/.test(concatenated) ||
|
|
328
284
|
/[+*].*\)[+*]/.test(concatenated) ||
|
|
329
285
|
/\([+*]\)[+*]/.test(concatenated);
|
|
@@ -345,7 +301,6 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
345
301
|
return;
|
|
346
302
|
}
|
|
347
303
|
const pattern = firstArg.value;
|
|
348
|
-
// Skip if pattern is too long (performance)
|
|
349
304
|
if (pattern.length > maxPatternLength) {
|
|
350
305
|
return;
|
|
351
306
|
}
|
|
@@ -353,7 +308,6 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
353
308
|
if (!vulnerability) {
|
|
354
309
|
return;
|
|
355
310
|
}
|
|
356
|
-
// Allow common patterns if configured
|
|
357
311
|
if (allowCommonPatterns && (vulnerability.severity === 'medium' || vulnerability.name === 'Alternation with Quantifier')) {
|
|
358
312
|
return;
|
|
359
313
|
}
|
|
@@ -370,7 +324,7 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
370
324
|
},
|
|
371
325
|
suggest: suggestions.map(suggestion => ({
|
|
372
326
|
messageId: suggestion.messageId,
|
|
373
|
-
fix: () => null,
|
|
327
|
+
fix: () => null,
|
|
374
328
|
})),
|
|
375
329
|
});
|
|
376
330
|
}
|
|
@@ -1,25 +1,14 @@
|
|
|
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.noSensitiveDataExposure = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
-
/**
|
|
12
|
-
* Check if string contains sensitive data patterns.
|
|
13
|
-
* Handles camelCase (secretKey), snake_case (secret_key), and plain text.
|
|
14
|
-
*/
|
|
15
6
|
function containsSensitiveData(text, patterns) {
|
|
16
|
-
// Normalize camelCase → space separated for matching (secretKey → secret key)
|
|
17
7
|
const normalized = text
|
|
18
8
|
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
19
9
|
.toLowerCase();
|
|
20
10
|
for (const pattern of patterns) {
|
|
21
11
|
const escaped = pattern.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
22
|
-
// Allow spaces or underscores as word separators (e.g. 'credit card' matches 'credit_card')
|
|
23
12
|
const flexPattern = escaped.replace(/[_ ]/g, '[_ ]');
|
|
24
13
|
if (new RegExp(`\\b${flexPattern}\\b`, 'i').test(normalized)) {
|
|
25
14
|
return pattern;
|
|
@@ -113,11 +102,7 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
113
102
|
],
|
|
114
103
|
create(context, [options = {}]) {
|
|
115
104
|
const { sensitivePatterns = ['password', 'passwd', 'secret', 'token', 'access_token', 'auth_token', 'ssn', 'credit_card', 'creditcard', 'api_key', 'apikey', 'secret_key', 'private_key', 'encryption_key'], checkConsoleLog = true, checkErrorMessages = true, } = options || {};
|
|
116
|
-
/**
|
|
117
|
-
* Check CallExpression for logging calls with sensitive data
|
|
118
|
-
*/
|
|
119
105
|
function checkCallExpression(node) {
|
|
120
|
-
// Check if it's a logging call (console.*, logger.*)
|
|
121
106
|
const isLoggingCall = (() => {
|
|
122
107
|
if (node.callee.type === 'MemberExpression') {
|
|
123
108
|
const object = node.callee.object;
|
|
@@ -125,7 +110,6 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
125
110
|
if (property.type === 'Identifier') {
|
|
126
111
|
const methodName = property.name.toLowerCase();
|
|
127
112
|
if (['log', 'info', 'warn', 'error', 'debug', 'trace'].includes(methodName)) {
|
|
128
|
-
// Check if it's console.* or logger.*
|
|
129
113
|
if (object.type === 'Identifier') {
|
|
130
114
|
const objName = object.name.toLowerCase();
|
|
131
115
|
if (objName === 'console' || objName === 'logger') {
|
|
@@ -136,7 +120,6 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
136
120
|
}
|
|
137
121
|
}
|
|
138
122
|
else if (node.callee.type === 'Identifier') {
|
|
139
|
-
// Check for logger.info() pattern
|
|
140
123
|
const calleeName = node.callee.name.toLowerCase();
|
|
141
124
|
if (calleeName.includes('log') || calleeName.includes('logger')) {
|
|
142
125
|
return true;
|
|
@@ -145,7 +128,6 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
145
128
|
return false;
|
|
146
129
|
})();
|
|
147
130
|
if (isLoggingCall && checkConsoleLog) {
|
|
148
|
-
// Check if any argument contains sensitive data
|
|
149
131
|
for (const arg of node.arguments) {
|
|
150
132
|
if (arg.type === 'Literal' && typeof arg.value === 'string') {
|
|
151
133
|
const text = arg.value;
|
|
@@ -164,7 +146,7 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
164
146
|
{ messageId: 'removeFromLogs', fix: () => null },
|
|
165
147
|
],
|
|
166
148
|
});
|
|
167
|
-
return;
|
|
149
|
+
return;
|
|
168
150
|
}
|
|
169
151
|
}
|
|
170
152
|
else if (arg.type === 'Identifier' && arg.name) {
|
|
@@ -183,21 +165,17 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
183
165
|
{ messageId: 'removeFromLogs', fix: () => null },
|
|
184
166
|
],
|
|
185
167
|
});
|
|
186
|
-
return;
|
|
168
|
+
return;
|
|
187
169
|
}
|
|
188
170
|
}
|
|
189
171
|
}
|
|
190
172
|
}
|
|
191
173
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Check NewExpression for Error with sensitive data
|
|
194
|
-
*/
|
|
195
174
|
function checkNewExpression(node) {
|
|
196
175
|
if (!checkErrorMessages) {
|
|
197
176
|
return;
|
|
198
177
|
}
|
|
199
178
|
if (node.callee && node.callee.type === 'Identifier' && node.callee.name === 'Error') {
|
|
200
|
-
// Check all arguments for sensitive data (report only once per error)
|
|
201
179
|
for (const arg of node.arguments) {
|
|
202
180
|
if (arg.type === 'Literal' && typeof arg.value === 'string') {
|
|
203
181
|
const text = arg.value;
|
|
@@ -216,11 +194,10 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
216
194
|
{ messageId: 'removeFromLogs', fix: () => null },
|
|
217
195
|
],
|
|
218
196
|
});
|
|
219
|
-
return;
|
|
197
|
+
return;
|
|
220
198
|
}
|
|
221
199
|
}
|
|
222
200
|
else if (arg.type === 'BinaryExpression' && arg.operator === '+') {
|
|
223
|
-
// Check left side if it's a literal
|
|
224
201
|
if (arg.left && arg.left.type === 'Literal' && typeof arg.left.value === 'string') {
|
|
225
202
|
const leftText = arg.left.value;
|
|
226
203
|
const leftMatchedPattern = containsSensitiveData(leftText, sensitivePatterns);
|
|
@@ -238,10 +215,9 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
238
215
|
{ messageId: 'removeFromLogs', fix: () => null },
|
|
239
216
|
],
|
|
240
217
|
});
|
|
241
|
-
return;
|
|
218
|
+
return;
|
|
242
219
|
}
|
|
243
220
|
}
|
|
244
|
-
// Check right side if it's an identifier
|
|
245
221
|
if (arg.right && arg.right.type === 'Identifier' && arg.right.name) {
|
|
246
222
|
const rightMatchedPattern = containsSensitiveData(arg.right.name, sensitivePatterns);
|
|
247
223
|
if (rightMatchedPattern) {
|
|
@@ -258,7 +234,7 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
258
234
|
{ messageId: 'removeFromLogs', fix: () => null },
|
|
259
235
|
],
|
|
260
236
|
});
|
|
261
|
-
return;
|
|
237
|
+
return;
|
|
262
238
|
}
|
|
263
239
|
}
|
|
264
240
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.noTemplateInjection = void 0;
|
|
8
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -71,11 +67,9 @@ exports.noTemplateInjection = (0, eslint_devkit_1.createRule)({
|
|
|
71
67
|
const firstArg = args[0];
|
|
72
68
|
if (!firstArg)
|
|
73
69
|
return;
|
|
74
|
-
// String literal → safe (static template, no injection surface)
|
|
75
70
|
if (firstArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
76
71
|
typeof firstArg.value === 'string')
|
|
77
72
|
return;
|
|
78
|
-
// Template literal with NO expressions → safe (equivalent to a string literal)
|
|
79
73
|
if (firstArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral &&
|
|
80
74
|
firstArg.expressions.length === 0)
|
|
81
75
|
return;
|