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,125 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noPermissiveCorsMidly = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noPermissiveCorsMidly = (0, eslint_devkit_1.createRule)({
6
- name: 'no-permissive-cors-middy',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-middy.md',
11
- description: 'Detects @middy/http-cors middleware with permissive origin (*)',
12
- cwe: 'CWE-942',
13
- cvss: 7.5,
14
- },
15
- hasSuggestions: true,
16
- messages: {
17
- permissiveCors: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.SECURITY,
19
- issueName: 'Permissive CORS in Middy',
20
- cwe: 'CWE-942',
21
- description: 'Wildcard CORS origin in @middy/http-cors allows any domain',
22
- severity: 'HIGH',
23
- fix: 'Use specific origins: httpCors({ origins: ["https://your-domain.com"] })',
24
- documentationLink: 'https://middy.js.org/docs/middlewares/http-cors',
25
- }),
26
- useSpecificOrigins: (0, eslint_devkit_1.formatLLMMessage)({
27
- icon: eslint_devkit_1.MessageIcons.INFO,
28
- issueName: 'Use Specific Origins',
29
- description: 'Configure allowed origins in httpCors middleware',
30
- severity: 'LOW',
31
- fix: 'httpCors({ origins: ["https://allowed-domain.com"] })',
32
- documentationLink: 'https://middy.js.org/docs/middlewares/http-cors',
33
- }),
34
- },
35
- schema: [
36
- {
37
- type: 'object',
38
- properties: {
39
- allowInTests: {
40
- type: 'boolean',
41
- default: true,
42
- },
43
- },
44
- additionalProperties: false,
45
- },
46
- ],
47
- },
48
- defaultOptions: [{ allowInTests: true }],
49
- create(context, [options = {}]) {
50
- const { allowInTests = true } = options;
51
- const filename = context.filename;
52
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
53
- if (allowInTests && isTestFile) {
54
- return {};
55
- }
56
- function isCorsMiddlewareCall(node) {
57
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
58
- const name = node.callee.name.toLowerCase();
59
- return name === 'httpcors' || name === 'cors';
60
- }
61
- return false;
62
- }
63
- function checkCorsOptions(node, optionsObj) {
64
- for (const prop of optionsObj.properties) {
65
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
66
- continue;
67
- if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
68
- const keyName = prop.key.name.toLowerCase();
69
- if (keyName === 'origin' || keyName === 'origins') {
70
- if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal && prop.value.value === '*') {
71
- context.report({
72
- node: prop,
73
- messageId: 'permissiveCors',
74
- suggest: [
75
- {
76
- messageId: 'useSpecificOrigins',
77
- fix: () => null,
78
- },
79
- ],
80
- });
81
- }
82
- else if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.ArrayExpression) {
83
- for (const element of prop.value.elements) {
84
- if (element?.type === eslint_devkit_1.AST_NODE_TYPES.Literal && element.value === '*') {
85
- context.report({
86
- node: element,
87
- messageId: 'permissiveCors',
88
- suggest: [
89
- {
90
- messageId: 'useSpecificOrigins',
91
- fix: () => null,
92
- },
93
- ],
94
- });
95
- }
96
- }
97
- }
98
- }
99
- }
100
- }
101
- }
102
- return {
103
- CallExpression(node) {
104
- if (!isCorsMiddlewareCall(node))
105
- return;
106
- if (node.arguments.length === 0) {
107
- context.report({
108
- node,
109
- messageId: 'permissiveCors',
110
- suggest: [
111
- {
112
- messageId: 'useSpecificOrigins',
113
- fix: () => null,
114
- },
115
- ],
116
- });
117
- return;
118
- }
119
- if (node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
120
- checkCorsOptions(node, node.arguments[0]);
121
- }
122
- },
123
- };
124
- },
125
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCorsMidly=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noPermissiveCorsMidly=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors-middy",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-middy.md",description:"Detects @middy/http-cors middleware with permissive origin (*)",cwe:"CWE-942",cvss:7.5},hasSuggestions:true,messages:{permissiveCors:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Permissive CORS in Middy",cwe:"CWE-942",description:"Wildcard CORS origin in @middy/http-cors allows any domain",severity:"HIGH",fix:'Use specific origins: httpCors({ origins: ["https://your-domain.com"] })',documentationLink:"https://middy.js.org/docs/middlewares/http-cors"}),useSpecificOrigins:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Specific Origins",description:"Configure allowed origins in httpCors middleware",severity:"LOW",fix:'httpCors({ origins: ["https://allowed-domain.com"] })',documentationLink:"https://middy.js.org/docs/middlewares/http-cors"})},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 isCorsMiddlewareCall(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const name=node.callee.name.toLowerCase();return name==="httpcors"||name==="cors"}return false}function checkCorsOptions(node,optionsObj){for(const prop of optionsObj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const keyName=prop.key.name.toLowerCase();if(keyName==="origin"||keyName==="origins"){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&prop.value.value==="*"){context.report({node:prop,messageId:"permissiveCors",suggest:[{messageId:"useSpecificOrigins",fix:()=>null}]})}else if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression){for(const element of prop.value.elements){if(element?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&element.value==="*"){context.report({node:element,messageId:"permissiveCors",suggest:[{messageId:"useSpecificOrigins",fix:()=>null}]})}}}}}}}return{CallExpression(node){if(!isCorsMiddlewareCall(node))return;if(node.arguments.length===0){context.report({node,messageId:"permissiveCors",suggest:[{messageId:"useSpecificOrigins",fix:()=>null}]});return}if(node.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCorsOptions(node,node.arguments[0])}}}}});
@@ -1,119 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noPermissiveCorsResponse = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noPermissiveCorsResponse = (0, eslint_devkit_1.createRule)({
6
- name: 'no-permissive-cors-response',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-response.md',
11
- description: 'Detects permissive CORS (Access-Control-Allow-Origin: *) in Lambda response headers',
12
- cwe: 'CWE-942',
13
- cvss: 7.5,
14
- },
15
- fixable: 'code',
16
- messages: {
17
- permissiveCors: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.SECURITY,
19
- issueName: 'Permissive CORS in Lambda Response',
20
- cwe: 'CWE-942',
21
- description: 'Wildcard CORS origin (*) allows any domain to access this Lambda function',
22
- severity: 'HIGH',
23
- fix: 'Use specific origins: headers: { "Access-Control-Allow-Origin": "https://your-domain.com" }',
24
- documentationLink: 'https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html',
25
- }),
26
- useSpecificOrigin: (0, eslint_devkit_1.formatLLMMessage)({
27
- icon: eslint_devkit_1.MessageIcons.INFO,
28
- issueName: 'Use Specific Origin',
29
- description: 'Specify allowed origins instead of wildcard',
30
- severity: 'LOW',
31
- fix: 'Replace "*" with specific domain(s)',
32
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS',
33
- }),
34
- },
35
- schema: [
36
- {
37
- type: 'object',
38
- properties: {
39
- allowInTests: {
40
- type: 'boolean',
41
- default: true,
42
- description: 'Allow permissive CORS in test files',
43
- },
44
- },
45
- additionalProperties: false,
46
- },
47
- ],
48
- },
49
- defaultOptions: [{ allowInTests: true }],
50
- create(context, [options = {}]) {
51
- const { allowInTests = true } = options;
52
- const filename = context.filename;
53
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
54
- if (allowInTests && isTestFile) {
55
- return {};
56
- }
57
- function isLambdaResponse(obj) {
58
- const propNames = obj.properties
59
- .filter((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Property)
60
- .map(p => (p.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier ? p.key.name : ''));
61
- return propNames.includes('statusCode') || propNames.includes('body');
62
- }
63
- function checkHeadersObject(obj) {
64
- for (const prop of obj.properties) {
65
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
66
- continue;
67
- let headerName = '';
68
- if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
69
- headerName = prop.key.name;
70
- }
71
- else if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof prop.key.value === 'string') {
72
- headerName = prop.key.value;
73
- }
74
- if (headerName.toLowerCase() === 'access-control-allow-origin') {
75
- if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal && prop.value.value === '*') {
76
- context.report({
77
- node: prop,
78
- messageId: 'permissiveCors',
79
- fix: (fixer) => {
80
- return fixer.replaceText(prop.value, '"https://your-domain.com"');
81
- },
82
- });
83
- }
84
- }
85
- }
86
- }
87
- function checkResponseObject(obj) {
88
- if (!isLambdaResponse(obj))
89
- return;
90
- for (const prop of obj.properties) {
91
- if (prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
92
- prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
93
- prop.key.name === 'headers' &&
94
- prop.value.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
95
- checkHeadersObject(prop.value);
96
- }
97
- }
98
- }
99
- return {
100
- ReturnStatement(node) {
101
- if (node.argument?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
102
- checkResponseObject(node.argument);
103
- }
104
- },
105
- ArrowFunctionExpression(node) {
106
- if (node.body.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
107
- checkResponseObject(node.body);
108
- }
109
- },
110
- VariableDeclarator(node) {
111
- if (node.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
112
- node.id.name.toLowerCase().includes('response') &&
113
- node.init?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
114
- checkResponseObject(node.init);
115
- }
116
- },
117
- };
118
- },
119
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCorsResponse=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noPermissiveCorsResponse=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors-response",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-response.md",description:"Detects permissive CORS (Access-Control-Allow-Origin: *) in Lambda response headers",cwe:"CWE-942",cvss:7.5},fixable:"code",messages:{permissiveCors:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Permissive CORS in Lambda Response",cwe:"CWE-942",description:"Wildcard CORS origin (*) allows any domain to access this Lambda function",severity:"HIGH",fix:'Use specific origins: headers: { "Access-Control-Allow-Origin": "https://your-domain.com" }',documentationLink:"https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html"}),useSpecificOrigin:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Specific Origin",description:"Specify allowed origins instead of wildcard",severity:"LOW",fix:'Replace "*" with specific domain(s)',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow permissive CORS 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 isLambdaResponse(obj){const propNames=obj.properties.filter(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property).map(p=>p.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?p.key.name:"");return propNames.includes("statusCode")||propNames.includes("body")}function checkHeadersObject(obj){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;let headerName="";if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){headerName=prop.key.name}else if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof prop.key.value==="string"){headerName=prop.key.value}if(headerName.toLowerCase()==="access-control-allow-origin"){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&prop.value.value==="*"){context.report({node:prop,messageId:"permissiveCors",fix:fixer=>{return fixer.replaceText(prop.value,'"https://your-domain.com"')}})}}}}function checkResponseObject(obj){if(!isLambdaResponse(obj))return;for(const prop of obj.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&prop.key.name==="headers"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkHeadersObject(prop.value)}}}return{ReturnStatement(node){if(node.argument?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkResponseObject(node.argument)}},ArrowFunctionExpression(node){if(node.body.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkResponseObject(node.body)}},VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.id.name.toLowerCase().includes("response")&&node.init?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkResponseObject(node.init)}}}}});
@@ -1,143 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSecretsInEnv = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const SECRET_PATTERNS = [
6
- /password/i,
7
- /secret/i,
8
- /api[_-]?key/i,
9
- /api[_-]?token/i,
10
- /auth[_-]?token/i,
11
- /access[_-]?token/i,
12
- /private[_-]?key/i,
13
- /encryption[_-]?key/i,
14
- /db[_-]?pass/i,
15
- /database[_-]?password/i,
16
- /jwt[_-]?secret/i,
17
- /signing[_-]?key/i,
18
- /client[_-]?secret/i,
19
- /aws[_-]?secret/i,
20
- ];
21
- exports.noSecretsInEnv = (0, eslint_devkit_1.createRule)({
22
- name: 'no-secrets-in-env',
23
- meta: {
24
- type: 'problem',
25
- docs: {
26
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-secrets-in-env.md',
27
- description: 'Detects secrets directly assigned to environment variables',
28
- cwe: 'CWE-798',
29
- cvss: 9.8,
30
- },
31
- hasSuggestions: true,
32
- messages: {
33
- secretsInEnv: (0, eslint_devkit_1.formatLLMMessage)({
34
- icon: eslint_devkit_1.MessageIcons.SECURITY,
35
- issueName: 'Secret in Environment Variable',
36
- cwe: 'CWE-798',
37
- description: 'Secret "{{varName}}" should not be hardcoded in environment variables',
38
- severity: 'CRITICAL',
39
- fix: 'Use AWS Secrets Manager: const secret = await secretsClient.send(new GetSecretValueCommand({ SecretId: "{{varName}}" }))',
40
- documentationLink: 'https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html',
41
- }),
42
- useSecretsManager: (0, eslint_devkit_1.formatLLMMessage)({
43
- icon: eslint_devkit_1.MessageIcons.INFO,
44
- issueName: 'Use Secrets Manager',
45
- description: 'Store secrets in AWS Secrets Manager instead of env vars',
46
- severity: 'LOW',
47
- fix: 'import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager"',
48
- documentationLink: 'https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html',
49
- }),
50
- },
51
- schema: [
52
- {
53
- type: 'object',
54
- properties: {
55
- allowInTests: { type: 'boolean', default: true },
56
- additionalPatterns: { type: 'array', items: { type: 'string' }, default: [], description: 'Extra environment-variable name patterns to treat as secrets' },
57
- },
58
- additionalProperties: false,
59
- },
60
- ],
61
- },
62
- defaultOptions: [{ allowInTests: true, additionalPatterns: [] }],
63
- create(context, [options = {}]) {
64
- const { allowInTests = true, additionalPatterns = [] } = options;
65
- const filename = context.filename;
66
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
67
- if (allowInTests && isTestFile) {
68
- return {};
69
- }
70
- const allPatterns = [
71
- ...SECRET_PATTERNS,
72
- ...additionalPatterns.map(p => new RegExp(p, 'i')),
73
- ];
74
- function isSecretName(name) {
75
- return allPatterns.some(pattern => pattern.test(name));
76
- }
77
- function isHardcodedSecretValue(node) {
78
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.value === 'string') {
79
- return node.value.length > 5;
80
- }
81
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
82
- return node.quasis.some(quasi => quasi.value.raw.length > 5);
83
- }
84
- return false;
85
- }
86
- return {
87
- AssignmentExpression(node) {
88
- if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
89
- node.left.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
90
- node.left.object.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
91
- node.left.object.object.name === 'process' &&
92
- node.left.object.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
93
- node.left.object.property.name === 'env') {
94
- let envVarName = '';
95
- if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
96
- envVarName = node.left.property.name;
97
- }
98
- else if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.left.property.value === 'string') {
99
- envVarName = node.left.property.value;
100
- }
101
- if (isSecretName(envVarName) && isHardcodedSecretValue(node.right)) {
102
- context.report({
103
- node,
104
- messageId: 'secretsInEnv',
105
- data: { varName: envVarName },
106
- suggest: [{ messageId: 'useSecretsManager', fix: () => null }],
107
- });
108
- }
109
- }
110
- },
111
- Property(node) {
112
- let propName = '';
113
- if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
114
- propName = node.key.name;
115
- }
116
- else if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.key.value === 'string') {
117
- propName = node.key.value;
118
- }
119
- if (isSecretName(propName) && isHardcodedSecretValue(node.value)) {
120
- let parent = node.parent;
121
- while (parent) {
122
- if (parent.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
123
- parent = parent.parent;
124
- continue;
125
- }
126
- if (parent.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator &&
127
- parent.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
128
- /env|config|settings/i.test(parent.id.name)) {
129
- context.report({
130
- node,
131
- messageId: 'secretsInEnv',
132
- data: { varName: propName },
133
- suggest: [{ messageId: 'useSecretsManager', fix: () => null }],
134
- });
135
- break;
136
- }
137
- break;
138
- }
139
- }
140
- },
141
- };
142
- },
143
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSecretsInEnv=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const SECRET_PATTERNS=[/password/i,/secret/i,/api[_-]?key/i,/api[_-]?token/i,/auth[_-]?token/i,/access[_-]?token/i,/private[_-]?key/i,/encryption[_-]?key/i,/db[_-]?pass/i,/database[_-]?password/i,/jwt[_-]?secret/i,/signing[_-]?key/i,/client[_-]?secret/i,/aws[_-]?secret/i];exports.noSecretsInEnv=(0,eslint_devkit_1.createRule)({name:"no-secrets-in-env",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-secrets-in-env.md",description:"Detects secrets directly assigned to environment variables",cwe:"CWE-798",cvss:9.8},hasSuggestions:true,messages:{secretsInEnv:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Secret in Environment Variable",cwe:"CWE-798",description:'Secret "{{varName}}" should not be hardcoded in environment variables',severity:"CRITICAL",fix:'Use AWS Secrets Manager: const secret = await secretsClient.send(new GetSecretValueCommand({ SecretId: "{{varName}}" }))',documentationLink:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"}),useSecretsManager:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Secrets Manager",description:"Store secrets in AWS Secrets Manager instead of env vars",severity:"LOW",fix:'import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager"',documentationLink:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},additionalPatterns:{type:"array",items:{type:"string"},default:[],description:"Extra environment-variable name patterns to treat as secrets"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,additionalPatterns:[]}],create(context,[options={}]){const{allowInTests=true,additionalPatterns=[]}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}const allPatterns=[...SECRET_PATTERNS,...additionalPatterns.map(p=>new RegExp(p,"i"))];function isSecretName(name){return allPatterns.some(pattern=>pattern.test(name))}function isHardcodedSecretValue(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.value==="string"){return node.value.length>5}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.some(quasi=>quasi.value.raw.length>5)}return false}return{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.object.object.name==="process"&&node.left.object.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.object.property.name==="env"){let envVarName="";if(node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){envVarName=node.left.property.name}else if(node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.left.property.value==="string"){envVarName=node.left.property.value}if(isSecretName(envVarName)&&isHardcodedSecretValue(node.right)){context.report({node,messageId:"secretsInEnv",data:{varName:envVarName},suggest:[{messageId:"useSecretsManager",fix:()=>null}]})}}},Property(node){let propName="";if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){propName=node.key.name}else if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.key.value==="string"){propName=node.key.value}if(isSecretName(propName)&&isHardcodedSecretValue(node.value)){let parent=node.parent;while(parent){if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){parent=parent.parent;continue}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/env|config|settings/i.test(parent.id.name)){context.report({node,messageId:"secretsInEnv",data:{varName:propName},suggest:[{messageId:"useSecretsManager",fix:()=>null}]});break}break}}}}}});
@@ -1,168 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noUnboundedBatchProcessing = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const BATCH_SOURCE_PROPERTIES = new Set([
6
- 'Records',
7
- 'records',
8
- 'items',
9
- 'messages',
10
- ]);
11
- const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
12
- exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
13
- name: 'no-unbounded-batch-processing',
14
- meta: {
15
- type: 'problem',
16
- docs: {
17
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unbounded-batch-processing.md',
18
- description: 'Detects processing batch records without size validation',
19
- cwe: 'CWE-770',
20
- cvss: 5.5,
21
- },
22
- hasSuggestions: true,
23
- messages: {
24
- unboundedBatch: (0, eslint_devkit_1.formatLLMMessage)({
25
- icon: eslint_devkit_1.MessageIcons.WARNING,
26
- issueName: 'Unbounded Batch Processing',
27
- cwe: 'CWE-770',
28
- cvss: 5.5,
29
- description: 'Processing {{source}} without size check. Large batches may cause timeout or memory exhaustion.',
30
- severity: 'MEDIUM',
31
- fix: 'Validate batch size before processing: if (event.Records.length > MAX_BATCH) throw new Error("Batch too large")',
32
- documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html',
33
- }),
34
- addBatchLimit: (0, eslint_devkit_1.formatLLMMessage)({
35
- icon: eslint_devkit_1.MessageIcons.INFO,
36
- issueName: 'Add Batch Size Limit',
37
- description: 'Add a maximum batch size check before processing',
38
- severity: 'LOW',
39
- fix: 'const MAX_BATCH_SIZE = 10; const records = event.Records.slice(0, MAX_BATCH_SIZE);',
40
- documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html',
41
- }),
42
- },
43
- schema: [
44
- {
45
- type: 'object',
46
- properties: {
47
- allowInTests: {
48
- type: 'boolean',
49
- default: true,
50
- },
51
- maxBatchSize: {
52
- type: 'number',
53
- default: 100, description: 'Batch size above which processing must be explicitly bounded'
54
- },
55
- },
56
- additionalProperties: false,
57
- },
58
- ],
59
- },
60
- defaultOptions: [{ allowInTests: true, maxBatchSize: 100 }],
61
- create(context, [options = {}]) {
62
- const { allowInTests = true } = options;
63
- const filename = context.filename;
64
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
65
- if (allowInTests && isTestFile) {
66
- return {};
67
- }
68
- let currentHandlerNode = null;
69
- let hasBatchSizeCheck = false;
70
- const batchAccessNodes = [];
71
- const eventParamName = [];
72
- function enterFunction(node) {
73
- const hasEvent = node.params.some((p) => {
74
- if (p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
75
- EVENT_PARAM_NAMES.has(p.name)) {
76
- eventParamName.push(p.name);
77
- return true;
78
- }
79
- return false;
80
- });
81
- if (hasEvent) {
82
- currentHandlerNode = node;
83
- hasBatchSizeCheck = false;
84
- batchAccessNodes.length = 0;
85
- }
86
- }
87
- function exitFunction(node) {
88
- if (currentHandlerNode !== node)
89
- return;
90
- if (!hasBatchSizeCheck) {
91
- for (const { node: batchNode, source } of batchAccessNodes) {
92
- context.report({
93
- node: batchNode,
94
- messageId: 'unboundedBatch',
95
- data: { source },
96
- suggest: [
97
- {
98
- messageId: 'addBatchLimit',
99
- fix: () => null,
100
- },
101
- ],
102
- });
103
- }
104
- }
105
- currentHandlerNode = null;
106
- eventParamName.length = 0;
107
- }
108
- return {
109
- 'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
110
- enterFunction(node);
111
- },
112
- 'ArrowFunctionExpression:exit'(node) {
113
- exitFunction(node);
114
- },
115
- 'FunctionExpression:exit'(node) {
116
- exitFunction(node);
117
- },
118
- 'FunctionDeclaration:exit'(node) {
119
- exitFunction(node);
120
- },
121
- MemberExpression(node) {
122
- if (!currentHandlerNode)
123
- return;
124
- if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
125
- eventParamName.includes(node.object.name) &&
126
- node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
127
- BATCH_SOURCE_PROPERTIES.has(node.property.name)) {
128
- batchAccessNodes.push({
129
- node,
130
- source: `${node.object.name}.${node.property.name}`,
131
- });
132
- }
133
- if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
134
- node.property.name === 'length') {
135
- if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
136
- node.object.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
137
- BATCH_SOURCE_PROPERTIES.has(node.object.property.name)) {
138
- hasBatchSizeCheck = true;
139
- }
140
- }
141
- },
142
- CallExpression(node) {
143
- if (!currentHandlerNode)
144
- return;
145
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
146
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
147
- ['slice', 'splice', 'take', 'chunk'].includes(node.callee.property.name)) {
148
- hasBatchSizeCheck = true;
149
- }
150
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
151
- ['slice', 'splice', 'take', 'chunk'].includes(node.callee.name)) {
152
- hasBatchSizeCheck = true;
153
- }
154
- },
155
- BinaryExpression(node) {
156
- if (!currentHandlerNode)
157
- return;
158
- if (['<', '<=', '>', '>='].includes(node.operator)) {
159
- const sourceCode = context.sourceCode;
160
- const text = sourceCode.getText(node);
161
- if (/\.length|Records|records/.test(text)) {
162
- hasBatchSizeCheck = true;
163
- }
164
- }
165
- },
166
- };
167
- },
168
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnboundedBatchProcessing=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const BATCH_SOURCE_PROPERTIES=new Set(["Records","records","items","messages"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noUnboundedBatchProcessing=(0,eslint_devkit_1.createRule)({name:"no-unbounded-batch-processing",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unbounded-batch-processing.md",description:"Detects processing batch records without size validation",cwe:"CWE-770",cvss:5.5},hasSuggestions:true,messages:{unboundedBatch:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Unbounded Batch Processing",cwe:"CWE-770",cvss:5.5,description:"Processing {{source}} without size check. Large batches may cause timeout or memory exhaustion.",severity:"MEDIUM",fix:'Validate batch size before processing: if (event.Records.length > MAX_BATCH) throw new Error("Batch too large")',documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"}),addBatchLimit:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Batch Size Limit",description:"Add a maximum batch size check before processing",severity:"LOW",fix:"const MAX_BATCH_SIZE = 10; const records = event.Records.slice(0, MAX_BATCH_SIZE);",documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},maxBatchSize:{type:"number",default:100,description:"Batch size above which processing must be explicitly bounded"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,maxBatchSize:100}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}let currentHandlerNode=null;let hasBatchSizeCheck=false;const batchAccessNodes=[];const eventParamName=[];function enterFunction(node){const hasEvent=node.params.some(p=>{if(p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&EVENT_PARAM_NAMES.has(p.name)){eventParamName.push(p.name);return true}return false});if(hasEvent){currentHandlerNode=node;hasBatchSizeCheck=false;batchAccessNodes.length=0}}function exitFunction(node){if(currentHandlerNode!==node)return;if(!hasBatchSizeCheck){for(const{node:batchNode,source}of batchAccessNodes){context.report({node:batchNode,messageId:"unboundedBatch",data:{source},suggest:[{messageId:"addBatchLimit",fix:()=>null}]})}}currentHandlerNode=null;eventParamName.length=0}return{"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentHandlerNode)return;if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamName.includes(node.object.name)&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&BATCH_SOURCE_PROPERTIES.has(node.property.name)){batchAccessNodes.push({node,source:`${node.object.name}.${node.property.name}`})}if(node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.property.name==="length"){if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&BATCH_SOURCE_PROPERTIES.has(node.object.property.name)){hasBatchSizeCheck=true}}},CallExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["slice","splice","take","chunk"].includes(node.callee.property.name)){hasBatchSizeCheck=true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["slice","splice","take","chunk"].includes(node.callee.name)){hasBatchSizeCheck=true}},BinaryExpression(node){if(!currentHandlerNode)return;if(["<","<=",">",">="].includes(node.operator)){const sourceCode=context.sourceCode;const text=sourceCode.getText(node);if(/\.length|Records|records/.test(text)){hasBatchSizeCheck=true}}}}}});