eslint-plugin-lambda-security 1.3.1 → 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.
- package/package.json +2 -3
- package/src/index.js +1 -85
- package/src/oxlint.js +1 -3
- package/src/rules/no-env-logging/index.js +1 -113
- package/src/rules/no-error-swallowing/index.js +1 -135
- package/src/rules/no-exposed-debug-endpoints/index.js +1 -120
- package/src/rules/no-exposed-error-details/index.js +1 -147
- package/src/rules/no-hardcoded-credentials-sdk/index.js +1 -194
- package/src/rules/no-missing-authorization-check/index.js +1 -198
- package/src/rules/no-overly-permissive-iam-policy/index.js +1 -125
- package/src/rules/no-permissive-cors-middy/index.js +1 -125
- package/src/rules/no-permissive-cors-response/index.js +1 -119
- package/src/rules/no-secrets-in-env/index.js +1 -143
- package/src/rules/no-unbounded-batch-processing/index.js +1 -168
- package/src/rules/no-unvalidated-event-body/index.js +1 -276
- package/src/rules/no-user-controlled-requests/index.js +1 -224
- package/src/rules/require-timeout-handling/index.js +1 -160
|
@@ -1,224 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUserControlledRequests = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const HTTP_CLIENT_METHODS = new Set([
|
|
6
|
-
'fetch',
|
|
7
|
-
'request',
|
|
8
|
-
'get',
|
|
9
|
-
'post',
|
|
10
|
-
'put',
|
|
11
|
-
'delete',
|
|
12
|
-
'patch',
|
|
13
|
-
'axios',
|
|
14
|
-
'got',
|
|
15
|
-
'nodeFetch',
|
|
16
|
-
'superagent',
|
|
17
|
-
]);
|
|
18
|
-
const HTTP_CLIENT_OBJECTS = new Set(['http', 'https', 'axios', 'got', 'request']);
|
|
19
|
-
const USER_INPUT_PROPERTIES = new Set([
|
|
20
|
-
'body',
|
|
21
|
-
'queryStringParameters',
|
|
22
|
-
'pathParameters',
|
|
23
|
-
'multiValueQueryStringParameters',
|
|
24
|
-
'headers',
|
|
25
|
-
'rawPath',
|
|
26
|
-
'rawQueryString',
|
|
27
|
-
]);
|
|
28
|
-
const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
|
|
29
|
-
exports.noUserControlledRequests = (0, eslint_devkit_1.createRule)({
|
|
30
|
-
name: 'no-user-controlled-requests',
|
|
31
|
-
meta: {
|
|
32
|
-
type: 'problem',
|
|
33
|
-
docs: {
|
|
34
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-user-controlled-requests.md',
|
|
35
|
-
description: 'Detects HTTP requests with user-controlled URLs (SSRF vulnerability)',
|
|
36
|
-
cwe: 'CWE-918',
|
|
37
|
-
cvss: 9.1,
|
|
38
|
-
},
|
|
39
|
-
hasSuggestions: true,
|
|
40
|
-
messages: {
|
|
41
|
-
ssrfVulnerability: (0, eslint_devkit_1.formatLLMMessage)({
|
|
42
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
43
|
-
issueName: 'Server-Side Request Forgery (SSRF)',
|
|
44
|
-
cwe: 'CWE-918',
|
|
45
|
-
cvss: 9.1,
|
|
46
|
-
description: 'HTTP request URL contains user-controlled input from {{source}}. Attackers can access internal services or exfiltrate data.',
|
|
47
|
-
severity: 'CRITICAL',
|
|
48
|
-
fix: 'Validate URL against allowlist before making request. Never use user input directly in URLs.',
|
|
49
|
-
documentationLink: 'https://owasp.org/www-community/attacks/Server_Side_Request_Forgery',
|
|
50
|
-
}),
|
|
51
|
-
useAllowlist: (0, eslint_devkit_1.formatLLMMessage)({
|
|
52
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
53
|
-
issueName: 'Use URL Allowlist',
|
|
54
|
-
description: 'Implement an allowlist for permitted URL domains/hosts',
|
|
55
|
-
severity: 'LOW',
|
|
56
|
-
fix: "const ALLOWED_HOSTS = ['api.trusted.com']; if (!ALLOWED_HOSTS.includes(new URL(url).host)) throw new Error('Invalid URL')",
|
|
57
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html',
|
|
58
|
-
}),
|
|
59
|
-
},
|
|
60
|
-
schema: [
|
|
61
|
-
{
|
|
62
|
-
type: 'object',
|
|
63
|
-
properties: {
|
|
64
|
-
allowInTests: {
|
|
65
|
-
type: 'boolean',
|
|
66
|
-
default: true,
|
|
67
|
-
description: 'Allow user-controlled URLs in test files',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
additionalProperties: false,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
defaultOptions: [
|
|
75
|
-
{
|
|
76
|
-
allowInTests: true,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
create(context, [options = {}]) {
|
|
80
|
-
const { allowInTests = true } = options;
|
|
81
|
-
const filename = context.filename;
|
|
82
|
-
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
83
|
-
if (allowInTests && isTestFile) {
|
|
84
|
-
return {};
|
|
85
|
-
}
|
|
86
|
-
const eventParameters = new Set();
|
|
87
|
-
const taintedVariables = new Map();
|
|
88
|
-
function isEventParameter(name) {
|
|
89
|
-
return eventParameters.has(name);
|
|
90
|
-
}
|
|
91
|
-
function getEventInputSource(node) {
|
|
92
|
-
if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
93
|
-
isEventParameter(node.object.name) &&
|
|
94
|
-
node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
95
|
-
USER_INPUT_PROPERTIES.has(node.property.name)) {
|
|
96
|
-
return `event.${node.property.name}`;
|
|
97
|
-
}
|
|
98
|
-
if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
99
|
-
node.object.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
100
|
-
isEventParameter(node.object.object.name) &&
|
|
101
|
-
node.object.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
102
|
-
USER_INPUT_PROPERTIES.has(node.object.property.name)) {
|
|
103
|
-
return `event.${node.object.property.name}.${node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
|
|
104
|
-
? node.property.name
|
|
105
|
-
: '[...]'}`;
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
function getTaintSource(node) {
|
|
110
|
-
if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
111
|
-
const source = getEventInputSource(node);
|
|
112
|
-
if (source)
|
|
113
|
-
return source;
|
|
114
|
-
}
|
|
115
|
-
if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
116
|
-
const source = taintedVariables.get(node.name);
|
|
117
|
-
if (source)
|
|
118
|
-
return source;
|
|
119
|
-
}
|
|
120
|
-
if (node.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
121
|
-
for (const expr of node.expressions) {
|
|
122
|
-
const source = getTaintSource(expr);
|
|
123
|
-
if (source)
|
|
124
|
-
return source;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (node.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
|
|
128
|
-
const leftSource = getTaintSource(node.left);
|
|
129
|
-
if (leftSource)
|
|
130
|
-
return leftSource;
|
|
131
|
-
const rightSource = getTaintSource(node.right);
|
|
132
|
-
if (rightSource)
|
|
133
|
-
return rightSource;
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
function isHttpClientCall(node) {
|
|
138
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
139
|
-
HTTP_CLIENT_METHODS.has(node.callee.name)) {
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
143
|
-
node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
144
|
-
HTTP_CLIENT_OBJECTS.has(node.callee.object.name)) {
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
148
|
-
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
149
|
-
['get', 'post', 'put', 'delete', 'patch', 'request'].includes(node.callee.property.name)) {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
function checkUrlArgument(node) {
|
|
155
|
-
if (node.arguments.length === 0)
|
|
156
|
-
return null;
|
|
157
|
-
const urlArg = node.arguments[0];
|
|
158
|
-
const source = getTaintSource(urlArg);
|
|
159
|
-
if (source) {
|
|
160
|
-
return { tainted: true, source };
|
|
161
|
-
}
|
|
162
|
-
if (urlArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
163
|
-
for (const prop of urlArg.properties) {
|
|
164
|
-
if (prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
|
|
165
|
-
prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
166
|
-
['url', 'uri', 'href', 'baseURL'].includes(prop.key.name)) {
|
|
167
|
-
const propSource = getTaintSource(prop.value);
|
|
168
|
-
if (propSource) {
|
|
169
|
-
return { tainted: true, source: propSource };
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
|
|
178
|
-
for (const param of node.params) {
|
|
179
|
-
if (param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
180
|
-
if (EVENT_PARAM_NAMES.has(param.name)) {
|
|
181
|
-
eventParameters.add(param.name);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
VariableDeclarator(node) {
|
|
187
|
-
if (node.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && node.init) {
|
|
188
|
-
const source = getTaintSource(node.init);
|
|
189
|
-
if (source) {
|
|
190
|
-
taintedVariables.set(node.id.name, source);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
AssignmentExpression(node) {
|
|
195
|
-
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
196
|
-
const source = getTaintSource(node.right);
|
|
197
|
-
if (source) {
|
|
198
|
-
taintedVariables.set(node.left.name, source);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
CallExpression(node) {
|
|
203
|
-
if (!isHttpClientCall(node))
|
|
204
|
-
return;
|
|
205
|
-
const result = checkUrlArgument(node);
|
|
206
|
-
if (result?.tainted) {
|
|
207
|
-
context.report({
|
|
208
|
-
node,
|
|
209
|
-
messageId: 'ssrfVulnerability',
|
|
210
|
-
data: {
|
|
211
|
-
source: result.source,
|
|
212
|
-
},
|
|
213
|
-
suggest: [
|
|
214
|
-
{
|
|
215
|
-
messageId: 'useAllowlist',
|
|
216
|
-
fix: () => null,
|
|
217
|
-
},
|
|
218
|
-
],
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
},
|
|
224
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUserControlledRequests=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const HTTP_CLIENT_METHODS=new Set(["fetch","request","get","post","put","delete","patch","axios","got","nodeFetch","superagent"]);const HTTP_CLIENT_OBJECTS=new Set(["http","https","axios","got","request"]);const USER_INPUT_PROPERTIES=new Set(["body","queryStringParameters","pathParameters","multiValueQueryStringParameters","headers","rawPath","rawQueryString"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noUserControlledRequests=(0,eslint_devkit_1.createRule)({name:"no-user-controlled-requests",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-user-controlled-requests.md",description:"Detects HTTP requests with user-controlled URLs (SSRF vulnerability)",cwe:"CWE-918",cvss:9.1},hasSuggestions:true,messages:{ssrfVulnerability:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Server-Side Request Forgery (SSRF)",cwe:"CWE-918",cvss:9.1,description:"HTTP request URL contains user-controlled input from {{source}}. Attackers can access internal services or exfiltrate data.",severity:"CRITICAL",fix:"Validate URL against allowlist before making request. Never use user input directly in URLs.",documentationLink:"https://owasp.org/www-community/attacks/Server_Side_Request_Forgery"}),useAllowlist:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use URL Allowlist",description:"Implement an allowlist for permitted URL domains/hosts",severity:"LOW",fix:"const ALLOWED_HOSTS = ['api.trusted.com']; if (!ALLOWED_HOSTS.includes(new URL(url).host)) throw new Error('Invalid URL')",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow user-controlled URLs in test files"}},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{}}const eventParameters=new Set;const taintedVariables=new Map;function isEventParameter(name){return eventParameters.has(name)}function getEventInputSource(node){if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isEventParameter(node.object.name)&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&USER_INPUT_PROPERTIES.has(node.property.name)){return`event.${node.property.name}`}if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isEventParameter(node.object.object.name)&&node.object.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&USER_INPUT_PROPERTIES.has(node.object.property.name)){return`event.${node.object.property.name}.${node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.property.name:"[...]"}`}return null}function getTaintSource(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const source=getEventInputSource(node);if(source)return source}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const source=taintedVariables.get(node.name);if(source)return source}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){for(const expr of node.expressions){const source=getTaintSource(expr);if(source)return source}}if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression){const leftSource=getTaintSource(node.left);if(leftSource)return leftSource;const rightSource=getTaintSource(node.right);if(rightSource)return rightSource}return null}function isHttpClientCall(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HTTP_CLIENT_METHODS.has(node.callee.name)){return true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HTTP_CLIENT_OBJECTS.has(node.callee.object.name)){return true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["get","post","put","delete","patch","request"].includes(node.callee.property.name)){return true}return false}function checkUrlArgument(node){if(node.arguments.length===0)return null;const urlArg=node.arguments[0];const source=getTaintSource(urlArg);if(source){return{tainted:true,source}}if(urlArg.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of urlArg.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["url","uri","href","baseURL"].includes(prop.key.name)){const propSource=getTaintSource(prop.value);if(propSource){return{tainted:true,source:propSource}}}}}return null}return{"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){for(const param of node.params){if(param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(EVENT_PARAM_NAMES.has(param.name)){eventParameters.add(param.name)}}}},VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.init){const source=getTaintSource(node.init);if(source){taintedVariables.set(node.id.name,source)}}},AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const source=getTaintSource(node.right);if(source){taintedVariables.set(node.left.name,source)}}},CallExpression(node){if(!isHttpClientCall(node))return;const result=checkUrlArgument(node);if(result?.tainted){context.report({node,messageId:"ssrfVulnerability",data:{source:result.source},suggest:[{messageId:"useAllowlist",fix:()=>null}]})}}}}});
|
|
@@ -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}}}}});
|