eslint-plugin-secure-coding 3.4.3 → 3.5.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.
- package/README.md +1 -1
- package/package.json +3 -3
- package/src/index.js +1 -107
- package/src/oxlint.js +1 -3
- package/src/rules/detect-non-literal-regexp/index.js +1 -329
- package/src/rules/detect-object-injection/index.js +1 -691
- package/src/rules/detect-weak-password-validation/index.js +1 -54
- package/src/rules/no-directive-injection/index.js +1 -416
- package/src/rules/no-electron-security-issues/index.js +1 -385
- package/src/rules/no-format-string-injection/index.js +1 -565
- package/src/rules/no-graphql-injection/index.js +1 -612
- package/src/rules/no-hardcoded-credentials/index.js +1 -658
- package/src/rules/no-hardcoded-session-tokens/index.js +1 -56
- package/src/rules/no-improper-sanitization/index.js +1 -391
- package/src/rules/no-improper-type-validation/index.js +1 -422
- package/src/rules/no-insecure-comparison/index.js +1 -249
- package/src/rules/no-ldap-injection/index.js +1 -403
- package/src/rules/no-missing-authentication/index.js +1 -282
- package/src/rules/no-pii-in-logs/index.js +1 -63
- package/src/rules/no-privilege-escalation/index.js +1 -282
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -0
- package/src/rules/no-sensitive-data-exposure/index.js +1 -249
- package/src/rules/no-template-injection/index.js +1 -84
- package/src/rules/no-unchecked-loop-condition/index.js +1 -541
- package/src/rules/no-unlimited-resource-allocation/index.js +1 -555
- package/src/rules/no-unsafe-deserialization/index.js +1 -497
- package/src/rules/no-unsafe-regex-construction/index.js +1 -275
- package/src/rules/no-weak-password-recovery/index.js +1 -382
- package/src/rules/no-xpath-injection/index.js +1 -431
- package/src/rules/no-xxe-injection/index.js +1 -230
- package/src/rules/require-backend-authorization/index.js +1 -58
- package/src/rules/require-secure-defaults/index.js +1 -41
- package/src/types/index.js +1 -2
|
@@ -1,382 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noWeakPasswordRecovery = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
const eslint_devkit_3 = require("@interlace/eslint-devkit");
|
|
7
|
-
exports.noWeakPasswordRecovery = (0, eslint_devkit_1.createRule)({
|
|
8
|
-
name: 'no-weak-password-recovery',
|
|
9
|
-
meta: {
|
|
10
|
-
type: 'problem',
|
|
11
|
-
docs: {
|
|
12
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-weak-password-recovery.md',
|
|
13
|
-
description: 'Detects weak password recovery mechanisms',
|
|
14
|
-
cwe: 'CWE-640',
|
|
15
|
-
},
|
|
16
|
-
hasSuggestions: true,
|
|
17
|
-
messages: {
|
|
18
|
-
weakPasswordRecovery: (0, eslint_devkit_2.formatLLMMessage)({
|
|
19
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
20
|
-
issueName: 'Weak Password Recovery',
|
|
21
|
-
cwe: 'CWE-640',
|
|
22
|
-
description: 'Password recovery mechanism has security weaknesses',
|
|
23
|
-
severity: '{{severity}}',
|
|
24
|
-
fix: '{{safeAlternative}}',
|
|
25
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
26
|
-
}),
|
|
27
|
-
missingRateLimit: (0, eslint_devkit_2.formatLLMMessage)({
|
|
28
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
29
|
-
issueName: 'Missing Rate Limit',
|
|
30
|
-
cwe: 'CWE-640',
|
|
31
|
-
description: 'Password recovery attempts not rate limited',
|
|
32
|
-
severity: 'HIGH',
|
|
33
|
-
fix: 'Implement rate limiting on recovery requests',
|
|
34
|
-
documentationLink: 'https://owasp.org/www-community/attacks/Brute_force_attack',
|
|
35
|
-
}),
|
|
36
|
-
predictableRecoveryToken: (0, eslint_devkit_2.formatLLMMessage)({
|
|
37
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
38
|
-
issueName: 'Predictable Recovery Token',
|
|
39
|
-
cwe: 'CWE-640',
|
|
40
|
-
description: 'Recovery token can be predicted or guessed',
|
|
41
|
-
severity: 'CRITICAL',
|
|
42
|
-
fix: 'Use cryptographically secure random tokens',
|
|
43
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
44
|
-
}),
|
|
45
|
-
unlimitedRecoveryAttempts: (0, eslint_devkit_2.formatLLMMessage)({
|
|
46
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
47
|
-
issueName: 'Unlimited Recovery Attempts',
|
|
48
|
-
cwe: 'CWE-640',
|
|
49
|
-
description: 'No limit on password recovery attempts',
|
|
50
|
-
severity: 'MEDIUM',
|
|
51
|
-
fix: 'Limit recovery attempts per time period',
|
|
52
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
53
|
-
}),
|
|
54
|
-
insufficientTokenEntropy: (0, eslint_devkit_2.formatLLMMessage)({
|
|
55
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
56
|
-
issueName: 'Insufficient Token Entropy',
|
|
57
|
-
cwe: 'CWE-640',
|
|
58
|
-
description: 'Recovery token has insufficient randomness',
|
|
59
|
-
severity: 'HIGH',
|
|
60
|
-
fix: 'Use at least 128-bit entropy for tokens',
|
|
61
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
62
|
-
}),
|
|
63
|
-
missingTokenExpiration: (0, eslint_devkit_2.formatLLMMessage)({
|
|
64
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
65
|
-
issueName: 'Missing Token Expiration',
|
|
66
|
-
cwe: 'CWE-640',
|
|
67
|
-
description: 'Recovery tokens never expire',
|
|
68
|
-
severity: 'HIGH',
|
|
69
|
-
fix: 'Implement token expiration (15-60 minutes)',
|
|
70
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
71
|
-
}),
|
|
72
|
-
recoveryLoggingSensitiveData: (0, eslint_devkit_2.formatLLMMessage)({
|
|
73
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
74
|
-
issueName: 'Recovery Logging Sensitive Data',
|
|
75
|
-
cwe: 'CWE-640',
|
|
76
|
-
description: 'Logging sensitive data during password recovery',
|
|
77
|
-
severity: 'MEDIUM',
|
|
78
|
-
fix: 'Never log passwords, tokens, or sensitive recovery data',
|
|
79
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
80
|
-
}),
|
|
81
|
-
weakRecoveryVerification: (0, eslint_devkit_2.formatLLMMessage)({
|
|
82
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
83
|
-
issueName: 'Weak Recovery Verification',
|
|
84
|
-
cwe: 'CWE-640',
|
|
85
|
-
description: 'Recovery request verification is insufficient',
|
|
86
|
-
severity: 'HIGH',
|
|
87
|
-
fix: 'Require strong verification (email + SMS, security questions)',
|
|
88
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
89
|
-
}),
|
|
90
|
-
tokenReuseVulnerability: (0, eslint_devkit_2.formatLLMMessage)({
|
|
91
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
92
|
-
issueName: 'Token Reuse Vulnerability',
|
|
93
|
-
cwe: 'CWE-640',
|
|
94
|
-
description: 'Recovery tokens can be reused',
|
|
95
|
-
severity: 'HIGH',
|
|
96
|
-
fix: 'Mark tokens as used after successful recovery',
|
|
97
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
98
|
-
}),
|
|
99
|
-
implementRateLimiting: (0, eslint_devkit_2.formatLLMMessage)({
|
|
100
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
101
|
-
issueName: 'Implement Rate Limiting',
|
|
102
|
-
description: 'Add rate limiting to recovery endpoints',
|
|
103
|
-
severity: 'LOW',
|
|
104
|
-
fix: 'Limit recovery attempts to 5 per hour per IP/user',
|
|
105
|
-
documentationLink: 'https://owasp.org/www-community/attacks/Brute_force_attack',
|
|
106
|
-
}),
|
|
107
|
-
useCryptographicallySecureTokens: (0, eslint_devkit_2.formatLLMMessage)({
|
|
108
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
109
|
-
issueName: 'Use Cryptographically Secure Tokens',
|
|
110
|
-
description: 'Generate tokens with crypto.randomBytes()',
|
|
111
|
-
severity: 'LOW',
|
|
112
|
-
fix: 'const token = crypto.randomBytes(32).toString("hex");',
|
|
113
|
-
documentationLink: 'https://nodejs.org/api/crypto.html#cryptorandombytessize-callback',
|
|
114
|
-
}),
|
|
115
|
-
implementTokenExpiration: (0, eslint_devkit_2.formatLLMMessage)({
|
|
116
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
117
|
-
issueName: 'Implement Token Expiration',
|
|
118
|
-
description: 'Set reasonable token expiration times',
|
|
119
|
-
severity: 'LOW',
|
|
120
|
-
fix: 'Expire tokens after 15-60 minutes',
|
|
121
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
122
|
-
}),
|
|
123
|
-
secureRecoveryFlow: (0, eslint_devkit_2.formatLLMMessage)({
|
|
124
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
125
|
-
issueName: 'Secure Recovery Flow',
|
|
126
|
-
description: 'Implement secure password recovery flow',
|
|
127
|
-
severity: 'LOW',
|
|
128
|
-
fix: 'Verify identity, send secure link, require current password',
|
|
129
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Forgot_Password_Cheat_Sheet.html',
|
|
130
|
-
}),
|
|
131
|
-
strategyMultiFactor: (0, eslint_devkit_2.formatLLMMessage)({
|
|
132
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
133
|
-
issueName: 'Multi-Factor Strategy',
|
|
134
|
-
description: 'Require multiple verification factors',
|
|
135
|
-
severity: 'LOW',
|
|
136
|
-
fix: 'Email + SMS verification for password recovery',
|
|
137
|
-
documentationLink: 'https://owasp.org/www-community/attacks/Brute_force_attack',
|
|
138
|
-
}),
|
|
139
|
-
strategyOutOfBandVerification: (0, eslint_devkit_2.formatLLMMessage)({
|
|
140
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
141
|
-
issueName: 'Out-of-Band Verification Strategy',
|
|
142
|
-
description: 'Use out-of-band verification channels',
|
|
143
|
-
severity: 'LOW',
|
|
144
|
-
fix: 'Send recovery codes via SMS or authenticator app',
|
|
145
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Forgot_Password_Cheat_Sheet.html',
|
|
146
|
-
}),
|
|
147
|
-
strategyTimeBoundTokens: (0, eslint_devkit_2.formatLLMMessage)({
|
|
148
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
149
|
-
issueName: 'Time-Bound Tokens Strategy',
|
|
150
|
-
description: 'Use time-bound recovery tokens',
|
|
151
|
-
severity: 'LOW',
|
|
152
|
-
fix: 'Tokens expire quickly and can only be used once',
|
|
153
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
|
|
154
|
-
})
|
|
155
|
-
},
|
|
156
|
-
schema: [
|
|
157
|
-
{
|
|
158
|
-
type: 'object',
|
|
159
|
-
properties: {
|
|
160
|
-
minTokenEntropy: {
|
|
161
|
-
type: 'number',
|
|
162
|
-
minimum: 64,
|
|
163
|
-
default: 128, description: 'Minimum recovery-token entropy in bits'
|
|
164
|
-
},
|
|
165
|
-
maxTokenLifetimeHours: {
|
|
166
|
-
type: 'number',
|
|
167
|
-
minimum: 0.25,
|
|
168
|
-
default: 1, description: 'Maximum recovery-token lifetime in hours'
|
|
169
|
-
},
|
|
170
|
-
recoveryKeywords: {
|
|
171
|
-
type: 'array',
|
|
172
|
-
items: { type: 'string' },
|
|
173
|
-
default: ['reset', 'password', 'recovery', 'forgot', 'token', 'resetToken'], description: 'Identifier keywords that mark password-recovery code'
|
|
174
|
-
},
|
|
175
|
-
secureTokenFunctions: {
|
|
176
|
-
type: 'array',
|
|
177
|
-
items: { type: 'string' },
|
|
178
|
-
default: ['crypto.randomBytes', 'crypto.randomUUID', 'randomBytes', 'generateSecureToken'], description: 'Functions that generate cryptographically secure tokens'
|
|
179
|
-
},
|
|
180
|
-
trustedSanitizers: {
|
|
181
|
-
type: 'array',
|
|
182
|
-
items: { type: 'string' },
|
|
183
|
-
default: [],
|
|
184
|
-
description: 'Additional function names to consider as secure',
|
|
185
|
-
},
|
|
186
|
-
trustedAnnotations: {
|
|
187
|
-
type: 'array',
|
|
188
|
-
items: { type: 'string' },
|
|
189
|
-
default: [],
|
|
190
|
-
description: 'Additional JSDoc annotations to consider as safe markers',
|
|
191
|
-
},
|
|
192
|
-
strictMode: {
|
|
193
|
-
type: 'boolean',
|
|
194
|
-
default: false,
|
|
195
|
-
description: 'Disable all false positive detection (strict mode)',
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
additionalProperties: false,
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
},
|
|
202
|
-
defaultOptions: [
|
|
203
|
-
{
|
|
204
|
-
minTokenEntropy: 128,
|
|
205
|
-
maxTokenLifetimeHours: 1,
|
|
206
|
-
recoveryKeywords: ['reset', 'password', 'recovery', 'forgot', 'token', 'resetToken'],
|
|
207
|
-
secureTokenFunctions: ['crypto.randomBytes', 'crypto.randomUUID', 'randomBytes', 'generateSecureToken'],
|
|
208
|
-
trustedSanitizers: [],
|
|
209
|
-
trustedAnnotations: [],
|
|
210
|
-
strictMode: false,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
create(context) {
|
|
214
|
-
const options = context.options[0] || {};
|
|
215
|
-
const { secureTokenFunctions = ['crypto.randomBytes', 'crypto.randomUUID', 'randomBytes', 'generateSecureToken'], trustedSanitizers = [], trustedAnnotations = ['secure-recovery', 'rate-limited'], strictMode = false, } = options;
|
|
216
|
-
const sourceCode = context.sourceCode;
|
|
217
|
-
const filename = context.filename;
|
|
218
|
-
const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
|
|
219
|
-
trustedSanitizers,
|
|
220
|
-
trustedAnnotations,
|
|
221
|
-
trustedOrmPatterns: [],
|
|
222
|
-
strictMode,
|
|
223
|
-
});
|
|
224
|
-
const isRecoveryRelated = (text) => {
|
|
225
|
-
const lowerText = text.toLowerCase();
|
|
226
|
-
const passwordKeywords = ['password', 'pwd'];
|
|
227
|
-
const recoveryKeywords = ['reset', 'recover', 'forgot', 'restore'];
|
|
228
|
-
const hasPasswordKeyword = passwordKeywords.some(keyword => lowerText.includes(keyword));
|
|
229
|
-
const hasRecoveryKeyword = recoveryKeywords.some(keyword => lowerText.includes(keyword));
|
|
230
|
-
if (hasPasswordKeyword && hasRecoveryKeyword) {
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
const strongRecoveryPatterns = [
|
|
234
|
-
'resetpassword', 'passwordreset', 'forgotpassword', 'passwordrecovery',
|
|
235
|
-
'recoverytoken', 'password_reset', 'forgot_password', 'reset_password',
|
|
236
|
-
'passwordforgot', 'recoverpassword'
|
|
237
|
-
];
|
|
238
|
-
return strongRecoveryPatterns.some(pattern => lowerText.includes(pattern));
|
|
239
|
-
};
|
|
240
|
-
const isSecureTokenGeneration = (callExpression) => {
|
|
241
|
-
const callText = sourceCode.getText(callExpression);
|
|
242
|
-
return secureTokenFunctions.some(func => callText.includes(func));
|
|
243
|
-
};
|
|
244
|
-
const hasTokenExpiration = (functionNode) => {
|
|
245
|
-
const functionText = sourceCode.getText(functionNode).toLowerCase();
|
|
246
|
-
return functionText.includes('expire') ||
|
|
247
|
-
functionText.includes('ttl') ||
|
|
248
|
-
functionText.includes('timeout') ||
|
|
249
|
-
functionText.includes('lifetime');
|
|
250
|
-
};
|
|
251
|
-
return {
|
|
252
|
-
VariableDeclarator(node) {
|
|
253
|
-
if (!node.init || node.id.type !== 'Identifier') {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const varName = node.id.name.toLowerCase();
|
|
257
|
-
if (isRecoveryRelated(varName)) {
|
|
258
|
-
const initText = sourceCode.getText(node.init);
|
|
259
|
-
if (node.init.type === 'CallExpression') {
|
|
260
|
-
if (!isSecureTokenGeneration(node.init)) {
|
|
261
|
-
if (safetyChecker.isSafe(node, context) || (node.parent && safetyChecker.isSafe(node.parent, context))) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
context.report({
|
|
265
|
-
node: node.init,
|
|
266
|
-
messageId: 'predictableRecoveryToken',
|
|
267
|
-
data: {
|
|
268
|
-
filePath: filename,
|
|
269
|
-
line: String(node.loc?.start.line ?? 0),
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else if (node.init.type === 'BinaryExpression') {
|
|
275
|
-
const weakPatterns = ['Date.now()', 'Math.random()', 'timestamp', 'new Date()'];
|
|
276
|
-
if (weakPatterns.some(pattern => initText.includes(pattern))) {
|
|
277
|
-
if (safetyChecker.isSafe(node, context) || (node.parent && safetyChecker.isSafe(node.parent, context))) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
context.report({
|
|
281
|
-
node: node.init,
|
|
282
|
-
messageId: 'insufficientTokenEntropy',
|
|
283
|
-
data: {
|
|
284
|
-
filePath: filename,
|
|
285
|
-
line: String(node.loc?.start.line ?? 0),
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
FunctionDeclaration(node) {
|
|
293
|
-
if (!node.id) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const functionName = node.id.name;
|
|
297
|
-
const functionText = sourceCode.getText(node).toLowerCase();
|
|
298
|
-
if (isRecoveryRelated(functionName)) {
|
|
299
|
-
if (!hasTokenExpiration(node)) {
|
|
300
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
context.report({
|
|
304
|
-
node: node.id,
|
|
305
|
-
messageId: 'missingTokenExpiration',
|
|
306
|
-
data: {
|
|
307
|
-
filePath: filename,
|
|
308
|
-
line: String(node.loc?.start.line ?? 0),
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
if (!functionText.includes('limit') && !functionText.includes('rate')) {
|
|
313
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
context.report({
|
|
317
|
-
node: node.id,
|
|
318
|
-
messageId: 'missingRateLimit',
|
|
319
|
-
data: {
|
|
320
|
-
filePath: filename,
|
|
321
|
-
line: String(node.loc?.start.line ?? 0),
|
|
322
|
-
},
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
CallExpression(node) {
|
|
328
|
-
const callee = node.callee;
|
|
329
|
-
if ((callee.type === 'MemberExpression' &&
|
|
330
|
-
callee.object.type === 'Identifier' &&
|
|
331
|
-
(callee.object.name === 'console' || callee.object.name === 'logger') &&
|
|
332
|
-
callee.property.type === 'Identifier' &&
|
|
333
|
-
['log', 'info', 'warn', 'error'].includes(callee.property.name)) ||
|
|
334
|
-
(callee.type === 'Identifier' && callee.name === 'logger')) {
|
|
335
|
-
const args = node.arguments;
|
|
336
|
-
for (const arg of args) {
|
|
337
|
-
if (arg.type === 'Literal') {
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
const argText = sourceCode.getText(arg).toLowerCase();
|
|
341
|
-
if (isRecoveryRelated(argText) &&
|
|
342
|
-
(argText.includes('token') || argText.includes('password') ||
|
|
343
|
-
argText.includes('reset') || argText.includes('code'))) {
|
|
344
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
345
|
-
continue;
|
|
346
|
-
}
|
|
347
|
-
context.report({
|
|
348
|
-
node: arg,
|
|
349
|
-
messageId: 'recoveryLoggingSensitiveData',
|
|
350
|
-
data: {
|
|
351
|
-
filePath: filename,
|
|
352
|
-
line: String(node.loc?.start.line ?? 0),
|
|
353
|
-
},
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
},
|
|
359
|
-
IfStatement(node) {
|
|
360
|
-
const test = node.test;
|
|
361
|
-
const testText = sourceCode.getText(test).toLowerCase();
|
|
362
|
-
if (isRecoveryRelated(testText)) {
|
|
363
|
-
if (testText.includes('email') && !testText.includes('verify') &&
|
|
364
|
-
!testText.includes('token') && !testText.includes('code') &&
|
|
365
|
-
!testText.includes('otp') && !testText.includes('sms')) {
|
|
366
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
context.report({
|
|
370
|
-
node: test,
|
|
371
|
-
messageId: 'weakRecoveryVerification',
|
|
372
|
-
data: {
|
|
373
|
-
filePath: filename,
|
|
374
|
-
line: String(node.loc?.start.line ?? 0),
|
|
375
|
-
},
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
},
|
|
382
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noWeakPasswordRecovery=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const eslint_devkit_3=require("@interlace/eslint-devkit");exports.noWeakPasswordRecovery=(0,eslint_devkit_1.createRule)({name:"no-weak-password-recovery",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-weak-password-recovery.md",description:"Detects weak password recovery mechanisms",cwe:"CWE-640"},messages:{weakPasswordRecovery:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Weak Password Recovery",cwe:"CWE-640",description:"Password recovery mechanism has security weaknesses",severity:"{{severity}}",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),missingRateLimit:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Missing Rate Limit",cwe:"CWE-640",description:"Password recovery attempts not rate limited",severity:"HIGH",fix:"Implement rate limiting on recovery requests",documentationLink:"https://owasp.org/www-community/attacks/Brute_force_attack"}),predictableRecoveryToken:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Predictable Recovery Token",cwe:"CWE-640",description:"Recovery token can be predicted or guessed",severity:"CRITICAL",fix:"Use cryptographically secure random tokens",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),unlimitedRecoveryAttempts:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unlimited Recovery Attempts",cwe:"CWE-640",description:"No limit on password recovery attempts",severity:"MEDIUM",fix:"Limit recovery attempts per time period",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),insufficientTokenEntropy:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Insufficient Token Entropy",cwe:"CWE-640",description:"Recovery token has insufficient randomness",severity:"HIGH",fix:"Use at least 128-bit entropy for tokens",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),missingTokenExpiration:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Missing Token Expiration",cwe:"CWE-640",description:"Recovery tokens never expire",severity:"HIGH",fix:"Implement token expiration (15-60 minutes)",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),recoveryLoggingSensitiveData:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Recovery Logging Sensitive Data",cwe:"CWE-640",description:"Logging sensitive data during password recovery",severity:"MEDIUM",fix:"Never log passwords, tokens, or sensitive recovery data",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),weakRecoveryVerification:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Weak Recovery Verification",cwe:"CWE-640",description:"Recovery request verification is insufficient",severity:"HIGH",fix:"Require strong verification (email + SMS, security questions)",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),tokenReuseVulnerability:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Token Reuse Vulnerability",cwe:"CWE-640",description:"Recovery tokens can be reused",severity:"HIGH",fix:"Mark tokens as used after successful recovery",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),implementRateLimiting:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Implement Rate Limiting",description:"Add rate limiting to recovery endpoints",severity:"LOW",fix:"Limit recovery attempts to 5 per hour per IP/user",documentationLink:"https://owasp.org/www-community/attacks/Brute_force_attack"}),useCryptographicallySecureTokens:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use Cryptographically Secure Tokens",description:"Generate tokens with crypto.randomBytes()",severity:"LOW",fix:'const token = crypto.randomBytes(32).toString("hex");',documentationLink:"https://nodejs.org/api/crypto.html#cryptorandombytessize-callback"}),implementTokenExpiration:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Implement Token Expiration",description:"Set reasonable token expiration times",severity:"LOW",fix:"Expire tokens after 15-60 minutes",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),secureRecoveryFlow:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Secure Recovery Flow",description:"Implement secure password recovery flow",severity:"LOW",fix:"Verify identity, send secure link, require current password",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Forgot_Password_Cheat_Sheet.html"}),strategyMultiFactor:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Multi-Factor Strategy",description:"Require multiple verification factors",severity:"LOW",fix:"Email + SMS verification for password recovery",documentationLink:"https://owasp.org/www-community/attacks/Brute_force_attack"}),strategyOutOfBandVerification:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Out-of-Band Verification Strategy",description:"Use out-of-band verification channels",severity:"LOW",fix:"Send recovery codes via SMS or authenticator app",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Forgot_Password_Cheat_Sheet.html"}),strategyTimeBoundTokens:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Time-Bound Tokens Strategy",description:"Use time-bound recovery tokens",severity:"LOW",fix:"Tokens expire quickly and can only be used once",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"})},schema:[{type:"object",properties:{minTokenEntropy:{type:"number",minimum:64,default:128,description:"Minimum recovery-token entropy in bits"},maxTokenLifetimeHours:{type:"number",minimum:.25,default:1,description:"Maximum recovery-token lifetime in hours"},recoveryKeywords:{type:"array",items:{type:"string"},default:["reset","password","recovery","forgot","token","resetToken"],description:"Identifier keywords that mark password-recovery code"},secureTokenFunctions:{type:"array",items:{type:"string"},default:["crypto.randomBytes","crypto.randomUUID","randomBytes","generateSecureToken"],description:"Functions that generate cryptographically secure tokens"},trustedSanitizers:{type:"array",items:{type:"string"},default:[],description:"Additional function names to consider as secure"},trustedAnnotations:{type:"array",items:{type:"string"},default:[],description:"Additional JSDoc annotations to consider as safe markers"},strictMode:{type:"boolean",default:false,description:"Disable all false positive detection (strict mode)"}},additionalProperties:false}]},defaultOptions:[{minTokenEntropy:128,maxTokenLifetimeHours:1,recoveryKeywords:["reset","password","recovery","forgot","token","resetToken"],secureTokenFunctions:["crypto.randomBytes","crypto.randomUUID","randomBytes","generateSecureToken"],trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]||{};const{secureTokenFunctions=["crypto.randomBytes","crypto.randomUUID","randomBytes","generateSecureToken"],trustedSanitizers=[],trustedAnnotations=["secure-recovery","rate-limited"],strictMode=false}=options;const sourceCode=context.sourceCode;const filename=context.filename;const safetyChecker=(0,eslint_devkit_3.createSafetyChecker)({trustedSanitizers,trustedAnnotations,trustedOrmPatterns:[],strictMode});const isRecoveryRelated=text=>{const lowerText=text.toLowerCase();const passwordKeywords=["password","pwd"];const recoveryKeywords=["reset","recover","forgot","restore"];const hasPasswordKeyword=passwordKeywords.some(keyword=>lowerText.includes(keyword));const hasRecoveryKeyword=recoveryKeywords.some(keyword=>lowerText.includes(keyword));if(hasPasswordKeyword&&hasRecoveryKeyword){return true}const strongRecoveryPatterns=["resetpassword","passwordreset","forgotpassword","passwordrecovery","recoverytoken","password_reset","forgot_password","reset_password","passwordforgot","recoverpassword"];return strongRecoveryPatterns.some(pattern=>lowerText.includes(pattern))};const isSecureTokenGeneration=callExpression=>{const callText=sourceCode.getText(callExpression);return secureTokenFunctions.some(func=>callText.includes(func))};const hasTokenExpiration=functionNode=>{const functionText=sourceCode.getText(functionNode).toLowerCase();return functionText.includes("expire")||functionText.includes("ttl")||functionText.includes("timeout")||functionText.includes("lifetime")};return{VariableDeclarator(node){if(!node.init||node.id.type!=="Identifier"){return}const varName=node.id.name.toLowerCase();if(isRecoveryRelated(varName)){const initText=sourceCode.getText(node.init);if(node.init.type==="CallExpression"){if(!isSecureTokenGeneration(node.init)){if(safetyChecker.isSafe(node,context)||node.parent&&safetyChecker.isSafe(node.parent,context)){return}context.report({node:node.init,messageId:"predictableRecoveryToken",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}else if(node.init.type==="BinaryExpression"){const weakPatterns=["Date.now()","Math.random()","timestamp","new Date()"];if(weakPatterns.some(pattern=>initText.includes(pattern))){if(safetyChecker.isSafe(node,context)||node.parent&&safetyChecker.isSafe(node.parent,context)){return}context.report({node:node.init,messageId:"insufficientTokenEntropy",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}},FunctionDeclaration(node){if(!node.id){return}const functionName=node.id.name;const functionText=sourceCode.getText(node).toLowerCase();if(isRecoveryRelated(functionName)){if(!hasTokenExpiration(node)){if(safetyChecker.isSafe(node,context)){return}context.report({node:node.id,messageId:"missingTokenExpiration",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}if(!functionText.includes("limit")&&!functionText.includes("rate")){if(safetyChecker.isSafe(node,context)){return}context.report({node:node.id,messageId:"missingRateLimit",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}},CallExpression(node){const callee=node.callee;if(callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&(callee.object.name==="console"||callee.object.name==="logger")&&callee.property.type==="Identifier"&&["log","info","warn","error"].includes(callee.property.name)||callee.type==="Identifier"&&callee.name==="logger"){const args=node.arguments;for(const arg of args){if(arg.type==="Literal"){continue}const argText=sourceCode.getText(arg).toLowerCase();if(isRecoveryRelated(argText)&&(argText.includes("token")||argText.includes("password")||argText.includes("reset")||argText.includes("code"))){if(safetyChecker.isSafe(node,context)){continue}context.report({node:arg,messageId:"recoveryLoggingSensitiveData",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}},IfStatement(node){const test=node.test;const testText=sourceCode.getText(test).toLowerCase();if(isRecoveryRelated(testText)){if(testText.includes("email")&&!testText.includes("verify")&&!testText.includes("token")&&!testText.includes("code")&&!testText.includes("otp")&&!testText.includes("sms")){if(safetyChecker.isSafe(node,context)){return}context.report({node:test,messageId:"weakRecoveryVerification",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}}}});
|