eslint-plugin-lambda-security 1.0.1 → 1.0.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/LICENSE +21 -0
- package/README.md +40 -19
- package/package.json +4 -13
- package/src/index.d.ts +54 -1
- package/src/index.js +65 -3
- package/src/rules/no-error-swallowing/index.d.ts +7 -0
- package/src/rules/no-error-swallowing/index.js +188 -0
- package/src/rules/no-exposed-error-details/index.d.ts +5 -0
- package/src/rules/no-exposed-error-details/index.js +157 -0
- package/src/rules/no-missing-authorization-check/index.d.ts +7 -0
- package/src/rules/no-missing-authorization-check/index.js +216 -0
- package/src/rules/no-overly-permissive-iam-policy/index.d.ts +5 -0
- package/src/rules/no-overly-permissive-iam-policy/index.js +135 -0
- package/src/rules/no-unbounded-batch-processing/index.d.ts +7 -0
- package/src/rules/no-unbounded-batch-processing/index.js +166 -0
- package/src/rules/no-unvalidated-event-body/index.d.ts +7 -0
- package/src/rules/no-unvalidated-event-body/index.js +266 -0
- package/src/rules/no-user-controlled-requests/index.d.ts +5 -0
- package/src/rules/no-user-controlled-requests/index.js +263 -0
- package/src/rules/require-timeout-handling/index.d.ts +5 -0
- package/src/rules/require-timeout-handling/index.js +167 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noExposedErrorDetails = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
// Properties that expose internal details
|
|
6
|
+
const SENSITIVE_ERROR_PROPERTIES = [
|
|
7
|
+
'stack',
|
|
8
|
+
'stackTrace',
|
|
9
|
+
'trace',
|
|
10
|
+
'cause',
|
|
11
|
+
'__dirname',
|
|
12
|
+
'__filename',
|
|
13
|
+
'path',
|
|
14
|
+
'hostname',
|
|
15
|
+
'config',
|
|
16
|
+
'env',
|
|
17
|
+
];
|
|
18
|
+
exports.noExposedErrorDetails = (0, eslint_devkit_1.createRule)({
|
|
19
|
+
name: 'no-exposed-error-details',
|
|
20
|
+
meta: {
|
|
21
|
+
type: 'problem',
|
|
22
|
+
docs: {
|
|
23
|
+
description: 'Detects Lambda handlers exposing internal error details in responses',
|
|
24
|
+
},
|
|
25
|
+
hasSuggestions: true,
|
|
26
|
+
messages: {
|
|
27
|
+
exposedErrorDetails: (0, eslint_devkit_1.formatLLMMessage)({
|
|
28
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
29
|
+
issueName: 'Exposed Error Details',
|
|
30
|
+
cwe: 'CWE-209',
|
|
31
|
+
owasp: 'SAS-9',
|
|
32
|
+
cvss: 4.3,
|
|
33
|
+
description: 'Response exposes {{property}} which may leak internal paths, configs, or stack traces.',
|
|
34
|
+
severity: 'MEDIUM',
|
|
35
|
+
fix: 'Return generic error message. Log detailed errors server-side: console.error(error)',
|
|
36
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/209.html',
|
|
37
|
+
}),
|
|
38
|
+
sanitizeError: (0, eslint_devkit_1.formatLLMMessage)({
|
|
39
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
40
|
+
issueName: 'Sanitize Error Response',
|
|
41
|
+
description: 'Return a generic error message without internal details',
|
|
42
|
+
severity: 'LOW',
|
|
43
|
+
fix: 'return { statusCode: 500, body: JSON.stringify({ message: "Internal server error" }) }',
|
|
44
|
+
documentationLink: 'https://owasp.org/www-community/Improper_Error_Handling',
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
schema: [
|
|
48
|
+
{
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
allowInTests: {
|
|
52
|
+
type: 'boolean',
|
|
53
|
+
default: true,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
additionalProperties: false,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
defaultOptions: [{ allowInTests: true }],
|
|
61
|
+
create(context, [options = {}]) {
|
|
62
|
+
const { allowInTests = true } = options;
|
|
63
|
+
const filename = context.filename || context.getFilename();
|
|
64
|
+
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
65
|
+
if (allowInTests && isTestFile) {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
// Track if we're inside a return statement that looks like API response
|
|
69
|
+
let insideApiResponse = false;
|
|
70
|
+
/**
|
|
71
|
+
* Check if this return looks like an API Gateway response
|
|
72
|
+
*/
|
|
73
|
+
function isApiResponse(node) {
|
|
74
|
+
return node.properties.some((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
|
|
75
|
+
prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
76
|
+
['statusCode', 'body', 'headers'].includes(prop.key.name));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if member expression accesses sensitive property
|
|
80
|
+
*/
|
|
81
|
+
function getSensitiveProperty(node) {
|
|
82
|
+
if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
83
|
+
if (SENSITIVE_ERROR_PROPERTIES.includes(node.property.name)) {
|
|
84
|
+
return node.property.name;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
ReturnStatement(node) {
|
|
91
|
+
if (node.argument?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression &&
|
|
92
|
+
isApiResponse(node.argument)) {
|
|
93
|
+
insideApiResponse = true;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
'ReturnStatement:exit'() {
|
|
97
|
+
insideApiResponse = false;
|
|
98
|
+
},
|
|
99
|
+
MemberExpression(node) {
|
|
100
|
+
if (!insideApiResponse)
|
|
101
|
+
return;
|
|
102
|
+
const sensitiveProperty = getSensitiveProperty(node);
|
|
103
|
+
if (sensitiveProperty) {
|
|
104
|
+
// Check if this is in a body property or response
|
|
105
|
+
const parent = node.parent;
|
|
106
|
+
// error.stack in response
|
|
107
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.Property ||
|
|
108
|
+
parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
|
|
109
|
+
context.report({
|
|
110
|
+
node,
|
|
111
|
+
messageId: 'exposedErrorDetails',
|
|
112
|
+
data: {
|
|
113
|
+
property: sensitiveProperty,
|
|
114
|
+
},
|
|
115
|
+
suggest: [
|
|
116
|
+
{
|
|
117
|
+
messageId: 'sanitizeError',
|
|
118
|
+
fix: () => null,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
// JSON.stringify(error) - stringifying entire error object
|
|
126
|
+
CallExpression(node) {
|
|
127
|
+
if (!insideApiResponse)
|
|
128
|
+
return;
|
|
129
|
+
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
130
|
+
node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
131
|
+
node.callee.object.name === 'JSON' &&
|
|
132
|
+
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
133
|
+
node.callee.property.name === 'stringify') {
|
|
134
|
+
const arg = node.arguments[0];
|
|
135
|
+
if (arg?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
136
|
+
// Check if it looks like an error variable
|
|
137
|
+
if (/error|err|e|exception/i.test(arg.name)) {
|
|
138
|
+
context.report({
|
|
139
|
+
node,
|
|
140
|
+
messageId: 'exposedErrorDetails',
|
|
141
|
+
data: {
|
|
142
|
+
property: 'error object',
|
|
143
|
+
},
|
|
144
|
+
suggest: [
|
|
145
|
+
{
|
|
146
|
+
messageId: 'sanitizeError',
|
|
147
|
+
fix: () => null,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** Allow in test files. Default: true */
|
|
3
|
+
allowInTests?: boolean;
|
|
4
|
+
/** Handler file patterns to check. Default: common Lambda patterns */
|
|
5
|
+
handlerPatterns?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const noMissingAuthorizationCheck: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noMissingAuthorizationCheck = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
// Property accesses that indicate authorization checks
|
|
6
|
+
const AUTHORIZATION_CHECK_PATTERNS = [
|
|
7
|
+
// API Gateway authorizer
|
|
8
|
+
'requestContext.authorizer',
|
|
9
|
+
'requestContext.identity',
|
|
10
|
+
// JWT/Token validation
|
|
11
|
+
'Authorization',
|
|
12
|
+
'authorization',
|
|
13
|
+
// Common auth checks
|
|
14
|
+
'claims',
|
|
15
|
+
'principalId',
|
|
16
|
+
'isAdmin',
|
|
17
|
+
'isAuthenticated',
|
|
18
|
+
'userId',
|
|
19
|
+
'sub',
|
|
20
|
+
'scope',
|
|
21
|
+
'permissions',
|
|
22
|
+
];
|
|
23
|
+
// Sensitive operations that require authorization
|
|
24
|
+
const SENSITIVE_OPERATIONS = [
|
|
25
|
+
// Database operations
|
|
26
|
+
'query',
|
|
27
|
+
'put',
|
|
28
|
+
'delete',
|
|
29
|
+
'update',
|
|
30
|
+
'insert',
|
|
31
|
+
'remove',
|
|
32
|
+
'create',
|
|
33
|
+
// AWS SDK operations
|
|
34
|
+
'send',
|
|
35
|
+
'invoke',
|
|
36
|
+
'putObject',
|
|
37
|
+
'deleteObject',
|
|
38
|
+
'getObject',
|
|
39
|
+
'putItem',
|
|
40
|
+
'deleteItem',
|
|
41
|
+
'updateItem',
|
|
42
|
+
'getItem',
|
|
43
|
+
];
|
|
44
|
+
// Event parameter names
|
|
45
|
+
const EVENT_PARAM_NAMES = ['event', 'evt', 'e', 'request', 'req'];
|
|
46
|
+
exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
|
|
47
|
+
name: 'no-missing-authorization-check',
|
|
48
|
+
meta: {
|
|
49
|
+
type: 'problem',
|
|
50
|
+
docs: {
|
|
51
|
+
description: 'Detects Lambda handlers without authorization checks',
|
|
52
|
+
},
|
|
53
|
+
hasSuggestions: true,
|
|
54
|
+
messages: {
|
|
55
|
+
missingAuthCheck: (0, eslint_devkit_1.formatLLMMessage)({
|
|
56
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
57
|
+
issueName: 'Missing Authorization Check',
|
|
58
|
+
cwe: 'CWE-862',
|
|
59
|
+
owasp: 'SAS-5',
|
|
60
|
+
cvss: 7.5,
|
|
61
|
+
description: 'Lambda handler performs {{operation}} operation without authorization check. Users may access resources without proper permissions.',
|
|
62
|
+
severity: 'HIGH',
|
|
63
|
+
fix: "Add authorization check: const claims = event.requestContext.authorizer?.claims; if (!claims?.sub) { return { statusCode: 401 } }",
|
|
64
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/862.html',
|
|
65
|
+
}),
|
|
66
|
+
addAuthCheck: (0, eslint_devkit_1.formatLLMMessage)({
|
|
67
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
68
|
+
issueName: 'Add Authorization Check',
|
|
69
|
+
description: 'Check event.requestContext.authorizer for API Gateway or implement custom JWT validation',
|
|
70
|
+
severity: 'LOW',
|
|
71
|
+
fix: "const userId = event.requestContext.authorizer?.claims?.sub; if (!userId) throw new Error('Unauthorized');",
|
|
72
|
+
documentationLink: 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html',
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
schema: [
|
|
76
|
+
{
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
allowInTests: {
|
|
80
|
+
type: 'boolean',
|
|
81
|
+
default: true,
|
|
82
|
+
description: 'Allow missing auth in test files',
|
|
83
|
+
},
|
|
84
|
+
handlerPatterns: {
|
|
85
|
+
type: 'array',
|
|
86
|
+
items: { type: 'string' },
|
|
87
|
+
description: 'Handler file patterns to check',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
additionalProperties: false,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
defaultOptions: [
|
|
95
|
+
{
|
|
96
|
+
allowInTests: true,
|
|
97
|
+
handlerPatterns: [],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
create(context, [options = {}]) {
|
|
101
|
+
const { allowInTests = true } = options;
|
|
102
|
+
const filename = context.filename || context.getFilename();
|
|
103
|
+
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
104
|
+
if (allowInTests && isTestFile) {
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
// Track state within each handler function
|
|
108
|
+
let currentFunctionNode = null;
|
|
109
|
+
let hasAuthCheck = false;
|
|
110
|
+
let hasEventParameter = false;
|
|
111
|
+
const sensitiveOperations = [];
|
|
112
|
+
/**
|
|
113
|
+
* Reset state when entering a new function
|
|
114
|
+
*/
|
|
115
|
+
function enterFunction(node) {
|
|
116
|
+
// Check if this function has an event parameter
|
|
117
|
+
const hasEvent = node.params.some((param) => param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
118
|
+
EVENT_PARAM_NAMES.includes(param.name));
|
|
119
|
+
if (hasEvent) {
|
|
120
|
+
currentFunctionNode = node;
|
|
121
|
+
hasAuthCheck = false;
|
|
122
|
+
hasEventParameter = true;
|
|
123
|
+
sensitiveOperations.length = 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Check and report on function exit
|
|
128
|
+
*/
|
|
129
|
+
function exitFunction(node) {
|
|
130
|
+
if (currentFunctionNode !== node)
|
|
131
|
+
return;
|
|
132
|
+
// Report if we have sensitive operations without auth check
|
|
133
|
+
if (hasEventParameter && !hasAuthCheck) {
|
|
134
|
+
for (const { node: opNode, operation } of sensitiveOperations) {
|
|
135
|
+
context.report({
|
|
136
|
+
node: opNode,
|
|
137
|
+
messageId: 'missingAuthCheck',
|
|
138
|
+
data: { operation },
|
|
139
|
+
suggest: [
|
|
140
|
+
{
|
|
141
|
+
messageId: 'addAuthCheck',
|
|
142
|
+
fix: () => null,
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
currentFunctionNode = null;
|
|
149
|
+
hasEventParameter = false;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check if a member expression chain indicates auth check
|
|
153
|
+
*/
|
|
154
|
+
function isAuthorizationAccess(node) {
|
|
155
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
156
|
+
const text = sourceCode.getText(node);
|
|
157
|
+
return AUTHORIZATION_CHECK_PATTERNS.some((pattern) => text.includes(pattern) ||
|
|
158
|
+
text.toLowerCase().includes(pattern.toLowerCase()));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Check if call is a sensitive operation
|
|
162
|
+
*/
|
|
163
|
+
function getSensitiveOperationName(node) {
|
|
164
|
+
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
165
|
+
const property = node.callee.property;
|
|
166
|
+
if (property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
167
|
+
if (SENSITIVE_OPERATIONS.includes(property.name)) {
|
|
168
|
+
return property.name;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
|
|
176
|
+
enterFunction(node);
|
|
177
|
+
},
|
|
178
|
+
'ArrowFunctionExpression:exit, FunctionExpression:exit, FunctionDeclaration:exit'(node) {
|
|
179
|
+
exitFunction(node);
|
|
180
|
+
},
|
|
181
|
+
// Detect authorization checks
|
|
182
|
+
MemberExpression(node) {
|
|
183
|
+
if (!currentFunctionNode)
|
|
184
|
+
return;
|
|
185
|
+
if (isAuthorizationAccess(node)) {
|
|
186
|
+
hasAuthCheck = true;
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
// Track sensitive operations
|
|
190
|
+
CallExpression(node) {
|
|
191
|
+
if (!currentFunctionNode)
|
|
192
|
+
return;
|
|
193
|
+
const operation = getSensitiveOperationName(node);
|
|
194
|
+
if (operation) {
|
|
195
|
+
sensitiveOperations.push({ node, operation });
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
// Detect early returns (401/403) as auth checks
|
|
199
|
+
ReturnStatement(node) {
|
|
200
|
+
if (!currentFunctionNode)
|
|
201
|
+
return;
|
|
202
|
+
if (node.argument?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
203
|
+
for (const prop of node.argument.properties) {
|
|
204
|
+
if (prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
|
|
205
|
+
prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
206
|
+
prop.key.name === 'statusCode' &&
|
|
207
|
+
prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
208
|
+
(prop.value.value === 401 || prop.value.value === 403)) {
|
|
209
|
+
hasAuthCheck = true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noOverlyPermissiveIamPolicy = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
// IAM policy property names
|
|
6
|
+
const POLICY_PROPERTIES = ['Resource', 'Action', 'Principal'];
|
|
7
|
+
// Wildcards that indicate overly permissive
|
|
8
|
+
const DANGEROUS_WILDCARDS = ['*', 'arn:aws:*', 'arn:*:*:*:*:*'];
|
|
9
|
+
exports.noOverlyPermissiveIamPolicy = (0, eslint_devkit_1.createRule)({
|
|
10
|
+
name: 'no-overly-permissive-iam-policy',
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Detects IAM policies with overly broad permissions (wildcards)',
|
|
15
|
+
},
|
|
16
|
+
hasSuggestions: true,
|
|
17
|
+
messages: {
|
|
18
|
+
permissivePolicy: (0, eslint_devkit_1.formatLLMMessage)({
|
|
19
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
20
|
+
issueName: 'Overly Permissive IAM Policy',
|
|
21
|
+
cwe: 'CWE-732',
|
|
22
|
+
owasp: 'SAS-5',
|
|
23
|
+
cvss: 6.5,
|
|
24
|
+
description: 'IAM policy has wildcard {{property}}: "{{value}}". Violates principle of least privilege.',
|
|
25
|
+
severity: 'HIGH',
|
|
26
|
+
fix: 'Restrict {{property}} to specific resources/actions. Example: "arn:aws:s3:::my-bucket/*" instead of "*"',
|
|
27
|
+
documentationLink: 'https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege',
|
|
28
|
+
}),
|
|
29
|
+
useLeastPrivilege: (0, eslint_devkit_1.formatLLMMessage)({
|
|
30
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
31
|
+
issueName: 'Apply Least Privilege',
|
|
32
|
+
description: 'Restrict permissions to specific resources and actions',
|
|
33
|
+
severity: 'LOW',
|
|
34
|
+
fix: 'Replace "*" with specific ARNs and action names',
|
|
35
|
+
documentationLink: 'https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html',
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
schema: [
|
|
39
|
+
{
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
allowInTests: {
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
default: true,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
additionalProperties: false,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
defaultOptions: [{ allowInTests: true }],
|
|
52
|
+
create(context, [options = {}]) {
|
|
53
|
+
const { allowInTests = true } = options;
|
|
54
|
+
const filename = context.filename || context.getFilename();
|
|
55
|
+
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
56
|
+
if (allowInTests && isTestFile) {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if a value is a dangerous wildcard
|
|
61
|
+
*/
|
|
62
|
+
function isDangerousWildcard(value) {
|
|
63
|
+
return (DANGEROUS_WILDCARDS.includes(value) ||
|
|
64
|
+
(value.endsWith('*') && value.includes(':*:')));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check property values for wildcards
|
|
68
|
+
*/
|
|
69
|
+
function checkPolicyProperty(node, propertyName) {
|
|
70
|
+
const value = node.value;
|
|
71
|
+
// Check literal string
|
|
72
|
+
if (value.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof value.value === 'string') {
|
|
73
|
+
if (isDangerousWildcard(value.value)) {
|
|
74
|
+
context.report({
|
|
75
|
+
node,
|
|
76
|
+
messageId: 'permissivePolicy',
|
|
77
|
+
data: {
|
|
78
|
+
property: propertyName,
|
|
79
|
+
value: value.value,
|
|
80
|
+
},
|
|
81
|
+
suggest: [
|
|
82
|
+
{
|
|
83
|
+
messageId: 'useLeastPrivilege',
|
|
84
|
+
fix: () => null,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Check array of values
|
|
91
|
+
if (value.type === eslint_devkit_1.AST_NODE_TYPES.ArrayExpression) {
|
|
92
|
+
for (const element of value.elements) {
|
|
93
|
+
if (element?.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
94
|
+
typeof element.value === 'string') {
|
|
95
|
+
if (isDangerousWildcard(element.value)) {
|
|
96
|
+
context.report({
|
|
97
|
+
node: element,
|
|
98
|
+
messageId: 'permissivePolicy',
|
|
99
|
+
data: {
|
|
100
|
+
property: propertyName,
|
|
101
|
+
value: element.value,
|
|
102
|
+
},
|
|
103
|
+
suggest: [
|
|
104
|
+
{
|
|
105
|
+
messageId: 'useLeastPrivilege',
|
|
106
|
+
fix: () => null,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
Property(node) {
|
|
117
|
+
// Check for IAM policy properties
|
|
118
|
+
if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
119
|
+
const keyName = node.key.name;
|
|
120
|
+
if (POLICY_PROPERTIES.includes(keyName)) {
|
|
121
|
+
checkPolicyProperty(node, keyName);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Also check string key properties
|
|
125
|
+
if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
126
|
+
typeof node.key.value === 'string') {
|
|
127
|
+
const keyName = node.key.value;
|
|
128
|
+
if (POLICY_PROPERTIES.includes(keyName)) {
|
|
129
|
+
checkPolicyProperty(node, keyName);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** Allow in test files. Default: true */
|
|
3
|
+
allowInTests?: boolean;
|
|
4
|
+
/** Maximum allowed batch size before warning. Default: 100 */
|
|
5
|
+
maxBatchSize?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const noUnboundedBatchProcessing: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|