eslint-plugin-lambda-security 1.2.9 → 1.2.11
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 -22
- package/src/index.d.ts +17 -30
- package/src/index.js +1 -24
- package/src/oxlint.d.ts +17 -20
- package/src/oxlint.js +0 -18
- package/src/rules/no-env-logging/index.js +0 -23
- package/src/rules/no-error-swallowing/index.js +1 -27
- package/src/rules/no-exposed-debug-endpoints/index.js +0 -13
- package/src/rules/no-exposed-error-details/index.js +0 -17
- package/src/rules/no-hardcoded-credentials-sdk/index.js +4 -43
- package/src/rules/no-missing-authorization-check/index.js +0 -31
- package/src/rules/no-overly-permissive-iam-policy/index.js +0 -17
- package/src/rules/no-permissive-cors-middy/index.js +0 -16
- package/src/rules/no-permissive-cors-response/index.js +19 -41
- package/src/rules/no-secrets-in-env/index.js +0 -18
- package/src/rules/no-unbounded-batch-processing/index.js +4 -20
- package/src/rules/no-unvalidated-event-body/index.js +19 -86
- package/src/rules/no-user-controlled-requests/index.js +2 -48
- package/src/rules/require-timeout-handling/index.js +0 -20
- package/AGENTS.md +0 -106
- package/CHANGELOG.md +0 -203
- package/src/rules/no-env-logging/index.d.ts +0 -23
- package/src/rules/no-error-swallowing/index.d.ts +0 -26
- package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -14
- package/src/rules/no-exposed-error-details/index.d.ts +0 -24
- package/src/rules/no-hardcoded-credentials-sdk/index.d.ts +0 -24
- package/src/rules/no-missing-authorization-check/index.d.ts +0 -26
- package/src/rules/no-overly-permissive-iam-policy/index.d.ts +0 -24
- package/src/rules/no-permissive-cors-middy/index.d.ts +0 -24
- package/src/rules/no-permissive-cors-response/index.d.ts +0 -26
- package/src/rules/no-secrets-in-env/index.d.ts +0 -26
- package/src/rules/no-unbounded-batch-processing/index.d.ts +0 -26
- package/src/rules/no-unvalidated-event-body/index.d.ts +0 -26
- package/src/rules/no-user-controlled-requests/index.d.ts +0 -24
- package/src/rules/require-timeout-handling/index.d.ts +0 -24
|
@@ -1,13 +1,7 @@
|
|
|
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.noUnvalidatedEventBody = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
// Properties on 'event' that contain untrusted user input
|
|
11
5
|
const DANGEROUS_EVENT_PROPERTIES = [
|
|
12
6
|
'body',
|
|
13
7
|
'queryStringParameters',
|
|
@@ -18,20 +12,17 @@ const DANGEROUS_EVENT_PROPERTIES = [
|
|
|
18
12
|
'rawPath',
|
|
19
13
|
'rawQueryString',
|
|
20
14
|
];
|
|
21
|
-
// Property accesses that indicate validation
|
|
22
15
|
const VALIDATION_INDICATORS = new Set([
|
|
23
|
-
// Middy validators
|
|
24
16
|
'validator',
|
|
25
17
|
'httpJsonBodyParser',
|
|
26
18
|
'@middy/validator',
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'parseAsync', // zod.parseAsync()
|
|
19
|
+
'parse',
|
|
20
|
+
'validate',
|
|
21
|
+
'parseAsync',
|
|
31
22
|
'safeParse',
|
|
32
23
|
'safeParseAsync',
|
|
33
|
-
'assert',
|
|
34
|
-
'is',
|
|
24
|
+
'assert',
|
|
25
|
+
'is',
|
|
35
26
|
]);
|
|
36
27
|
exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
37
28
|
name: 'no-unvalidated-event-body',
|
|
@@ -101,18 +92,11 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
101
92
|
...DANGEROUS_EVENT_PROPERTIES,
|
|
102
93
|
...additionalProperties,
|
|
103
94
|
]);
|
|
104
|
-
// Track which variables have been validated
|
|
105
95
|
const validatedVariables = new Set();
|
|
106
|
-
// Track which event parameters we're monitoring
|
|
107
96
|
const eventParameters = new Set();
|
|
108
|
-
// Track if we're inside a handler that uses validation middleware
|
|
109
97
|
let hasValidationMiddleware = false;
|
|
110
|
-
/**
|
|
111
|
-
* Check if an expression indicates validation has occurred
|
|
112
|
-
*/
|
|
113
98
|
function isValidationCall(node) {
|
|
114
99
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
|
|
115
|
-
// Check for schema.parse(x), schema.validate(x), etc.
|
|
116
100
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
117
101
|
const property = node.callee.property;
|
|
118
102
|
if (property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
@@ -120,7 +104,6 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
120
104
|
return true;
|
|
121
105
|
}
|
|
122
106
|
}
|
|
123
|
-
// Check for direct function calls like validate(x)
|
|
124
107
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
125
108
|
if (VALIDATION_INDICATORS.has(node.callee.name)) {
|
|
126
109
|
return true;
|
|
@@ -129,9 +112,6 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
129
112
|
}
|
|
130
113
|
return false;
|
|
131
114
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Check if this is an event parameter access (e.g., event.body)
|
|
134
|
-
*/
|
|
135
115
|
function isEventPropertyAccess(node) {
|
|
136
116
|
if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
137
117
|
eventParameters.has(node.object.name) &&
|
|
@@ -144,20 +124,18 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
144
124
|
}
|
|
145
125
|
return null;
|
|
146
126
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// allowlist of `['event', 'evt', 'e', 'request', 'req']` was too
|
|
160
|
-
// loose — see benchmarks/AUDIT_PATTERNS.md §2.4.
|
|
127
|
+
function semanticParent(node) {
|
|
128
|
+
let current = node;
|
|
129
|
+
let parent = current.parent;
|
|
130
|
+
while (parent &&
|
|
131
|
+
(parent.type === eslint_devkit_1.AST_NODE_TYPES.LogicalExpression ||
|
|
132
|
+
parent.type === eslint_devkit_1.AST_NODE_TYPES.TSAsExpression ||
|
|
133
|
+
parent.type === eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression)) {
|
|
134
|
+
current = parent;
|
|
135
|
+
parent = current.parent;
|
|
136
|
+
}
|
|
137
|
+
return parent;
|
|
138
|
+
}
|
|
161
139
|
const sourceCode = context.sourceCode;
|
|
162
140
|
const fileImportsLambda = sourceCode.ast.body.some((n) => {
|
|
163
141
|
if (n.type !== eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration)
|
|
@@ -168,13 +146,7 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
168
146
|
src.startsWith('@middy/') ||
|
|
169
147
|
src === '@aws-cdk/aws-lambda');
|
|
170
148
|
});
|
|
171
|
-
// Detect the `export const handler = ...`, `exports.handler = ...`,
|
|
172
|
-
// and `module.exports.handler = ...` Lambda export conventions. A
|
|
173
|
-
// function attached to one of these is a Lambda handler regardless
|
|
174
|
-
// of whether it has the (event, context) signature or just a single
|
|
175
|
-
// `event` parameter — that's the AWS Lambda convention.
|
|
176
149
|
function isExportedAsHandler(node) {
|
|
177
|
-
// function handler() {} / export function handler() {}
|
|
178
150
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration &&
|
|
179
151
|
node.id?.name === 'handler') {
|
|
180
152
|
return true;
|
|
@@ -182,13 +154,11 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
182
154
|
const parent = node.parent;
|
|
183
155
|
if (!parent)
|
|
184
156
|
return false;
|
|
185
|
-
// const handler = (...) / export const handler = (...)
|
|
186
157
|
if (parent.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
187
158
|
parent.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
188
159
|
parent.id.name === 'handler') {
|
|
189
160
|
return true;
|
|
190
161
|
}
|
|
191
|
-
// exports.handler = (...) / module.exports.handler = (...)
|
|
192
162
|
if (parent.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression) {
|
|
193
163
|
const left = parent.left;
|
|
194
164
|
if (left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
@@ -208,26 +178,16 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
208
178
|
const second = params[1];
|
|
209
179
|
const hasContextSibling = second?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
210
180
|
(second.name === 'context' || second.name === 'callback');
|
|
211
|
-
// Discriminator: 2-arg `(req, res)` / `(request, response)` is
|
|
212
|
-
// Express, not Lambda. Reject explicitly so we never misclassify.
|
|
213
181
|
const looksLikeExpress = second?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
214
182
|
((first.name === 'req' && second.name === 'res') ||
|
|
215
183
|
(first.name === 'request' && second.name === 'response'));
|
|
216
184
|
if (looksLikeExpress)
|
|
217
185
|
return false;
|
|
218
186
|
const isEventName = first.name === 'event' || first.name === 'evt';
|
|
219
|
-
// Path 1: classic AWS signature (event, context, ...).
|
|
220
187
|
if (isEventName && hasContextSibling)
|
|
221
188
|
return true;
|
|
222
|
-
// Path 2: file imports Lambda-related modules — single-arg
|
|
223
|
-
// `event`/`evt` is enough.
|
|
224
189
|
if (isEventName && fileImportsLambda)
|
|
225
190
|
return true;
|
|
226
|
-
// Path 3: function is exported under the conventional `handler`
|
|
227
|
-
// name (AWS Lambda runtime invokes by that name). The Lambda
|
|
228
|
-
// export convention narrows the param-name allowlist to common
|
|
229
|
-
// AWS-event identifiers — Express's 2-arg form is already
|
|
230
|
-
// excluded by `looksLikeExpress` above.
|
|
231
191
|
if (isExportedAsHandler(node)) {
|
|
232
192
|
const allowedHandlerParam = ['event', 'evt', 'e', 'request', 'req'];
|
|
233
193
|
if (allowedHandlerParam.includes(first.name))
|
|
@@ -236,27 +196,16 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
236
196
|
return false;
|
|
237
197
|
}
|
|
238
198
|
return {
|
|
239
|
-
// Track arrow function/function parameters that match a Lambda
|
|
240
|
-
// handler signature. Three valid paths (see isLambdaSignature):
|
|
241
|
-
// (a) (event, context, ...) — classic AWS shape
|
|
242
|
-
// (b) single-arg `event` AND file imports aws-lambda / @aws-sdk
|
|
243
|
-
// (c) function exported as `handler` (AWS Lambda export convention)
|
|
244
|
-
// Express handlers never satisfy any of these.
|
|
245
199
|
'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
|
|
246
200
|
if (!isLambdaSignature(node.params, node))
|
|
247
201
|
return;
|
|
248
|
-
// isLambdaSignature already guarantees params[0] is an Identifier
|
|
249
|
-
// (it returns false otherwise), so a type-narrowing cast is safe here.
|
|
250
202
|
const first = node.params[0];
|
|
251
203
|
eventParameters.add(first.name);
|
|
252
204
|
},
|
|
253
|
-
// Check for Middy with validation middleware
|
|
254
205
|
CallExpression(node) {
|
|
255
|
-
// Check for middy().use(validator(...))
|
|
256
206
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
257
207
|
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
258
208
|
node.callee.property.name === 'use') {
|
|
259
|
-
// Check if argument is validator call
|
|
260
209
|
for (const arg of node.arguments) {
|
|
261
210
|
if (arg.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
|
|
262
211
|
arg.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
@@ -265,9 +214,7 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
265
214
|
}
|
|
266
215
|
}
|
|
267
216
|
}
|
|
268
|
-
// Track validation calls that assign to variables
|
|
269
217
|
if (isValidationCall(node)) {
|
|
270
|
-
// If this is part of a variable assignment, mark that variable as validated
|
|
271
218
|
const parent = node.parent;
|
|
272
219
|
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
273
220
|
parent.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
@@ -275,49 +222,35 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
275
222
|
}
|
|
276
223
|
}
|
|
277
224
|
},
|
|
278
|
-
// Check direct access to event properties without validation
|
|
279
225
|
MemberExpression(node) {
|
|
280
|
-
// Skip if validation middleware is present
|
|
281
226
|
if (hasValidationMiddleware)
|
|
282
227
|
return;
|
|
283
228
|
const eventAccess = isEventPropertyAccess(node);
|
|
284
229
|
if (!eventAccess)
|
|
285
230
|
return;
|
|
286
|
-
|
|
287
|
-
const parent = node.parent;
|
|
288
|
-
// Case: const data = schema.parse(event.body) - this is OK
|
|
231
|
+
const parent = semanticParent(node);
|
|
289
232
|
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
|
|
290
233
|
isValidationCall(parent)) {
|
|
291
234
|
return;
|
|
292
235
|
}
|
|
293
|
-
// Case: Direct use without validation - DANGER
|
|
294
|
-
// Check common safe patterns
|
|
295
|
-
// Safe: typeof event.body === 'string'
|
|
296
236
|
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.UnaryExpression &&
|
|
297
237
|
parent.operator === 'typeof') {
|
|
298
238
|
return;
|
|
299
239
|
}
|
|
300
|
-
// Safe: if (event.body) - null check
|
|
301
240
|
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement ||
|
|
302
241
|
parent?.type === eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression) {
|
|
303
242
|
return;
|
|
304
243
|
}
|
|
305
|
-
// Safe: event.body?.prop - optional chain check
|
|
306
|
-
// If this node is event.body, and the parent is a MemberExpression with optional chaining
|
|
307
244
|
if (node.optional) {
|
|
308
245
|
return;
|
|
309
246
|
}
|
|
310
|
-
// Check if parent is using optional chaining on this node
|
|
311
|
-
// e.g., event.body?.name - the event.body node's parent is optional
|
|
312
247
|
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
313
248
|
parent.optional) {
|
|
314
249
|
return;
|
|
315
250
|
}
|
|
316
|
-
// Also check ChainExpression wrapping
|
|
317
251
|
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ChainExpression) {
|
|
318
252
|
return;
|
|
319
253
|
}
|
|
320
|
-
// Safe: Logging event input (detected by property access in console.log argument)
|
|
321
254
|
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
|
|
322
255
|
parent.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
323
256
|
parent.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
@@ -333,7 +266,7 @@ exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
|
|
|
333
266
|
suggest: [
|
|
334
267
|
{
|
|
335
268
|
messageId: 'useValidation',
|
|
336
|
-
fix: () => null,
|
|
269
|
+
fix: () => null,
|
|
337
270
|
},
|
|
338
271
|
],
|
|
339
272
|
});
|
|
@@ -1,35 +1,21 @@
|
|
|
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.noUserControlledRequests = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
// HTTP client function/method names
|
|
11
5
|
const HTTP_CLIENT_METHODS = new Set([
|
|
12
|
-
// Built-in
|
|
13
6
|
'fetch',
|
|
14
|
-
// Node.js http module
|
|
15
7
|
'request',
|
|
16
8
|
'get',
|
|
17
9
|
'post',
|
|
18
10
|
'put',
|
|
19
11
|
'delete',
|
|
20
12
|
'patch',
|
|
21
|
-
// Axios
|
|
22
13
|
'axios',
|
|
23
|
-
// got
|
|
24
14
|
'got',
|
|
25
|
-
// node-fetch
|
|
26
15
|
'nodeFetch',
|
|
27
|
-
// superagent
|
|
28
16
|
'superagent',
|
|
29
17
|
]);
|
|
30
|
-
// HTTP client objects with methods
|
|
31
18
|
const HTTP_CLIENT_OBJECTS = new Set(['http', 'https', 'axios', 'got', 'request']);
|
|
32
|
-
// Event properties containing user input
|
|
33
19
|
const USER_INPUT_PROPERTIES = new Set([
|
|
34
20
|
'body',
|
|
35
21
|
'queryStringParameters',
|
|
@@ -39,7 +25,6 @@ const USER_INPUT_PROPERTIES = new Set([
|
|
|
39
25
|
'rawPath',
|
|
40
26
|
'rawQueryString',
|
|
41
27
|
]);
|
|
42
|
-
// Lambda event parameter names
|
|
43
28
|
const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
|
|
44
29
|
exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
45
30
|
name: 'no-user-controlled-requests',
|
|
@@ -98,28 +83,18 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
98
83
|
if (allowInTests && isTestFile) {
|
|
99
84
|
return {};
|
|
100
85
|
}
|
|
101
|
-
// Track event parameters
|
|
102
86
|
const eventParameters = new Set();
|
|
103
|
-
|
|
104
|
-
const taintedVariables = new Map(); // variable name -> source
|
|
105
|
-
/**
|
|
106
|
-
* Check if an identifier is an event parameter
|
|
107
|
-
*/
|
|
87
|
+
const taintedVariables = new Map();
|
|
108
88
|
function isEventParameter(name) {
|
|
109
89
|
return eventParameters.has(name);
|
|
110
90
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Check if a member expression accesses user input from event
|
|
113
|
-
*/
|
|
114
91
|
function getEventInputSource(node) {
|
|
115
|
-
// event.body, event.queryStringParameters, etc.
|
|
116
92
|
if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
117
93
|
isEventParameter(node.object.name) &&
|
|
118
94
|
node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
119
95
|
USER_INPUT_PROPERTIES.has(node.property.name)) {
|
|
120
96
|
return `event.${node.property.name}`;
|
|
121
97
|
}
|
|
122
|
-
// event.queryStringParameters.url, event.body.targetUrl, etc.
|
|
123
98
|
if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
124
99
|
node.object.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
125
100
|
isEventParameter(node.object.object.name) &&
|
|
@@ -131,23 +106,17 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
131
106
|
}
|
|
132
107
|
return null;
|
|
133
108
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Get taint source from an expression
|
|
136
|
-
*/
|
|
137
109
|
function getTaintSource(node) {
|
|
138
|
-
// Direct event property access
|
|
139
110
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
140
111
|
const source = getEventInputSource(node);
|
|
141
112
|
if (source)
|
|
142
113
|
return source;
|
|
143
114
|
}
|
|
144
|
-
// Variable that was previously tainted
|
|
145
115
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
146
116
|
const source = taintedVariables.get(node.name);
|
|
147
117
|
if (source)
|
|
148
118
|
return source;
|
|
149
119
|
}
|
|
150
|
-
// Template literal with tainted content
|
|
151
120
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
152
121
|
for (const expr of node.expressions) {
|
|
153
122
|
const source = getTaintSource(expr);
|
|
@@ -155,7 +124,6 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
155
124
|
return source;
|
|
156
125
|
}
|
|
157
126
|
}
|
|
158
|
-
// Binary expression (string concatenation)
|
|
159
127
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
|
|
160
128
|
const leftSource = getTaintSource(node.left);
|
|
161
129
|
if (leftSource)
|
|
@@ -166,22 +134,16 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
166
134
|
}
|
|
167
135
|
return null;
|
|
168
136
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Check if this is an HTTP client call
|
|
171
|
-
*/
|
|
172
137
|
function isHttpClientCall(node) {
|
|
173
|
-
// fetch(url), axios(url), got(url)
|
|
174
138
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
175
139
|
HTTP_CLIENT_METHODS.has(node.callee.name)) {
|
|
176
140
|
return true;
|
|
177
141
|
}
|
|
178
|
-
// axios.get(url), http.request(url), etc.
|
|
179
142
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
180
143
|
node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
181
144
|
HTTP_CLIENT_OBJECTS.has(node.callee.object.name)) {
|
|
182
145
|
return true;
|
|
183
146
|
}
|
|
184
|
-
// axios.create().get(url) - chained methods
|
|
185
147
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
186
148
|
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
187
149
|
['get', 'post', 'put', 'delete', 'patch', 'request'].includes(node.callee.property.name)) {
|
|
@@ -189,9 +151,6 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
189
151
|
}
|
|
190
152
|
return false;
|
|
191
153
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Check if URL argument is user-controlled
|
|
194
|
-
*/
|
|
195
154
|
function checkUrlArgument(node) {
|
|
196
155
|
if (node.arguments.length === 0)
|
|
197
156
|
return null;
|
|
@@ -200,7 +159,6 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
200
159
|
if (source) {
|
|
201
160
|
return { tainted: true, source };
|
|
202
161
|
}
|
|
203
|
-
// Check object config { url: taintedVar }
|
|
204
162
|
if (urlArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
205
163
|
for (const prop of urlArg.properties) {
|
|
206
164
|
if (prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
|
|
@@ -216,7 +174,6 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
216
174
|
return null;
|
|
217
175
|
}
|
|
218
176
|
return {
|
|
219
|
-
// Track event parameters in handlers
|
|
220
177
|
'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
|
|
221
178
|
for (const param of node.params) {
|
|
222
179
|
if (param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
@@ -226,7 +183,6 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
226
183
|
}
|
|
227
184
|
}
|
|
228
185
|
},
|
|
229
|
-
// Track variable assignments that contain user input
|
|
230
186
|
VariableDeclarator(node) {
|
|
231
187
|
if (node.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && node.init) {
|
|
232
188
|
const source = getTaintSource(node.init);
|
|
@@ -235,7 +191,6 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
235
191
|
}
|
|
236
192
|
}
|
|
237
193
|
},
|
|
238
|
-
// Track reassignments
|
|
239
194
|
AssignmentExpression(node) {
|
|
240
195
|
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
241
196
|
const source = getTaintSource(node.right);
|
|
@@ -244,7 +199,6 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
244
199
|
}
|
|
245
200
|
}
|
|
246
201
|
},
|
|
247
|
-
// Check HTTP client calls for tainted URLs
|
|
248
202
|
CallExpression(node) {
|
|
249
203
|
if (!isHttpClientCall(node))
|
|
250
204
|
return;
|
|
@@ -259,7 +213,7 @@ exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
|
259
213
|
suggest: [
|
|
260
214
|
{
|
|
261
215
|
messageId: 'useAllowlist',
|
|
262
|
-
fix: () => null,
|
|
216
|
+
fix: () => null,
|
|
263
217
|
},
|
|
264
218
|
],
|
|
265
219
|
});
|
|
@@ -1,31 +1,19 @@
|
|
|
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.requireTimeoutHandling = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
// Lambda context parameter names
|
|
11
5
|
const CONTEXT_PARAM_NAMES = new Set(['context', 'ctx', 'lambdaContext']);
|
|
12
|
-
// Event parameter names (to identify Lambda handlers)
|
|
13
6
|
const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
|
|
14
|
-
// External call patterns that could timeout
|
|
15
7
|
const EXTERNAL_CALL_PATTERNS = new Set([
|
|
16
|
-
// HTTP clients
|
|
17
8
|
'fetch',
|
|
18
9
|
'axios',
|
|
19
10
|
'got',
|
|
20
11
|
'request',
|
|
21
|
-
// AWS SDK
|
|
22
12
|
'send',
|
|
23
13
|
'invoke',
|
|
24
|
-
// Database
|
|
25
14
|
'query',
|
|
26
15
|
'execute',
|
|
27
16
|
'connect',
|
|
28
|
-
// Other
|
|
29
17
|
'promise',
|
|
30
18
|
'wait',
|
|
31
19
|
]);
|
|
@@ -81,13 +69,11 @@ exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
|
|
|
81
69
|
if (allowInTests && isTestFile) {
|
|
82
70
|
return {};
|
|
83
71
|
}
|
|
84
|
-
// Track handler functions
|
|
85
72
|
let currentHandlerNode = null;
|
|
86
73
|
let hasTimeoutCheck = false;
|
|
87
74
|
let hasExternalCalls = false;
|
|
88
75
|
let hasContextParam = false;
|
|
89
76
|
function enterFunction(node) {
|
|
90
|
-
// Check if this looks like a Lambda handler (event, context)
|
|
91
77
|
const params = node.params;
|
|
92
78
|
const hasEvent = params.some((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
93
79
|
EVENT_PARAM_NAMES.has(p.name));
|
|
@@ -103,7 +89,6 @@ exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
|
|
|
103
89
|
function exitFunction(node) {
|
|
104
90
|
if (currentHandlerNode !== node)
|
|
105
91
|
return;
|
|
106
|
-
// Report if handler has external calls but no timeout handling and has context param
|
|
107
92
|
if (hasExternalCalls && !hasTimeoutCheck && hasContextParam) {
|
|
108
93
|
context.report({
|
|
109
94
|
node,
|
|
@@ -131,7 +116,6 @@ exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
|
|
|
131
116
|
'FunctionDeclaration:exit'(node) {
|
|
132
117
|
exitFunction(node);
|
|
133
118
|
},
|
|
134
|
-
// Detect getRemainingTimeInMillis() call
|
|
135
119
|
MemberExpression(node) {
|
|
136
120
|
if (!currentHandlerNode)
|
|
137
121
|
return;
|
|
@@ -140,7 +124,6 @@ exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
|
|
|
140
124
|
hasTimeoutCheck = true;
|
|
141
125
|
}
|
|
142
126
|
},
|
|
143
|
-
// Detect AbortController usage
|
|
144
127
|
NewExpression(node) {
|
|
145
128
|
if (!currentHandlerNode)
|
|
146
129
|
return;
|
|
@@ -149,11 +132,9 @@ exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
|
|
|
149
132
|
hasTimeoutCheck = true;
|
|
150
133
|
}
|
|
151
134
|
},
|
|
152
|
-
// Detect external calls
|
|
153
135
|
CallExpression(node) {
|
|
154
136
|
if (!currentHandlerNode)
|
|
155
137
|
return;
|
|
156
|
-
// Check for external call patterns
|
|
157
138
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
158
139
|
if (EXTERNAL_CALL_PATTERNS.has(node.callee.name)) {
|
|
159
140
|
hasExternalCalls = true;
|
|
@@ -166,7 +147,6 @@ exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
|
|
|
166
147
|
hasExternalCalls = true;
|
|
167
148
|
}
|
|
168
149
|
}
|
|
169
|
-
// Check for Promise.race (timeout pattern)
|
|
170
150
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
171
151
|
node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
172
152
|
node.callee.object.name === 'Promise' &&
|
package/AGENTS.md
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# AGENTS.md
|
|
2
|
-
|
|
3
|
-
> Context for AI coding agents working on eslint-plugin-lambda-security
|
|
4
|
-
|
|
5
|
-
## Setup Commands
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Install dependencies (from monorepo root)
|
|
9
|
-
npm install
|
|
10
|
-
|
|
11
|
-
# Build this package
|
|
12
|
-
nx build eslint-plugin-lambda-security
|
|
13
|
-
|
|
14
|
-
# Run tests
|
|
15
|
-
nx test eslint-plugin-lambda-security
|
|
16
|
-
|
|
17
|
-
# Run tests with coverage
|
|
18
|
-
nx test eslint-plugin-lambda-security --coverage
|
|
19
|
-
|
|
20
|
-
# Lint this package
|
|
21
|
-
nx lint eslint-plugin-lambda-security
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Code Style
|
|
25
|
-
|
|
26
|
-
- TypeScript strict mode with `@interlace/eslint-devkit` types
|
|
27
|
-
- Use `AST_NODE_TYPES` constants, never string literals for node types
|
|
28
|
-
- Use `formatLLMMessage()` for all rule error messages
|
|
29
|
-
- Include CWE, CVSS, OWASP Serverless Top 10 in every security message
|
|
30
|
-
- Use `c8 ignore` comments with documented reasons for untestable code
|
|
31
|
-
- Single-pass AST traversal patterns (O(n) complexity)
|
|
32
|
-
|
|
33
|
-
## Testing Instructions
|
|
34
|
-
|
|
35
|
-
- Tests use `@typescript-eslint/rule-tester` with Vitest
|
|
36
|
-
- Each rule has `index.ts` (implementation) and `*.test.ts` (tests) in same directory
|
|
37
|
-
- Run specific rule test: `nx test eslint-plugin-lambda-security --testPathPattern="no-hardcoded-credentials"`
|
|
38
|
-
- Coverage target: ≥90% lines, ≥95% functions
|
|
39
|
-
- All tests must pass before committing
|
|
40
|
-
|
|
41
|
-
## Project Structure
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
src/
|
|
45
|
-
├── index.ts # Plugin entry, exports rules and 2 configs
|
|
46
|
-
├── types/index.ts # Exported rule option types
|
|
47
|
-
└── rules/ # 5 rule directories
|
|
48
|
-
└── [rule-name]/
|
|
49
|
-
├── index.ts # Rule implementation
|
|
50
|
-
└── *.test.ts # Rule tests
|
|
51
|
-
docs/rules/ # Markdown documentation per rule
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Plugin Purpose
|
|
55
|
-
|
|
56
|
-
Security-focused ESLint plugin with **5 rules** for AWS Lambda, Middy, and serverless applications. Covers hardcoded credentials, secrets exposure, environment logging, and CORS misconfigurations.
|
|
57
|
-
|
|
58
|
-
## Rule Categories
|
|
59
|
-
|
|
60
|
-
| Category | Rules | CWEs |
|
|
61
|
-
| --------------------- | --------------------------------------------------------------------- | -------- |
|
|
62
|
-
| Credentials & Secrets | `no-hardcoded-credentials-sdk`, `no-secrets-in-env`, `no-env-logging` | 532, 798 |
|
|
63
|
-
| CORS | `no-permissive-cors-response`, `no-permissive-cors-middy` | 942 |
|
|
64
|
-
|
|
65
|
-
## AWS SDK Clients Detected
|
|
66
|
-
|
|
67
|
-
S3Client, DynamoDBClient, LambdaClient, STSClient, SecretsManagerClient, SQSClient, SNSClient, EC2Client, ECSClient, CloudWatchClient, CloudWatchLogsClient, APIGatewayClient, CognitoIdentityClient, CognitoIdentityProviderClient, EventBridgeClient, StepFunctionsClient, RDSClient, ElastiCacheClient
|
|
68
|
-
|
|
69
|
-
## AWS Access Key Patterns
|
|
70
|
-
|
|
71
|
-
| Pattern | Type |
|
|
72
|
-
| ------- | ------------------------ |
|
|
73
|
-
| `AKIA*` | IAM user access key |
|
|
74
|
-
| `ASIA*` | STS temporary access key |
|
|
75
|
-
| `AIDA*` | IAM user ID |
|
|
76
|
-
|
|
77
|
-
## Common Fix Patterns
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
// Hardcoded credentials
|
|
81
|
-
// BAD: new S3Client({ credentials: { accessKeyId: 'AKIA...', secretAccessKey: '...' } })
|
|
82
|
-
// GOOD: new S3Client({ region: 'us-east-1' }) // Uses Lambda execution role
|
|
83
|
-
// GOOD: new S3Client({ credentials: fromNodeProviderChain() })
|
|
84
|
-
|
|
85
|
-
// Secrets in env
|
|
86
|
-
// BAD: process.env.DB_PASSWORD = 'my-secret'
|
|
87
|
-
// GOOD: const secret = await client.send(new GetSecretValueCommand({ SecretId: 'my-secret' }))
|
|
88
|
-
|
|
89
|
-
// Logging env
|
|
90
|
-
// BAD: console.log(process.env)
|
|
91
|
-
// GOOD: console.log('Region:', process.env.AWS_REGION)
|
|
92
|
-
|
|
93
|
-
// Lambda CORS
|
|
94
|
-
// BAD: return { headers: { 'Access-Control-Allow-Origin': '*' }, ... }
|
|
95
|
-
// GOOD: return { headers: { 'Access-Control-Allow-Origin': 'https://your-app.com' }, ... }
|
|
96
|
-
|
|
97
|
-
// Middy CORS
|
|
98
|
-
// BAD: middy(handler).use(httpCors())
|
|
99
|
-
// GOOD: middy(handler).use(httpCors({ origins: ['https://your-app.com'] }))
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## Security Considerations
|
|
103
|
-
|
|
104
|
-
- All rules map to OWASP Serverless Top 10: SAS-2, SAS-3, SAS-4
|
|
105
|
-
- CWE coverage: 532, 798, 942
|
|
106
|
-
- Real AWS key pattern detection (not just string length checks)
|