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,147 +1 @@
|
|
|
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
|
-
const SENSITIVE_ERROR_PROPERTIES = new Set([
|
|
6
|
-
'stack',
|
|
7
|
-
'stackTrace',
|
|
8
|
-
'trace',
|
|
9
|
-
'cause',
|
|
10
|
-
'__dirname',
|
|
11
|
-
'__filename',
|
|
12
|
-
'path',
|
|
13
|
-
'hostname',
|
|
14
|
-
'config',
|
|
15
|
-
'env',
|
|
16
|
-
]);
|
|
17
|
-
exports.noExposedErrorDetails = (0, eslint_devkit_1.createRule)({
|
|
18
|
-
name: 'no-exposed-error-details',
|
|
19
|
-
meta: {
|
|
20
|
-
type: 'problem',
|
|
21
|
-
docs: {
|
|
22
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-error-details.md',
|
|
23
|
-
description: 'Detects Lambda handlers exposing internal error details in responses',
|
|
24
|
-
cwe: 'CWE-209',
|
|
25
|
-
cvss: 4.3,
|
|
26
|
-
},
|
|
27
|
-
hasSuggestions: true,
|
|
28
|
-
messages: {
|
|
29
|
-
exposedErrorDetails: (0, eslint_devkit_1.formatLLMMessage)({
|
|
30
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
31
|
-
issueName: 'Exposed Error Details',
|
|
32
|
-
cwe: 'CWE-209',
|
|
33
|
-
cvss: 4.3,
|
|
34
|
-
description: 'Response exposes {{property}} which may leak internal paths, configs, or stack traces.',
|
|
35
|
-
severity: 'MEDIUM',
|
|
36
|
-
fix: 'Return generic error message. Log detailed errors server-side: console.error(error)',
|
|
37
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/209.html',
|
|
38
|
-
}),
|
|
39
|
-
sanitizeError: (0, eslint_devkit_1.formatLLMMessage)({
|
|
40
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
41
|
-
issueName: 'Sanitize Error Response',
|
|
42
|
-
description: 'Return a generic error message without internal details',
|
|
43
|
-
severity: 'LOW',
|
|
44
|
-
fix: 'return { statusCode: 500, body: JSON.stringify({ message: "Internal server error" }) }',
|
|
45
|
-
documentationLink: 'https://owasp.org/www-community/Improper_Error_Handling',
|
|
46
|
-
}),
|
|
47
|
-
},
|
|
48
|
-
schema: [
|
|
49
|
-
{
|
|
50
|
-
type: 'object',
|
|
51
|
-
properties: {
|
|
52
|
-
allowInTests: {
|
|
53
|
-
type: 'boolean',
|
|
54
|
-
default: true,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
additionalProperties: false,
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
defaultOptions: [{ allowInTests: true }],
|
|
62
|
-
create(context, [options = {}]) {
|
|
63
|
-
const { allowInTests = true } = options;
|
|
64
|
-
const filename = context.filename;
|
|
65
|
-
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
66
|
-
if (allowInTests && isTestFile) {
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
let insideApiResponse = false;
|
|
70
|
-
function isApiResponse(node) {
|
|
71
|
-
return node.properties.some((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
|
|
72
|
-
prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
73
|
-
['statusCode', 'body', 'headers'].includes(prop.key.name));
|
|
74
|
-
}
|
|
75
|
-
function getSensitiveProperty(node) {
|
|
76
|
-
if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
77
|
-
if (SENSITIVE_ERROR_PROPERTIES.has(node.property.name)) {
|
|
78
|
-
return node.property.name;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
ReturnStatement(node) {
|
|
85
|
-
if (node.argument?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression &&
|
|
86
|
-
isApiResponse(node.argument)) {
|
|
87
|
-
insideApiResponse = true;
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
'ReturnStatement:exit'() {
|
|
91
|
-
insideApiResponse = false;
|
|
92
|
-
},
|
|
93
|
-
MemberExpression(node) {
|
|
94
|
-
if (!insideApiResponse)
|
|
95
|
-
return;
|
|
96
|
-
const sensitiveProperty = getSensitiveProperty(node);
|
|
97
|
-
if (sensitiveProperty) {
|
|
98
|
-
const parent = node.parent;
|
|
99
|
-
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.Property ||
|
|
100
|
-
parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
|
|
101
|
-
context.report({
|
|
102
|
-
node,
|
|
103
|
-
messageId: 'exposedErrorDetails',
|
|
104
|
-
data: {
|
|
105
|
-
property: sensitiveProperty,
|
|
106
|
-
},
|
|
107
|
-
suggest: [
|
|
108
|
-
{
|
|
109
|
-
messageId: 'sanitizeError',
|
|
110
|
-
fix: () => null,
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
CallExpression(node) {
|
|
118
|
-
if (!insideApiResponse)
|
|
119
|
-
return;
|
|
120
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
121
|
-
node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
122
|
-
node.callee.object.name === 'JSON' &&
|
|
123
|
-
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
124
|
-
node.callee.property.name === 'stringify') {
|
|
125
|
-
const arg = node.arguments[0];
|
|
126
|
-
if (arg?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
127
|
-
if (/error|err|e|exception/i.test(arg.name)) {
|
|
128
|
-
context.report({
|
|
129
|
-
node,
|
|
130
|
-
messageId: 'exposedErrorDetails',
|
|
131
|
-
data: {
|
|
132
|
-
property: 'error object',
|
|
133
|
-
},
|
|
134
|
-
suggest: [
|
|
135
|
-
{
|
|
136
|
-
messageId: 'sanitizeError',
|
|
137
|
-
fix: () => null,
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExposedErrorDetails=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const SENSITIVE_ERROR_PROPERTIES=new Set(["stack","stackTrace","trace","cause","__dirname","__filename","path","hostname","config","env"]);exports.noExposedErrorDetails=(0,eslint_devkit_1.createRule)({name:"no-exposed-error-details",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-error-details.md",description:"Detects Lambda handlers exposing internal error details in responses",cwe:"CWE-209",cvss:4.3},hasSuggestions:true,messages:{exposedErrorDetails:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Exposed Error Details",cwe:"CWE-209",cvss:4.3,description:"Response exposes {{property}} which may leak internal paths, configs, or stack traces.",severity:"MEDIUM",fix:"Return generic error message. Log detailed errors server-side: console.error(error)",documentationLink:"https://cwe.mitre.org/data/definitions/209.html"}),sanitizeError:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Sanitize Error Response",description:"Return a generic error message without internal details",severity:"LOW",fix:'return { statusCode: 500, body: JSON.stringify({ message: "Internal server error" }) }',documentationLink:"https://owasp.org/www-community/Improper_Error_Handling"})},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 insideApiResponse=false;function isApiResponse(node){return node.properties.some(prop=>prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["statusCode","body","headers"].includes(prop.key.name))}function getSensitiveProperty(node){if(node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(SENSITIVE_ERROR_PROPERTIES.has(node.property.name)){return node.property.name}}return null}return{ReturnStatement(node){if(node.argument?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression&&isApiResponse(node.argument)){insideApiResponse=true}},"ReturnStatement:exit"(){insideApiResponse=false},MemberExpression(node){if(!insideApiResponse)return;const sensitiveProperty=getSensitiveProperty(node);if(sensitiveProperty){const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.Property||parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){context.report({node,messageId:"exposedErrorDetails",data:{property:sensitiveProperty},suggest:[{messageId:"sanitizeError",fix:()=>null}]})}}},CallExpression(node){if(!insideApiResponse)return;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==="JSON"&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="stringify"){const arg=node.arguments[0];if(arg?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(/error|err|e|exception/i.test(arg.name)){context.report({node,messageId:"exposedErrorDetails",data:{property:"error object"},suggest:[{messageId:"sanitizeError",fix:()=>null}]})}}}}}}});
|
|
@@ -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}}}}}}});
|