eslint-plugin-lambda-security 1.3.2 → 1.3.4

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.
@@ -1,168 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noUnboundedBatchProcessing = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const BATCH_SOURCE_PROPERTIES = new Set([
6
- 'Records',
7
- 'records',
8
- 'items',
9
- 'messages',
10
- ]);
11
- const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
12
- exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
13
- name: 'no-unbounded-batch-processing',
14
- meta: {
15
- type: 'problem',
16
- docs: {
17
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unbounded-batch-processing.md',
18
- description: 'Detects processing batch records without size validation',
19
- cwe: 'CWE-770',
20
- cvss: 5.5,
21
- },
22
- hasSuggestions: true,
23
- messages: {
24
- unboundedBatch: (0, eslint_devkit_1.formatLLMMessage)({
25
- icon: eslint_devkit_1.MessageIcons.WARNING,
26
- issueName: 'Unbounded Batch Processing',
27
- cwe: 'CWE-770',
28
- cvss: 5.5,
29
- description: 'Processing {{source}} without size check. Large batches may cause timeout or memory exhaustion.',
30
- severity: 'MEDIUM',
31
- fix: 'Validate batch size before processing: if (event.Records.length > MAX_BATCH) throw new Error("Batch too large")',
32
- documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html',
33
- }),
34
- addBatchLimit: (0, eslint_devkit_1.formatLLMMessage)({
35
- icon: eslint_devkit_1.MessageIcons.INFO,
36
- issueName: 'Add Batch Size Limit',
37
- description: 'Add a maximum batch size check before processing',
38
- severity: 'LOW',
39
- fix: 'const MAX_BATCH_SIZE = 10; const records = event.Records.slice(0, MAX_BATCH_SIZE);',
40
- documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html',
41
- }),
42
- },
43
- schema: [
44
- {
45
- type: 'object',
46
- properties: {
47
- allowInTests: {
48
- type: 'boolean',
49
- default: true,
50
- },
51
- maxBatchSize: {
52
- type: 'number',
53
- default: 100, description: 'Batch size above which processing must be explicitly bounded'
54
- },
55
- },
56
- additionalProperties: false,
57
- },
58
- ],
59
- },
60
- defaultOptions: [{ allowInTests: true, maxBatchSize: 100 }],
61
- create(context, [options = {}]) {
62
- const { allowInTests = true } = options;
63
- const filename = context.filename;
64
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
65
- if (allowInTests && isTestFile) {
66
- return {};
67
- }
68
- let currentHandlerNode = null;
69
- let hasBatchSizeCheck = false;
70
- const batchAccessNodes = [];
71
- const eventParamName = [];
72
- function enterFunction(node) {
73
- const hasEvent = node.params.some((p) => {
74
- if (p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
75
- EVENT_PARAM_NAMES.has(p.name)) {
76
- eventParamName.push(p.name);
77
- return true;
78
- }
79
- return false;
80
- });
81
- if (hasEvent) {
82
- currentHandlerNode = node;
83
- hasBatchSizeCheck = false;
84
- batchAccessNodes.length = 0;
85
- }
86
- }
87
- function exitFunction(node) {
88
- if (currentHandlerNode !== node)
89
- return;
90
- if (!hasBatchSizeCheck) {
91
- for (const { node: batchNode, source } of batchAccessNodes) {
92
- context.report({
93
- node: batchNode,
94
- messageId: 'unboundedBatch',
95
- data: { source },
96
- suggest: [
97
- {
98
- messageId: 'addBatchLimit',
99
- fix: () => null,
100
- },
101
- ],
102
- });
103
- }
104
- }
105
- currentHandlerNode = null;
106
- eventParamName.length = 0;
107
- }
108
- return {
109
- 'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
110
- enterFunction(node);
111
- },
112
- 'ArrowFunctionExpression:exit'(node) {
113
- exitFunction(node);
114
- },
115
- 'FunctionExpression:exit'(node) {
116
- exitFunction(node);
117
- },
118
- 'FunctionDeclaration:exit'(node) {
119
- exitFunction(node);
120
- },
121
- MemberExpression(node) {
122
- if (!currentHandlerNode)
123
- return;
124
- if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
125
- eventParamName.includes(node.object.name) &&
126
- node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
127
- BATCH_SOURCE_PROPERTIES.has(node.property.name)) {
128
- batchAccessNodes.push({
129
- node,
130
- source: `${node.object.name}.${node.property.name}`,
131
- });
132
- }
133
- if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
134
- node.property.name === 'length') {
135
- if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
136
- node.object.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
137
- BATCH_SOURCE_PROPERTIES.has(node.object.property.name)) {
138
- hasBatchSizeCheck = true;
139
- }
140
- }
141
- },
142
- CallExpression(node) {
143
- if (!currentHandlerNode)
144
- return;
145
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
146
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
147
- ['slice', 'splice', 'take', 'chunk'].includes(node.callee.property.name)) {
148
- hasBatchSizeCheck = true;
149
- }
150
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
151
- ['slice', 'splice', 'take', 'chunk'].includes(node.callee.name)) {
152
- hasBatchSizeCheck = true;
153
- }
154
- },
155
- BinaryExpression(node) {
156
- if (!currentHandlerNode)
157
- return;
158
- if (['<', '<=', '>', '>='].includes(node.operator)) {
159
- const sourceCode = context.sourceCode;
160
- const text = sourceCode.getText(node);
161
- if (/\.length|Records|records/.test(text)) {
162
- hasBatchSizeCheck = true;
163
- }
164
- }
165
- },
166
- };
167
- },
168
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnboundedBatchProcessing=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const BATCH_SOURCE_PROPERTIES=new Set(["Records","records","items","messages"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noUnboundedBatchProcessing=(0,eslint_devkit_1.createRule)({name:"no-unbounded-batch-processing",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unbounded-batch-processing.md",description:"Detects processing batch records without size validation",cwe:"CWE-770",cvss:5.5},hasSuggestions:true,messages:{unboundedBatch:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Unbounded Batch Processing",cwe:"CWE-770",cvss:5.5,description:"Processing {{source}} without size check. Large batches may cause timeout or memory exhaustion.",severity:"MEDIUM",fix:'Validate batch size before processing: if (event.Records.length > MAX_BATCH) throw new Error("Batch too large")',documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"}),addBatchLimit:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Batch Size Limit",description:"Add a maximum batch size check before processing",severity:"LOW",fix:"const MAX_BATCH_SIZE = 10; const records = event.Records.slice(0, MAX_BATCH_SIZE);",documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},maxBatchSize:{type:"number",default:100,description:"Batch size above which processing must be explicitly bounded"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,maxBatchSize:100}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}let currentHandlerNode=null;let hasBatchSizeCheck=false;const batchAccessNodes=[];const eventParamName=[];function enterFunction(node){const hasEvent=node.params.some(p=>{if(p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&EVENT_PARAM_NAMES.has(p.name)){eventParamName.push(p.name);return true}return false});if(hasEvent){currentHandlerNode=node;hasBatchSizeCheck=false;batchAccessNodes.length=0}}function exitFunction(node){if(currentHandlerNode!==node)return;if(!hasBatchSizeCheck){for(const{node:batchNode,source}of batchAccessNodes){context.report({node:batchNode,messageId:"unboundedBatch",data:{source},suggest:[{messageId:"addBatchLimit",fix:()=>null}]})}}currentHandlerNode=null;eventParamName.length=0}return{"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentHandlerNode)return;if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamName.includes(node.object.name)&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&BATCH_SOURCE_PROPERTIES.has(node.property.name)){batchAccessNodes.push({node,source:`${node.object.name}.${node.property.name}`})}if(node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.property.name==="length"){if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&BATCH_SOURCE_PROPERTIES.has(node.object.property.name)){hasBatchSizeCheck=true}}},CallExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["slice","splice","take","chunk"].includes(node.callee.property.name)){hasBatchSizeCheck=true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["slice","splice","take","chunk"].includes(node.callee.name)){hasBatchSizeCheck=true}},BinaryExpression(node){if(!currentHandlerNode)return;if(["<","<=",">",">="].includes(node.operator)){const sourceCode=context.sourceCode;const text=sourceCode.getText(node);if(/\.length|Records|records/.test(text)){hasBatchSizeCheck=true}}}}}});
@@ -1,276 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noUnvalidatedEventBody = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const DANGEROUS_EVENT_PROPERTIES = [
6
- 'body',
7
- 'queryStringParameters',
8
- 'pathParameters',
9
- 'multiValueQueryStringParameters',
10
- 'headers',
11
- 'multiValueHeaders',
12
- 'rawPath',
13
- 'rawQueryString',
14
- ];
15
- const VALIDATION_INDICATORS = new Set([
16
- 'validator',
17
- 'httpJsonBodyParser',
18
- '@middy/validator',
19
- 'parse',
20
- 'validate',
21
- 'parseAsync',
22
- 'safeParse',
23
- 'safeParseAsync',
24
- 'assert',
25
- 'is',
26
- ]);
27
- exports.noUnvalidatedEventBody = (0, eslint_devkit_1.createRule)({
28
- name: 'no-unvalidated-event-body',
29
- meta: {
30
- type: 'problem',
31
- docs: {
32
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unvalidated-event-body.md',
33
- description: 'Detects Lambda handlers using event body/params without validation',
34
- cwe: 'CWE-20',
35
- cvss: 8,
36
- },
37
- hasSuggestions: true,
38
- messages: {
39
- unvalidatedInput: (0, eslint_devkit_1.formatLLMMessage)({
40
- icon: eslint_devkit_1.MessageIcons.SECURITY,
41
- issueName: 'Unvalidated Event Input',
42
- cwe: 'CWE-20',
43
- cvss: 8.0,
44
- description: 'Lambda handler uses {{property}} without validation. This can lead to injection attacks.',
45
- severity: 'HIGH',
46
- fix: 'Validate event input using Middy validator, Zod, or Joi before use',
47
- documentationLink: 'https://owasp.org/www-project-serverless-top-10/',
48
- }),
49
- useValidation: (0, eslint_devkit_1.formatLLMMessage)({
50
- icon: eslint_devkit_1.MessageIcons.INFO,
51
- issueName: 'Add Input Validation',
52
- description: 'Add input validation using Middy validator middleware or a schema library',
53
- severity: 'LOW',
54
- fix: "import { validator } from '@middy/validator'; middy(handler).use(validator({ inputSchema }))",
55
- documentationLink: 'https://middy.js.org/docs/middlewares/validator',
56
- }),
57
- },
58
- schema: [
59
- {
60
- type: 'object',
61
- properties: {
62
- allowInTests: {
63
- type: 'boolean',
64
- default: true,
65
- description: 'Allow unvalidated input in test files',
66
- },
67
- additionalProperties: {
68
- type: 'array',
69
- items: { type: 'string' },
70
- default: [],
71
- description: 'Additional event properties to check',
72
- },
73
- },
74
- additionalProperties: false,
75
- },
76
- ],
77
- },
78
- defaultOptions: [
79
- {
80
- allowInTests: true,
81
- additionalProperties: [],
82
- },
83
- ],
84
- create(context, [options = {}]) {
85
- const { allowInTests = true, additionalProperties = [] } = options;
86
- const filename = context.filename;
87
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
88
- if (allowInTests && isTestFile) {
89
- return {};
90
- }
91
- const dangerousProperties = new Set([
92
- ...DANGEROUS_EVENT_PROPERTIES,
93
- ...additionalProperties,
94
- ]);
95
- const validatedVariables = new Set();
96
- const eventParameters = new Set();
97
- let hasValidationMiddleware = false;
98
- function isValidationCall(node) {
99
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
100
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
101
- const property = node.callee.property;
102
- if (property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
103
- VALIDATION_INDICATORS.has(property.name)) {
104
- return true;
105
- }
106
- }
107
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
108
- if (VALIDATION_INDICATORS.has(node.callee.name)) {
109
- return true;
110
- }
111
- }
112
- }
113
- return false;
114
- }
115
- function isEventPropertyAccess(node) {
116
- if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
117
- eventParameters.has(node.object.name) &&
118
- node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
119
- dangerousProperties.has(node.property.name)) {
120
- return {
121
- eventName: node.object.name,
122
- property: node.property.name,
123
- };
124
- }
125
- return null;
126
- }
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
- }
139
- const sourceCode = context.sourceCode;
140
- const fileImportsLambda = sourceCode.ast.body.some((n) => {
141
- if (n.type !== eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration)
142
- return false;
143
- const src = String(n.source.value);
144
- return (src === 'aws-lambda' ||
145
- src.startsWith('@aws-sdk/') ||
146
- src.startsWith('@middy/') ||
147
- src === '@aws-cdk/aws-lambda');
148
- });
149
- function isExportedAsHandler(node) {
150
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration &&
151
- node.id?.name === 'handler') {
152
- return true;
153
- }
154
- const parent = node.parent;
155
- if (!parent)
156
- return false;
157
- if (parent.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator &&
158
- parent.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
159
- parent.id.name === 'handler') {
160
- return true;
161
- }
162
- if (parent.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression) {
163
- const left = parent.left;
164
- if (left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
165
- left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
166
- left.property.name === 'handler') {
167
- return true;
168
- }
169
- }
170
- return false;
171
- }
172
- function isLambdaSignature(params, node) {
173
- if (params.length < 1)
174
- return false;
175
- const first = params[0];
176
- if (first.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
177
- return false;
178
- const second = params[1];
179
- const hasContextSibling = second?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
180
- (second.name === 'context' || second.name === 'callback');
181
- const looksLikeExpress = second?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
182
- ((first.name === 'req' && second.name === 'res') ||
183
- (first.name === 'request' && second.name === 'response'));
184
- if (looksLikeExpress)
185
- return false;
186
- const isEventName = first.name === 'event' || first.name === 'evt';
187
- if (isEventName && hasContextSibling)
188
- return true;
189
- if (isEventName && fileImportsLambda)
190
- return true;
191
- if (isExportedAsHandler(node)) {
192
- const allowedHandlerParam = ['event', 'evt', 'e', 'request', 'req'];
193
- if (allowedHandlerParam.includes(first.name))
194
- return true;
195
- }
196
- return false;
197
- }
198
- return {
199
- 'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
200
- if (!isLambdaSignature(node.params, node))
201
- return;
202
- const first = node.params[0];
203
- eventParameters.add(first.name);
204
- },
205
- CallExpression(node) {
206
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
207
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
208
- node.callee.property.name === 'use') {
209
- for (const arg of node.arguments) {
210
- if (arg.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
211
- arg.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
212
- ['validator', 'httpJsonBodyParser'].includes(arg.callee.name)) {
213
- hasValidationMiddleware = true;
214
- }
215
- }
216
- }
217
- if (isValidationCall(node)) {
218
- const parent = node.parent;
219
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator &&
220
- parent.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
221
- validatedVariables.add(parent.id.name);
222
- }
223
- }
224
- },
225
- MemberExpression(node) {
226
- if (hasValidationMiddleware)
227
- return;
228
- const eventAccess = isEventPropertyAccess(node);
229
- if (!eventAccess)
230
- return;
231
- const parent = semanticParent(node);
232
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
233
- isValidationCall(parent)) {
234
- return;
235
- }
236
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.UnaryExpression &&
237
- parent.operator === 'typeof') {
238
- return;
239
- }
240
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement ||
241
- parent?.type === eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression) {
242
- return;
243
- }
244
- if (node.optional) {
245
- return;
246
- }
247
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
248
- parent.optional) {
249
- return;
250
- }
251
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ChainExpression) {
252
- return;
253
- }
254
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
255
- parent.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
256
- parent.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
257
- parent.callee.object.name === 'console') {
258
- return;
259
- }
260
- context.report({
261
- node,
262
- messageId: 'unvalidatedInput',
263
- data: {
264
- property: `event.${eventAccess.property}`,
265
- },
266
- suggest: [
267
- {
268
- messageId: 'useValidation',
269
- fix: () => null,
270
- },
271
- ],
272
- });
273
- },
274
- };
275
- },
276
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnvalidatedEventBody=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_EVENT_PROPERTIES=["body","queryStringParameters","pathParameters","multiValueQueryStringParameters","headers","multiValueHeaders","rawPath","rawQueryString"];const VALIDATION_INDICATORS=new Set(["validator","httpJsonBodyParser","@middy/validator","parse","validate","parseAsync","safeParse","safeParseAsync","assert","is"]);exports.noUnvalidatedEventBody=(0,eslint_devkit_1.createRule)({name:"no-unvalidated-event-body",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unvalidated-event-body.md",description:"Detects Lambda handlers using event body/params without validation",cwe:"CWE-20",cvss:8},hasSuggestions:true,messages:{unvalidatedInput:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unvalidated Event Input",cwe:"CWE-20",cvss:8,description:"Lambda handler uses {{property}} without validation. This can lead to injection attacks.",severity:"HIGH",fix:"Validate event input using Middy validator, Zod, or Joi before use",documentationLink:"https://owasp.org/www-project-serverless-top-10/"}),useValidation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Input Validation",description:"Add input validation using Middy validator middleware or a schema library",severity:"LOW",fix:"import { validator } from '@middy/validator'; middy(handler).use(validator({ inputSchema }))",documentationLink:"https://middy.js.org/docs/middlewares/validator"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow unvalidated input in test files"},additionalProperties:{type:"array",items:{type:"string"},default:[],description:"Additional event properties to check"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,additionalProperties:[]}],create(context,[options={}]){const{allowInTests=true,additionalProperties=[]}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}const dangerousProperties=new Set([...DANGEROUS_EVENT_PROPERTIES,...additionalProperties]);const validatedVariables=new Set;const eventParameters=new Set;let hasValidationMiddleware=false;function isValidationCall(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const property=node.callee.property;if(property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&VALIDATION_INDICATORS.has(property.name)){return true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(VALIDATION_INDICATORS.has(node.callee.name)){return true}}}return false}function isEventPropertyAccess(node){if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParameters.has(node.object.name)&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&dangerousProperties.has(node.property.name)){return{eventName:node.object.name,property:node.property.name}}return null}function semanticParent(node){let current=node;let parent=current.parent;while(parent&&(parent.type===eslint_devkit_1.AST_NODE_TYPES.LogicalExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.TSAsExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression)){current=parent;parent=current.parent}return parent}const sourceCode=context.sourceCode;const fileImportsLambda=sourceCode.ast.body.some(n=>{if(n.type!==eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration)return false;const src=String(n.source.value);return src==="aws-lambda"||src.startsWith("@aws-sdk/")||src.startsWith("@middy/")||src==="@aws-cdk/aws-lambda"});function isExportedAsHandler(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration&&node.id?.name==="handler"){return true}const parent=node.parent;if(!parent)return false;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.id.name==="handler"){return true}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression){const left=parent.left;if(left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&left.property.name==="handler"){return true}}return false}function isLambdaSignature(params,node){if(params.length<1)return false;const first=params[0];if(first.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const second=params[1];const hasContextSibling=second?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(second.name==="context"||second.name==="callback");const looksLikeExpress=second?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(first.name==="req"&&second.name==="res"||first.name==="request"&&second.name==="response");if(looksLikeExpress)return false;const isEventName=first.name==="event"||first.name==="evt";if(isEventName&&hasContextSibling)return true;if(isEventName&&fileImportsLambda)return true;if(isExportedAsHandler(node)){const allowedHandlerParam=["event","evt","e","request","req"];if(allowedHandlerParam.includes(first.name))return true}return false}return{"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){if(!isLambdaSignature(node.params,node))return;const first=node.params[0];eventParameters.add(first.name)},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="use"){for(const arg of node.arguments){if(arg.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&arg.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["validator","httpJsonBodyParser"].includes(arg.callee.name)){hasValidationMiddleware=true}}}if(isValidationCall(node)){const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){validatedVariables.add(parent.id.name)}}},MemberExpression(node){if(hasValidationMiddleware)return;const eventAccess=isEventPropertyAccess(node);if(!eventAccess)return;const parent=semanticParent(node);if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&isValidationCall(parent)){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.UnaryExpression&&parent.operator==="typeof"){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.IfStatement||parent?.type===eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression){return}if(node.optional){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.optional){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.ChainExpression){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.callee.object.name==="console"){return}context.report({node,messageId:"unvalidatedInput",data:{property:`event.${eventAccess.property}`},suggest:[{messageId:"useValidation",fix:()=>null}]})}}}});