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,194 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noHardcodedCredentialsSdk = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const AWS_ACCESS_KEY_PATTERNS = [
6
- /^AKIA[0-9A-Z]{16}$/,
7
- /^ASIA[0-9A-Z]{16}$/,
8
- /^AIDA[0-9A-Z]{16}$/,
9
- ];
10
- const CREDENTIAL_PROPERTY_NAMES = [
11
- 'accessKeyId',
12
- 'secretAccessKey',
13
- 'sessionToken',
14
- 'awsAccessKeyId',
15
- 'awsSecretAccessKey',
16
- ];
17
- const AWS_SDK_V3_CLIENTS = new Set([
18
- 'S3Client',
19
- 'DynamoDBClient',
20
- 'LambdaClient',
21
- 'SQSClient',
22
- 'SNSClient',
23
- 'SecretsManagerClient',
24
- 'KMSClient',
25
- 'STSClient',
26
- 'IAMClient',
27
- 'EC2Client',
28
- 'ECSClient',
29
- 'CloudWatchClient',
30
- 'CloudWatchLogsClient',
31
- 'APIGatewayClient',
32
- 'CognitoIdentityClient',
33
- 'CognitoIdentityProviderClient',
34
- 'EventBridgeClient',
35
- 'StepFunctionsClient',
36
- 'RDSClient',
37
- 'ElastiCacheClient',
38
- ]);
39
- exports.noHardcodedCredentialsSdk = (0, eslint_devkit_1.createRule)({
40
- name: 'no-hardcoded-credentials-sdk',
41
- meta: {
42
- type: 'problem',
43
- docs: {
44
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-hardcoded-credentials-sdk.md',
45
- description: 'Detects hardcoded AWS credentials in SDK client configurations',
46
- cwe: 'CWE-798',
47
- cvss: 9.8,
48
- },
49
- hasSuggestions: true,
50
- messages: {
51
- hardcodedCredentials: (0, eslint_devkit_1.formatLLMMessage)({
52
- icon: eslint_devkit_1.MessageIcons.SECURITY,
53
- issueName: 'Hardcoded AWS Credentials',
54
- cwe: 'CWE-798',
55
- description: 'Hardcoded AWS credentials detected in {{clientName}} config: {{property}}',
56
- severity: 'CRITICAL',
57
- fix: 'Use credential provider chain: new {{clientName}}({ credentials: fromNodeProviderChain() })',
58
- documentationLink: 'https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html',
59
- }),
60
- useCredentialProvider: (0, eslint_devkit_1.formatLLMMessage)({
61
- icon: eslint_devkit_1.MessageIcons.INFO,
62
- issueName: 'Use Credential Provider',
63
- description: 'Use AWS credential provider chain instead of hardcoded credentials',
64
- severity: 'LOW',
65
- fix: 'import { fromNodeProviderChain } from "@aws-sdk/credential-providers"',
66
- documentationLink: 'https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html',
67
- }),
68
- },
69
- schema: [
70
- {
71
- type: 'object',
72
- properties: {
73
- allowInTests: {
74
- type: 'boolean',
75
- default: true,
76
- description: 'Allow hardcoded credentials in test files',
77
- },
78
- },
79
- additionalProperties: false,
80
- },
81
- ],
82
- },
83
- defaultOptions: [
84
- {
85
- allowInTests: true,
86
- },
87
- ],
88
- create(context, [options = {}]) {
89
- const { allowInTests = true } = options;
90
- const filename = context.filename;
91
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
92
- if (allowInTests && isTestFile) {
93
- return {};
94
- }
95
- function looksLikeAwsAccessKey(value) {
96
- return AWS_ACCESS_KEY_PATTERNS.some(pattern => pattern.test(value));
97
- }
98
- function isCredentialProperty(name) {
99
- return CREDENTIAL_PROPERTY_NAMES.some(credProp => name.toLowerCase() === credProp.toLowerCase());
100
- }
101
- function getAwsClientName(node) {
102
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
103
- const name = node.callee.name;
104
- if (AWS_SDK_V3_CLIENTS.has(name)) {
105
- return name;
106
- }
107
- if (name.endsWith('Client') && /^(S3|DynamoDB|Lambda|SQS|SNS|Secrets|KMS|STS|IAM|EC2|ECS|CloudWatch|APIGateway|Cognito|EventBridge|StepFunctions|RDS|ElastiCache|SSM|Athena|Glue|Kinesis|Firehose|Rekognition|Textract|Comprehend|Polly|Lex|Bedrock|My|Custom|AWS)/i.test(name)) {
108
- return name;
109
- }
110
- }
111
- return null;
112
- }
113
- function checkCredentialsObject(obj, clientName) {
114
- for (const prop of obj.properties) {
115
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
116
- continue;
117
- if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
118
- prop.key.name === 'credentials' &&
119
- prop.value.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
120
- checkCredentialsInner(prop.value, clientName);
121
- }
122
- if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
123
- isCredentialProperty(prop.key.name)) {
124
- if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof prop.value.value === 'string') {
125
- reportHardcodedCredential(prop, clientName, prop.key.name);
126
- }
127
- }
128
- }
129
- }
130
- function checkCredentialsInner(obj, clientName) {
131
- for (const prop of obj.properties) {
132
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
133
- continue;
134
- if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && isCredentialProperty(prop.key.name)) {
135
- if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof prop.value.value === 'string') {
136
- const value = prop.value.value;
137
- const keyName = prop.key.name.toLowerCase();
138
- if (keyName === 'accesskeyid') {
139
- if (looksLikeAwsAccessKey(value)) {
140
- reportHardcodedCredential(prop, clientName, prop.key.name);
141
- }
142
- }
143
- else if (keyName === 'secretaccesskey') {
144
- if (value.length >= 20) {
145
- reportHardcodedCredential(prop, clientName, prop.key.name);
146
- }
147
- }
148
- else if (keyName === 'sessiontoken') {
149
- if (value.length >= 15) {
150
- reportHardcodedCredential(prop, clientName, prop.key.name);
151
- }
152
- }
153
- }
154
- else if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
155
- reportHardcodedCredential(prop, clientName, prop.key.name);
156
- }
157
- }
158
- }
159
- }
160
- function reportHardcodedCredential(node, clientName, propertyName) {
161
- context.report({
162
- node,
163
- messageId: 'hardcodedCredentials',
164
- data: {
165
- clientName,
166
- property: propertyName,
167
- },
168
- suggest: [
169
- {
170
- messageId: 'useCredentialProvider',
171
- fix: () => null,
172
- },
173
- ],
174
- });
175
- }
176
- return {
177
- NewExpression(node) {
178
- const clientName = getAwsClientName(node);
179
- if (!clientName)
180
- return;
181
- if (node.arguments.length > 0 && node.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
182
- checkCredentialsObject(node.arguments[0], clientName);
183
- }
184
- },
185
- VariableDeclarator(node) {
186
- if (node.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
187
- node.id.name.toLowerCase().includes('credential') &&
188
- node.init?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
189
- checkCredentialsInner(node.init, 'AWSClient');
190
- }
191
- },
192
- };
193
- },
194
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHardcodedCredentialsSdk=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const AWS_ACCESS_KEY_PATTERNS=[/^AKIA[0-9A-Z]{16}$/,/^ASIA[0-9A-Z]{16}$/,/^AIDA[0-9A-Z]{16}$/];const CREDENTIAL_PROPERTY_NAMES=["accessKeyId","secretAccessKey","sessionToken","awsAccessKeyId","awsSecretAccessKey"];const AWS_SDK_V3_CLIENTS=new Set(["S3Client","DynamoDBClient","LambdaClient","SQSClient","SNSClient","SecretsManagerClient","KMSClient","STSClient","IAMClient","EC2Client","ECSClient","CloudWatchClient","CloudWatchLogsClient","APIGatewayClient","CognitoIdentityClient","CognitoIdentityProviderClient","EventBridgeClient","StepFunctionsClient","RDSClient","ElastiCacheClient"]);exports.noHardcodedCredentialsSdk=(0,eslint_devkit_1.createRule)({name:"no-hardcoded-credentials-sdk",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-hardcoded-credentials-sdk.md",description:"Detects hardcoded AWS credentials in SDK client configurations",cwe:"CWE-798",cvss:9.8},hasSuggestions:true,messages:{hardcodedCredentials:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Hardcoded AWS Credentials",cwe:"CWE-798",description:"Hardcoded AWS credentials detected in {{clientName}} config: {{property}}",severity:"CRITICAL",fix:"Use credential provider chain: new {{clientName}}({ credentials: fromNodeProviderChain() })",documentationLink:"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html"}),useCredentialProvider:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Credential Provider",description:"Use AWS credential provider chain instead of hardcoded credentials",severity:"LOW",fix:'import { fromNodeProviderChain } from "@aws-sdk/credential-providers"',documentationLink:"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow hardcoded credentials 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{}}function looksLikeAwsAccessKey(value){return AWS_ACCESS_KEY_PATTERNS.some(pattern=>pattern.test(value))}function isCredentialProperty(name){return CREDENTIAL_PROPERTY_NAMES.some(credProp=>name.toLowerCase()===credProp.toLowerCase())}function getAwsClientName(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const name=node.callee.name;if(AWS_SDK_V3_CLIENTS.has(name)){return name}if(name.endsWith("Client")&&/^(S3|DynamoDB|Lambda|SQS|SNS|Secrets|KMS|STS|IAM|EC2|ECS|CloudWatch|APIGateway|Cognito|EventBridge|StepFunctions|RDS|ElastiCache|SSM|Athena|Glue|Kinesis|Firehose|Rekognition|Textract|Comprehend|Polly|Lex|Bedrock|My|Custom|AWS)/i.test(name)){return name}}return null}function checkCredentialsObject(obj,clientName){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&prop.key.name==="credentials"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsInner(prop.value,clientName)}if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isCredentialProperty(prop.key.name)){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof prop.value.value==="string"){reportHardcodedCredential(prop,clientName,prop.key.name)}}}}function checkCredentialsInner(obj,clientName){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isCredentialProperty(prop.key.name)){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof prop.value.value==="string"){const value=prop.value.value;const keyName=prop.key.name.toLowerCase();if(keyName==="accesskeyid"){if(looksLikeAwsAccessKey(value)){reportHardcodedCredential(prop,clientName,prop.key.name)}}else if(keyName==="secretaccesskey"){if(value.length>=20){reportHardcodedCredential(prop,clientName,prop.key.name)}}else if(keyName==="sessiontoken"){if(value.length>=15){reportHardcodedCredential(prop,clientName,prop.key.name)}}}else if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){reportHardcodedCredential(prop,clientName,prop.key.name)}}}}function reportHardcodedCredential(node,clientName,propertyName){context.report({node,messageId:"hardcodedCredentials",data:{clientName,property:propertyName},suggest:[{messageId:"useCredentialProvider",fix:()=>null}]})}return{NewExpression(node){const clientName=getAwsClientName(node);if(!clientName)return;if(node.arguments.length>0&&node.arguments[0].type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsObject(node.arguments[0],clientName)}},VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.id.name.toLowerCase().includes("credential")&&node.init?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsInner(node.init,"AWSClient")}}}}});
@@ -1,198 +1 @@
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
- const AUTHORIZATION_CHECK_PATTERNS = [
6
- 'requestContext.authorizer',
7
- 'requestContext.identity',
8
- 'Authorization',
9
- 'authorization',
10
- 'claims',
11
- 'principalId',
12
- 'isAdmin',
13
- 'isAuthenticated',
14
- 'userId',
15
- 'sub',
16
- 'scope',
17
- 'permissions',
18
- ];
19
- const SENSITIVE_OPERATIONS = new Set([
20
- 'query',
21
- 'put',
22
- 'delete',
23
- 'update',
24
- 'insert',
25
- 'remove',
26
- 'create',
27
- 'send',
28
- 'invoke',
29
- 'putObject',
30
- 'deleteObject',
31
- 'getObject',
32
- 'putItem',
33
- 'deleteItem',
34
- 'updateItem',
35
- 'getItem',
36
- ]);
37
- const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
38
- exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
39
- name: 'no-missing-authorization-check',
40
- meta: {
41
- type: 'problem',
42
- docs: {
43
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-missing-authorization-check.md',
44
- description: 'Detects Lambda handlers without authorization checks',
45
- cwe: 'CWE-862',
46
- cvss: 7.5,
47
- },
48
- hasSuggestions: true,
49
- messages: {
50
- missingAuthCheck: (0, eslint_devkit_1.formatLLMMessage)({
51
- icon: eslint_devkit_1.MessageIcons.SECURITY,
52
- issueName: 'Missing Authorization Check',
53
- cwe: 'CWE-862',
54
- cvss: 7.5,
55
- description: 'Lambda handler performs {{operation}} operation without authorization check. Users may access resources without proper permissions.',
56
- severity: 'HIGH',
57
- fix: "Add authorization check: const claims = event.requestContext.authorizer?.claims; if (!claims?.sub) { return { statusCode: 401 } }",
58
- documentationLink: 'https://cwe.mitre.org/data/definitions/862.html',
59
- }),
60
- addAuthCheck: (0, eslint_devkit_1.formatLLMMessage)({
61
- icon: eslint_devkit_1.MessageIcons.INFO,
62
- issueName: 'Add Authorization Check',
63
- description: 'Check event.requestContext.authorizer for API Gateway or implement custom JWT validation',
64
- severity: 'LOW',
65
- fix: "const userId = event.requestContext.authorizer?.claims?.sub; if (!userId) throw new Error('Unauthorized');",
66
- documentationLink: 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html',
67
- }),
68
- },
69
- schema: [
70
- {
71
- type: 'object',
72
- properties: {
73
- allowInTests: {
74
- type: 'boolean',
75
- default: true,
76
- description: 'Allow missing auth in test files',
77
- },
78
- handlerPatterns: {
79
- type: 'array',
80
- items: { type: 'string' },
81
- description: 'Handler file patterns to check',
82
- },
83
- },
84
- additionalProperties: false,
85
- },
86
- ],
87
- },
88
- defaultOptions: [
89
- {
90
- allowInTests: true,
91
- handlerPatterns: [],
92
- },
93
- ],
94
- create(context, [options = {}]) {
95
- const { allowInTests = true } = options;
96
- const filename = context.filename;
97
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
98
- if (allowInTests && isTestFile) {
99
- return {};
100
- }
101
- let currentFunctionNode = null;
102
- let hasAuthCheck = false;
103
- let hasEventParameter = false;
104
- const sensitiveOperations = [];
105
- function enterFunction(node) {
106
- const hasEvent = node.params.some((param) => param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
107
- EVENT_PARAM_NAMES.has(param.name));
108
- if (hasEvent) {
109
- currentFunctionNode = node;
110
- hasAuthCheck = false;
111
- hasEventParameter = true;
112
- sensitiveOperations.length = 0;
113
- }
114
- }
115
- function exitFunction(node) {
116
- if (currentFunctionNode !== node)
117
- return;
118
- if (hasEventParameter && !hasAuthCheck) {
119
- for (const { node: opNode, operation } of sensitiveOperations) {
120
- context.report({
121
- node: opNode,
122
- messageId: 'missingAuthCheck',
123
- data: { operation },
124
- suggest: [
125
- {
126
- messageId: 'addAuthCheck',
127
- fix: () => null,
128
- },
129
- ],
130
- });
131
- }
132
- }
133
- currentFunctionNode = null;
134
- hasEventParameter = false;
135
- }
136
- function isAuthorizationAccess(node) {
137
- const sourceCode = context.sourceCode;
138
- const text = sourceCode.getText(node);
139
- return AUTHORIZATION_CHECK_PATTERNS.some((pattern) => text.includes(pattern) ||
140
- text.toLowerCase().includes(pattern.toLowerCase()));
141
- }
142
- function getSensitiveOperationName(node) {
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
- if (SENSITIVE_OPERATIONS.has(property.name)) {
147
- return property.name;
148
- }
149
- }
150
- }
151
- return null;
152
- }
153
- return {
154
- 'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
155
- enterFunction(node);
156
- },
157
- 'ArrowFunctionExpression:exit'(node) {
158
- exitFunction(node);
159
- },
160
- 'FunctionExpression:exit'(node) {
161
- exitFunction(node);
162
- },
163
- 'FunctionDeclaration:exit'(node) {
164
- exitFunction(node);
165
- },
166
- MemberExpression(node) {
167
- if (!currentFunctionNode)
168
- return;
169
- if (isAuthorizationAccess(node)) {
170
- hasAuthCheck = true;
171
- }
172
- },
173
- CallExpression(node) {
174
- if (!currentFunctionNode)
175
- return;
176
- const operation = getSensitiveOperationName(node);
177
- if (operation) {
178
- sensitiveOperations.push({ node, operation });
179
- }
180
- },
181
- ReturnStatement(node) {
182
- if (!currentFunctionNode)
183
- return;
184
- if (node.argument?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
185
- for (const prop of node.argument.properties) {
186
- if (prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
187
- prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
188
- prop.key.name === 'statusCode' &&
189
- prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
190
- (prop.value.value === 401 || prop.value.value === 403)) {
191
- hasAuthCheck = true;
192
- }
193
- }
194
- }
195
- },
196
- };
197
- },
198
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingAuthorizationCheck=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const AUTHORIZATION_CHECK_PATTERNS=["requestContext.authorizer","requestContext.identity","Authorization","authorization","claims","principalId","isAdmin","isAuthenticated","userId","sub","scope","permissions"];const SENSITIVE_OPERATIONS=new Set(["query","put","delete","update","insert","remove","create","send","invoke","putObject","deleteObject","getObject","putItem","deleteItem","updateItem","getItem"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noMissingAuthorizationCheck=(0,eslint_devkit_1.createRule)({name:"no-missing-authorization-check",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-missing-authorization-check.md",description:"Detects Lambda handlers without authorization checks",cwe:"CWE-862",cvss:7.5},hasSuggestions:true,messages:{missingAuthCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing Authorization Check",cwe:"CWE-862",cvss:7.5,description:"Lambda handler performs {{operation}} operation without authorization check. Users may access resources without proper permissions.",severity:"HIGH",fix:"Add authorization check: const claims = event.requestContext.authorizer?.claims; if (!claims?.sub) { return { statusCode: 401 } }",documentationLink:"https://cwe.mitre.org/data/definitions/862.html"}),addAuthCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Authorization Check",description:"Check event.requestContext.authorizer for API Gateway or implement custom JWT validation",severity:"LOW",fix:"const userId = event.requestContext.authorizer?.claims?.sub; if (!userId) throw new Error('Unauthorized');",documentationLink:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow missing auth in test files"},handlerPatterns:{type:"array",items:{type:"string"},description:"Handler file patterns to check"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,handlerPatterns:[]}],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 currentFunctionNode=null;let hasAuthCheck=false;let hasEventParameter=false;const sensitiveOperations=[];function enterFunction(node){const hasEvent=node.params.some(param=>param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&EVENT_PARAM_NAMES.has(param.name));if(hasEvent){currentFunctionNode=node;hasAuthCheck=false;hasEventParameter=true;sensitiveOperations.length=0}}function exitFunction(node){if(currentFunctionNode!==node)return;if(hasEventParameter&&!hasAuthCheck){for(const{node:opNode,operation}of sensitiveOperations){context.report({node:opNode,messageId:"missingAuthCheck",data:{operation},suggest:[{messageId:"addAuthCheck",fix:()=>null}]})}}currentFunctionNode=null;hasEventParameter=false}function isAuthorizationAccess(node){const sourceCode=context.sourceCode;const text=sourceCode.getText(node);return AUTHORIZATION_CHECK_PATTERNS.some(pattern=>text.includes(pattern)||text.toLowerCase().includes(pattern.toLowerCase()))}function getSensitiveOperationName(node){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){if(SENSITIVE_OPERATIONS.has(property.name)){return property.name}}}return 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(!currentFunctionNode)return;if(isAuthorizationAccess(node)){hasAuthCheck=true}},CallExpression(node){if(!currentFunctionNode)return;const operation=getSensitiveOperationName(node);if(operation){sensitiveOperations.push({node,operation})}},ReturnStatement(node){if(!currentFunctionNode)return;if(node.argument?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of node.argument.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&prop.key.name==="statusCode"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&(prop.value.value===401||prop.value.value===403)){hasAuthCheck=true}}}}}}});
@@ -1,125 +1 @@
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
- const POLICY_PROPERTIES = new Set(['Resource', 'Action', 'Principal']);
6
- const DANGEROUS_WILDCARDS = new Set(['*', 'arn:aws:*', 'arn:*:*:*:*:*']);
7
- exports.noOverlyPermissiveIamPolicy = (0, eslint_devkit_1.createRule)({
8
- name: 'no-overly-permissive-iam-policy',
9
- meta: {
10
- type: 'problem',
11
- docs: {
12
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-overly-permissive-iam-policy.md',
13
- description: 'Detects IAM policies with overly broad permissions (wildcards)',
14
- cwe: 'CWE-732',
15
- cvss: 6.5,
16
- },
17
- hasSuggestions: true,
18
- messages: {
19
- permissivePolicy: (0, eslint_devkit_1.formatLLMMessage)({
20
- icon: eslint_devkit_1.MessageIcons.SECURITY,
21
- issueName: 'Overly Permissive IAM Policy',
22
- cwe: 'CWE-732',
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;
55
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
56
- if (allowInTests && isTestFile) {
57
- return {};
58
- }
59
- function isDangerousWildcard(value) {
60
- return (DANGEROUS_WILDCARDS.has(value) ||
61
- (value.endsWith('*') && value.includes(':*:')));
62
- }
63
- function checkPolicyProperty(node, propertyName) {
64
- const value = node.value;
65
- if (value.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof value.value === 'string') {
66
- if (isDangerousWildcard(value.value)) {
67
- context.report({
68
- node,
69
- messageId: 'permissivePolicy',
70
- data: {
71
- property: propertyName,
72
- value: value.value,
73
- },
74
- suggest: [
75
- {
76
- messageId: 'useLeastPrivilege',
77
- fix: () => null,
78
- },
79
- ],
80
- });
81
- }
82
- }
83
- if (value.type === eslint_devkit_1.AST_NODE_TYPES.ArrayExpression) {
84
- for (const element of value.elements) {
85
- if (element?.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
86
- typeof element.value === 'string') {
87
- if (isDangerousWildcard(element.value)) {
88
- context.report({
89
- node: element,
90
- messageId: 'permissivePolicy',
91
- data: {
92
- property: propertyName,
93
- value: element.value,
94
- },
95
- suggest: [
96
- {
97
- messageId: 'useLeastPrivilege',
98
- fix: () => null,
99
- },
100
- ],
101
- });
102
- }
103
- }
104
- }
105
- }
106
- }
107
- return {
108
- Property(node) {
109
- if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
110
- const keyName = node.key.name;
111
- if (POLICY_PROPERTIES.has(keyName)) {
112
- checkPolicyProperty(node, keyName);
113
- }
114
- }
115
- if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
116
- typeof node.key.value === 'string') {
117
- const keyName = node.key.value;
118
- if (POLICY_PROPERTIES.has(keyName)) {
119
- checkPolicyProperty(node, keyName);
120
- }
121
- }
122
- },
123
- };
124
- },
125
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noOverlyPermissiveIamPolicy=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const POLICY_PROPERTIES=new Set(["Resource","Action","Principal"]);const DANGEROUS_WILDCARDS=new Set(["*","arn:aws:*","arn:*:*:*:*:*"]);exports.noOverlyPermissiveIamPolicy=(0,eslint_devkit_1.createRule)({name:"no-overly-permissive-iam-policy",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-overly-permissive-iam-policy.md",description:"Detects IAM policies with overly broad permissions (wildcards)",cwe:"CWE-732",cvss:6.5},hasSuggestions:true,messages:{permissivePolicy:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Overly Permissive IAM Policy",cwe:"CWE-732",cvss:6.5,description:'IAM policy has wildcard {{property}}: "{{value}}". Violates principle of least privilege.',severity:"HIGH",fix:'Restrict {{property}} to specific resources/actions. Example: "arn:aws:s3:::my-bucket/*" instead of "*"',documentationLink:"https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege"}),useLeastPrivilege:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Apply Least Privilege",description:"Restrict permissions to specific resources and actions",severity:"LOW",fix:'Replace "*" with specific ARNs and action names',documentationLink:"https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.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{}}function isDangerousWildcard(value){return DANGEROUS_WILDCARDS.has(value)||value.endsWith("*")&&value.includes(":*:")}function checkPolicyProperty(node,propertyName){const value=node.value;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof value.value==="string"){if(isDangerousWildcard(value.value)){context.report({node,messageId:"permissivePolicy",data:{property:propertyName,value:value.value},suggest:[{messageId:"useLeastPrivilege",fix:()=>null}]})}}if(value.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression){for(const element of value.elements){if(element?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof element.value==="string"){if(isDangerousWildcard(element.value)){context.report({node:element,messageId:"permissivePolicy",data:{property:propertyName,value:element.value},suggest:[{messageId:"useLeastPrivilege",fix:()=>null}]})}}}}}return{Property(node){if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const keyName=node.key.name;if(POLICY_PROPERTIES.has(keyName)){checkPolicyProperty(node,keyName)}}if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.key.value==="string"){const keyName=node.key.value;if(POLICY_PROPERTIES.has(keyName)){checkPolicyProperty(node,keyName)}}}}}});