eslint-plugin-lambda-security 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -35
  3. package/package.json +3 -12
  4. package/src/index.d.ts +58 -20
  5. package/src/index.js +70 -3
  6. package/src/rules/no-env-logging/index.d.ts +17 -1
  7. package/src/rules/no-env-logging/index.js +5 -0
  8. package/src/rules/no-error-swallowing/index.d.ts +24 -0
  9. package/src/rules/no-error-swallowing/index.js +197 -0
  10. package/src/rules/no-exposed-error-details/index.d.ts +22 -0
  11. package/src/rules/no-exposed-error-details/index.js +161 -0
  12. package/src/rules/no-hardcoded-credentials-sdk/index.d.ts +18 -1
  13. package/src/rules/no-hardcoded-credentials-sdk/index.js +5 -0
  14. package/src/rules/no-missing-authorization-check/index.d.ts +24 -0
  15. package/src/rules/no-missing-authorization-check/index.js +220 -0
  16. package/src/rules/no-overly-permissive-iam-policy/index.d.ts +22 -0
  17. package/src/rules/no-overly-permissive-iam-policy/index.js +139 -0
  18. package/src/rules/no-permissive-cors-middy/index.d.ts +18 -1
  19. package/src/rules/no-permissive-cors-middy/index.js +5 -0
  20. package/src/rules/no-permissive-cors-response/index.d.ts +18 -1
  21. package/src/rules/no-permissive-cors-response/index.js +5 -0
  22. package/src/rules/no-secrets-in-env/index.d.ts +18 -1
  23. package/src/rules/no-secrets-in-env/index.js +5 -0
  24. package/src/rules/no-unbounded-batch-processing/index.d.ts +24 -0
  25. package/src/rules/no-unbounded-batch-processing/index.js +170 -0
  26. package/src/rules/no-unvalidated-event-body/index.d.ts +24 -0
  27. package/src/rules/no-unvalidated-event-body/index.js +270 -0
  28. package/src/rules/no-user-controlled-requests/index.d.ts +22 -0
  29. package/src/rules/no-user-controlled-requests/index.js +267 -0
  30. package/src/rules/require-timeout-handling/index.d.ts +22 -0
  31. package/src/rules/require-timeout-handling/index.js +171 -0
@@ -0,0 +1,171 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.requireTimeoutHandling = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ // Lambda context parameter names
11
+ const CONTEXT_PARAM_NAMES = ['context', 'ctx', 'lambdaContext'];
12
+ // Event parameter names (to identify Lambda handlers)
13
+ const EVENT_PARAM_NAMES = ['event', 'evt', 'e', 'request', 'req'];
14
+ // External call patterns that could timeout
15
+ const EXTERNAL_CALL_PATTERNS = [
16
+ // HTTP clients
17
+ 'fetch',
18
+ 'axios',
19
+ 'got',
20
+ 'request',
21
+ // AWS SDK
22
+ 'send',
23
+ 'invoke',
24
+ // Database
25
+ 'query',
26
+ 'execute',
27
+ 'connect',
28
+ // Other
29
+ 'promise',
30
+ 'wait',
31
+ ];
32
+ exports.requireTimeoutHandling = (0, eslint_devkit_1.createRule)({
33
+ name: 'require-timeout-handling',
34
+ meta: {
35
+ type: 'suggestion',
36
+ docs: {
37
+ description: 'Warns when Lambda handlers with external calls lack timeout handling',
38
+ },
39
+ hasSuggestions: true,
40
+ messages: {
41
+ missingTimeoutHandling: (0, eslint_devkit_1.formatLLMMessage)({
42
+ icon: eslint_devkit_1.MessageIcons.WARNING,
43
+ issueName: 'Missing Timeout Handling',
44
+ cwe: 'CWE-400',
45
+ cvss: 6.0,
46
+ description: 'Lambda handler makes external calls without timeout handling. Function may timeout without cleanup.',
47
+ severity: 'MEDIUM',
48
+ fix: 'Use context.getRemainingTimeInMillis() to check available time before external calls, or use AbortController',
49
+ documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html',
50
+ }),
51
+ addTimeoutCheck: (0, eslint_devkit_1.formatLLMMessage)({
52
+ icon: eslint_devkit_1.MessageIcons.INFO,
53
+ issueName: 'Add Timeout Check',
54
+ description: 'Check remaining time before making external calls to prevent timeouts',
55
+ severity: 'LOW',
56
+ fix: "const remainingTime = context.getRemainingTimeInMillis(); if (remainingTime < 5000) { return { statusCode: 503 } }",
57
+ documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html',
58
+ }),
59
+ },
60
+ schema: [
61
+ {
62
+ type: 'object',
63
+ properties: {
64
+ allowInTests: {
65
+ type: 'boolean',
66
+ default: true,
67
+ },
68
+ },
69
+ additionalProperties: false,
70
+ },
71
+ ],
72
+ },
73
+ defaultOptions: [{ allowInTests: true }],
74
+ create(context, [options = {}]) {
75
+ const { allowInTests = true } = options;
76
+ const filename = context.filename || context.getFilename();
77
+ const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
78
+ if (allowInTests && isTestFile) {
79
+ return {};
80
+ }
81
+ // Track handler functions
82
+ let currentHandlerNode = null;
83
+ let hasTimeoutCheck = false;
84
+ let hasExternalCalls = false;
85
+ let hasContextParam = false;
86
+ function enterFunction(node) {
87
+ // Check if this looks like a Lambda handler (event, context)
88
+ const params = node.params;
89
+ const hasEvent = params.some((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
90
+ EVENT_PARAM_NAMES.includes(p.name));
91
+ const hasContext = params.some((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
92
+ CONTEXT_PARAM_NAMES.includes(p.name));
93
+ if (hasEvent) {
94
+ currentHandlerNode = node;
95
+ hasTimeoutCheck = false;
96
+ hasExternalCalls = false;
97
+ hasContextParam = hasContext;
98
+ }
99
+ }
100
+ function exitFunction(node) {
101
+ if (currentHandlerNode !== node)
102
+ return;
103
+ // Report if handler has external calls but no timeout handling and has context param
104
+ if (hasExternalCalls && !hasTimeoutCheck && hasContextParam) {
105
+ context.report({
106
+ node,
107
+ messageId: 'missingTimeoutHandling',
108
+ suggest: [
109
+ {
110
+ messageId: 'addTimeoutCheck',
111
+ fix: () => null,
112
+ },
113
+ ],
114
+ });
115
+ }
116
+ currentHandlerNode = null;
117
+ }
118
+ return {
119
+ 'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
120
+ enterFunction(node);
121
+ },
122
+ 'ArrowFunctionExpression:exit, FunctionExpression:exit, FunctionDeclaration:exit'(node) {
123
+ exitFunction(node);
124
+ },
125
+ // Detect getRemainingTimeInMillis() call
126
+ MemberExpression(node) {
127
+ if (!currentHandlerNode)
128
+ return;
129
+ if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
130
+ node.property.name === 'getRemainingTimeInMillis') {
131
+ hasTimeoutCheck = true;
132
+ }
133
+ },
134
+ // Detect AbortController usage
135
+ NewExpression(node) {
136
+ if (!currentHandlerNode)
137
+ return;
138
+ if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
139
+ node.callee.name === 'AbortController') {
140
+ hasTimeoutCheck = true;
141
+ }
142
+ },
143
+ // Detect external calls
144
+ CallExpression(node) {
145
+ if (!currentHandlerNode)
146
+ return;
147
+ // Check for external call patterns
148
+ if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
149
+ if (EXTERNAL_CALL_PATTERNS.includes(node.callee.name)) {
150
+ hasExternalCalls = true;
151
+ }
152
+ }
153
+ if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
154
+ const property = node.callee.property;
155
+ if (property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
156
+ EXTERNAL_CALL_PATTERNS.includes(property.name)) {
157
+ hasExternalCalls = true;
158
+ }
159
+ }
160
+ // Check for Promise.race (timeout pattern)
161
+ if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
162
+ node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
163
+ node.callee.object.name === 'Promise' &&
164
+ node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
165
+ node.callee.property.name === 'race') {
166
+ hasTimeoutCheck = true;
167
+ }
168
+ },
169
+ };
170
+ },
171
+ });