eslint-plugin-lambda-security 1.3.2 → 1.3.3

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,160 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireTimeoutHandling = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const CONTEXT_PARAM_NAMES = new Set(['context', 'ctx', 'lambdaContext']);
6
- const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
7
- const EXTERNAL_CALL_PATTERNS = new Set([
8
- 'fetch',
9
- 'axios',
10
- 'got',
11
- 'request',
12
- 'send',
13
- 'invoke',
14
- 'query',
15
- 'execute',
16
- 'connect',
17
- 'promise',
18
- 'wait',
19
- ]);
20
- exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
21
- name: 'require-timeout-handling',
22
- meta: {
23
- type: 'suggestion',
24
- docs: {
25
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/require-timeout-handling.md',
26
- description: 'Warns when Lambda handlers with external calls lack timeout handling',
27
- cwe: 'CWE-400',
28
- cvss: 6,
29
- },
30
- hasSuggestions: true,
31
- messages: {
32
- missingTimeoutHandling: (0, eslint_devkit_1.formatLLMMessage)({
33
- icon: eslint_devkit_1.MessageIcons.WARNING,
34
- issueName: 'Missing Timeout Handling',
35
- cwe: 'CWE-400',
36
- cvss: 6.0,
37
- description: 'Lambda handler makes external calls without timeout handling. Function may timeout without cleanup.',
38
- severity: 'MEDIUM',
39
- fix: 'Use context.getRemainingTimeInMillis() to check available time before external calls, or use AbortController',
40
- documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html',
41
- }),
42
- addTimeoutCheck: (0, eslint_devkit_1.formatLLMMessage)({
43
- icon: eslint_devkit_1.MessageIcons.INFO,
44
- issueName: 'Add Timeout Check',
45
- description: 'Check remaining time before making external calls to prevent timeouts',
46
- severity: 'LOW',
47
- fix: "const remainingTime = context.getRemainingTimeInMillis(); if (remainingTime < 5000) { return { statusCode: 503 } }",
48
- documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html',
49
- }),
50
- },
51
- schema: [
52
- {
53
- type: 'object',
54
- properties: {
55
- allowInTests: {
56
- type: 'boolean',
57
- default: true,
58
- },
59
- },
60
- additionalProperties: false,
61
- },
62
- ],
63
- },
64
- defaultOptions: [{ allowInTests: true }],
65
- create(context, [options = {}]) {
66
- const { allowInTests = true } = options;
67
- const filename = context.filename;
68
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
69
- if (allowInTests && isTestFile) {
70
- return {};
71
- }
72
- let currentHandlerNode = null;
73
- let hasTimeoutCheck = false;
74
- let hasExternalCalls = false;
75
- let hasContextParam = false;
76
- function enterFunction(node) {
77
- const params = node.params;
78
- const hasEvent = params.some((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
79
- EVENT_PARAM_NAMES.has(p.name));
80
- const hasContext = params.some((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
81
- CONTEXT_PARAM_NAMES.has(p.name));
82
- if (hasEvent) {
83
- currentHandlerNode = node;
84
- hasTimeoutCheck = false;
85
- hasExternalCalls = false;
86
- hasContextParam = hasContext;
87
- }
88
- }
89
- function exitFunction(node) {
90
- if (currentHandlerNode !== node)
91
- return;
92
- if (hasExternalCalls && !hasTimeoutCheck && hasContextParam) {
93
- context.report({
94
- node,
95
- messageId: 'missingTimeoutHandling',
96
- suggest: [
97
- {
98
- messageId: 'addTimeoutCheck',
99
- fix: () => null,
100
- },
101
- ],
102
- });
103
- }
104
- currentHandlerNode = null;
105
- }
106
- return {
107
- 'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
108
- enterFunction(node);
109
- },
110
- 'ArrowFunctionExpression:exit'(node) {
111
- exitFunction(node);
112
- },
113
- 'FunctionExpression:exit'(node) {
114
- exitFunction(node);
115
- },
116
- 'FunctionDeclaration:exit'(node) {
117
- exitFunction(node);
118
- },
119
- MemberExpression(node) {
120
- if (!currentHandlerNode)
121
- return;
122
- if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
123
- node.property.name === 'getRemainingTimeInMillis') {
124
- hasTimeoutCheck = true;
125
- }
126
- },
127
- NewExpression(node) {
128
- if (!currentHandlerNode)
129
- return;
130
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
131
- node.callee.name === 'AbortController') {
132
- hasTimeoutCheck = true;
133
- }
134
- },
135
- CallExpression(node) {
136
- if (!currentHandlerNode)
137
- return;
138
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
139
- if (EXTERNAL_CALL_PATTERNS.has(node.callee.name)) {
140
- hasExternalCalls = true;
141
- }
142
- }
143
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
144
- const property = node.callee.property;
145
- if (property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
146
- EXTERNAL_CALL_PATTERNS.has(property.name)) {
147
- hasExternalCalls = true;
148
- }
149
- }
150
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
151
- node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
152
- node.callee.object.name === 'Promise' &&
153
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
154
- node.callee.property.name === 'race') {
155
- hasTimeoutCheck = true;
156
- }
157
- },
158
- };
159
- },
160
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireTimeoutHandling=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const CONTEXT_PARAM_NAMES=new Set(["context","ctx","lambdaContext"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);const EXTERNAL_CALL_PATTERNS=new Set(["fetch","axios","got","request","send","invoke","query","execute","connect","promise","wait"]);exports.requireTimeoutHandling=(0,eslint_devkit_1.createRule)({name:"require-timeout-handling",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/require-timeout-handling.md",description:"Warns when Lambda handlers with external calls lack timeout handling",cwe:"CWE-400",cvss:6},hasSuggestions:true,messages:{missingTimeoutHandling:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Missing Timeout Handling",cwe:"CWE-400",cvss:6,description:"Lambda handler makes external calls without timeout handling. Function may timeout without cleanup.",severity:"MEDIUM",fix:"Use context.getRemainingTimeInMillis() to check available time before external calls, or use AbortController",documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html"}),addTimeoutCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Timeout Check",description:"Check remaining time before making external calls to prevent timeouts",severity:"LOW",fix:"const remainingTime = context.getRemainingTimeInMillis(); if (remainingTime < 5000) { return { statusCode: 503 } }",documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],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 hasTimeoutCheck=false;let hasExternalCalls=false;let hasContextParam=false;function enterFunction(node){const params=node.params;const hasEvent=params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&EVENT_PARAM_NAMES.has(p.name));const hasContext=params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&CONTEXT_PARAM_NAMES.has(p.name));if(hasEvent){currentHandlerNode=node;hasTimeoutCheck=false;hasExternalCalls=false;hasContextParam=hasContext}}function exitFunction(node){if(currentHandlerNode!==node)return;if(hasExternalCalls&&!hasTimeoutCheck&&hasContextParam){context.report({node,messageId:"missingTimeoutHandling",suggest:[{messageId:"addTimeoutCheck",fix:()=>null}]})}currentHandlerNode=null}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.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.property.name==="getRemainingTimeInMillis"){hasTimeoutCheck=true}},NewExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="AbortController"){hasTimeoutCheck=true}},CallExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(EXTERNAL_CALL_PATTERNS.has(node.callee.name)){hasExternalCalls=true}}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&&EXTERNAL_CALL_PATTERNS.has(property.name)){hasExternalCalls=true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="Promise"&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="race"){hasTimeoutCheck=true}}}}});