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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-lambda-security",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "ESLint plugin for AWS Lambda security — detects overly permissive IAM policies and CORS, unvalidated event bodies, secrets in env vars, and leaked error details.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -71,8 +71,7 @@
71
71
  "node": ">=18.0.0"
72
72
  },
73
73
  "dependencies": {
74
- "tslib": "^2.3.0",
75
- "@interlace/eslint-devkit": "^1.7.0"
74
+ "@interlace/eslint-devkit": "^1.10.0"
76
75
  },
77
76
  "peerDependencies": {
78
77
  "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
package/src/index.js CHANGED
@@ -1,85 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configs = exports.plugin = exports.rules = void 0;
4
- const no_hardcoded_credentials_sdk_1 = require("./rules/no-hardcoded-credentials-sdk");
5
- const no_permissive_cors_response_1 = require("./rules/no-permissive-cors-response");
6
- const no_permissive_cors_middy_1 = require("./rules/no-permissive-cors-middy");
7
- const no_secrets_in_env_1 = require("./rules/no-secrets-in-env");
8
- const no_env_logging_1 = require("./rules/no-env-logging");
9
- const no_unvalidated_event_body_1 = require("./rules/no-unvalidated-event-body");
10
- const no_missing_authorization_check_1 = require("./rules/no-missing-authorization-check");
11
- const no_overly_permissive_iam_policy_1 = require("./rules/no-overly-permissive-iam-policy");
12
- const no_error_swallowing_1 = require("./rules/no-error-swallowing");
13
- const require_timeout_handling_1 = require("./rules/require-timeout-handling");
14
- const no_unbounded_batch_processing_1 = require("./rules/no-unbounded-batch-processing");
15
- const no_user_controlled_requests_1 = require("./rules/no-user-controlled-requests");
16
- const no_exposed_error_details_1 = require("./rules/no-exposed-error-details");
17
- const no_exposed_debug_endpoints_1 = require("./rules/no-exposed-debug-endpoints");
18
- exports.rules = {
19
- 'no-hardcoded-credentials-sdk': no_hardcoded_credentials_sdk_1.noHardcodedCredentialsSdk,
20
- 'no-permissive-cors-response': no_permissive_cors_response_1.noPermissiveCorsResponse,
21
- 'no-permissive-cors-middy': no_permissive_cors_middy_1.noPermissiveCorsMidly,
22
- 'no-secrets-in-env': no_secrets_in_env_1.noSecretsInEnv,
23
- 'no-env-logging': no_env_logging_1.noEnvLogging,
24
- 'no-unvalidated-event-body': no_unvalidated_event_body_1.noUnvalidatedEventBody,
25
- 'no-missing-authorization-check': no_missing_authorization_check_1.noMissingAuthorizationCheck,
26
- 'no-overly-permissive-iam-policy': no_overly_permissive_iam_policy_1.noOverlyPermissiveIamPolicy,
27
- 'no-error-swallowing': no_error_swallowing_1.noErrorSwallowing,
28
- 'require-timeout-handling': require_timeout_handling_1.requireTimeoutHandling,
29
- 'no-unbounded-batch-processing': no_unbounded_batch_processing_1.noUnboundedBatchProcessing,
30
- 'no-user-controlled-requests': no_user_controlled_requests_1.noUserControlledRequests,
31
- 'no-exposed-error-details': no_exposed_error_details_1.noExposedErrorDetails,
32
- 'no-exposed-debug-endpoints': no_exposed_debug_endpoints_1.noExposedDebugEndpoints,
33
- };
34
- exports.plugin = {
35
- meta: {
36
- name: 'eslint-plugin-lambda-security',
37
- version: '1.3.1',
38
- },
39
- rules: exports.rules,
40
- };
41
- exports.configs = {
42
- recommended: {
43
- plugins: {
44
- 'lambda-security': exports.plugin,
45
- },
46
- rules: {
47
- 'lambda-security/no-hardcoded-credentials-sdk': 'error',
48
- 'lambda-security/no-permissive-cors-response': 'error',
49
- 'lambda-security/no-permissive-cors-middy': 'error',
50
- 'lambda-security/no-secrets-in-env': 'error',
51
- 'lambda-security/no-user-controlled-requests': 'error',
52
- 'lambda-security/no-overly-permissive-iam-policy': 'error',
53
- 'lambda-security/no-unvalidated-event-body': 'warn',
54
- 'lambda-security/no-missing-authorization-check': 'warn',
55
- 'lambda-security/no-exposed-error-details': 'warn',
56
- 'lambda-security/no-exposed-debug-endpoints': 'error',
57
- 'lambda-security/no-env-logging': 'warn',
58
- 'lambda-security/no-error-swallowing': 'warn',
59
- 'lambda-security/require-timeout-handling': 'warn',
60
- 'lambda-security/no-unbounded-batch-processing': 'warn',
61
- },
62
- },
63
- strict: {
64
- plugins: {
65
- 'lambda-security': exports.plugin,
66
- },
67
- rules: {
68
- 'lambda-security/no-hardcoded-credentials-sdk': 'error',
69
- 'lambda-security/no-permissive-cors-response': 'error',
70
- 'lambda-security/no-permissive-cors-middy': 'error',
71
- 'lambda-security/no-secrets-in-env': 'error',
72
- 'lambda-security/no-env-logging': 'error',
73
- 'lambda-security/no-unvalidated-event-body': 'error',
74
- 'lambda-security/no-missing-authorization-check': 'error',
75
- 'lambda-security/no-overly-permissive-iam-policy': 'error',
76
- 'lambda-security/no-error-swallowing': 'error',
77
- 'lambda-security/require-timeout-handling': 'error',
78
- 'lambda-security/no-unbounded-batch-processing': 'error',
79
- 'lambda-security/no-user-controlled-requests': 'error',
80
- 'lambda-security/no-exposed-error-details': 'error',
81
- 'lambda-security/no-exposed-debug-endpoints': 'error',
82
- },
83
- },
84
- };
85
- exports.default = exports.plugin;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;exports.rules={get"no-hardcoded-credentials-sdk"(){return require("./rules/no-hardcoded-credentials-sdk").noHardcodedCredentialsSdk},get"no-permissive-cors-response"(){return require("./rules/no-permissive-cors-response").noPermissiveCorsResponse},get"no-permissive-cors-middy"(){return require("./rules/no-permissive-cors-middy").noPermissiveCorsMidly},get"no-secrets-in-env"(){return require("./rules/no-secrets-in-env").noSecretsInEnv},get"no-env-logging"(){return require("./rules/no-env-logging").noEnvLogging},get"no-unvalidated-event-body"(){return require("./rules/no-unvalidated-event-body").noUnvalidatedEventBody},get"no-missing-authorization-check"(){return require("./rules/no-missing-authorization-check").noMissingAuthorizationCheck},get"no-overly-permissive-iam-policy"(){return require("./rules/no-overly-permissive-iam-policy").noOverlyPermissiveIamPolicy},get"no-error-swallowing"(){return require("./rules/no-error-swallowing").noErrorSwallowing},get"require-timeout-handling"(){return require("./rules/require-timeout-handling").requireTimeoutHandling},get"no-unbounded-batch-processing"(){return require("./rules/no-unbounded-batch-processing").noUnboundedBatchProcessing},get"no-user-controlled-requests"(){return require("./rules/no-user-controlled-requests").noUserControlledRequests},get"no-exposed-error-details"(){return require("./rules/no-exposed-error-details").noExposedErrorDetails},get"no-exposed-debug-endpoints"(){return require("./rules/no-exposed-debug-endpoints").noExposedDebugEndpoints}};exports.plugin={meta:{name:"eslint-plugin-lambda-security",version:"1.3.3"},rules:exports.rules};exports.configs={recommended:{plugins:{"lambda-security":exports.plugin},rules:{"lambda-security/no-hardcoded-credentials-sdk":"error","lambda-security/no-permissive-cors-response":"error","lambda-security/no-permissive-cors-middy":"error","lambda-security/no-secrets-in-env":"error","lambda-security/no-user-controlled-requests":"error","lambda-security/no-overly-permissive-iam-policy":"error","lambda-security/no-unvalidated-event-body":"warn","lambda-security/no-missing-authorization-check":"warn","lambda-security/no-exposed-error-details":"warn","lambda-security/no-exposed-debug-endpoints":"error","lambda-security/no-env-logging":"warn","lambda-security/no-error-swallowing":"warn","lambda-security/require-timeout-handling":"warn","lambda-security/no-unbounded-batch-processing":"warn"}},strict:{plugins:{"lambda-security":exports.plugin},rules:{"lambda-security/no-hardcoded-credentials-sdk":"error","lambda-security/no-permissive-cors-response":"error","lambda-security/no-permissive-cors-middy":"error","lambda-security/no-secrets-in-env":"error","lambda-security/no-env-logging":"error","lambda-security/no-unvalidated-event-body":"error","lambda-security/no-missing-authorization-check":"error","lambda-security/no-overly-permissive-iam-policy":"error","lambda-security/no-error-swallowing":"error","lambda-security/require-timeout-handling":"error","lambda-security/no-unbounded-batch-processing":"error","lambda-security/no-user-controlled-requests":"error","lambda-security/no-exposed-error-details":"error","lambda-security/no-exposed-debug-endpoints":"error"}}};exports.default=exports.plugin;
package/src/oxlint.js CHANGED
@@ -1,3 +1 @@
1
- "use strict";
2
- const index_1 = require("./index");
3
- module.exports = index_1.plugin;
1
+ "use strict";const index_1=require("./index");module.exports=index_1.plugin;
@@ -1,113 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noEnvLogging = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const LOGGING_FUNCTIONS = new Set(['log', 'info', 'warn', 'error', 'debug', 'trace']);
6
- exports.noEnvLogging = (0, eslint_devkit_1.createRule)({
7
- name: 'no-env-logging',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-env-logging.md',
12
- description: 'Detects logging of process.env which may expose secrets',
13
- cwe: 'CWE-532',
14
- cvss: 5.3,
15
- },
16
- hasSuggestions: true,
17
- messages: {
18
- envLogging: (0, eslint_devkit_1.formatLLMMessage)({
19
- icon: eslint_devkit_1.MessageIcons.SECURITY,
20
- issueName: 'Environment Variable Logging',
21
- cwe: 'CWE-532',
22
- description: 'Logging process.env may expose secrets (API keys, passwords, tokens)',
23
- severity: 'HIGH',
24
- fix: 'Remove process.env from log statements or log specific non-sensitive values',
25
- documentationLink: 'https://cwe.mitre.org/data/definitions/532.html',
26
- }),
27
- removeEnvLogging: (0, eslint_devkit_1.formatLLMMessage)({
28
- icon: eslint_devkit_1.MessageIcons.INFO,
29
- issueName: 'Remove Env Logging',
30
- description: 'Remove environment variable logging',
31
- severity: 'LOW',
32
- fix: 'Log specific values instead: console.log("Region:", process.env.AWS_REGION)',
33
- documentationLink: 'https://cwe.mitre.org/data/definitions/532.html',
34
- }),
35
- },
36
- schema: [
37
- {
38
- type: 'object',
39
- properties: {
40
- allowInTests: { type: 'boolean', default: true },
41
- },
42
- additionalProperties: false,
43
- },
44
- ],
45
- },
46
- defaultOptions: [{ allowInTests: true }],
47
- create(context, [options = {}]) {
48
- const { allowInTests = true } = options;
49
- const filename = context.filename;
50
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
51
- if (allowInTests && isTestFile) {
52
- return {};
53
- }
54
- const sourceCode = context.sourceCode;
55
- function isProcessEnv(node) {
56
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
57
- node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
58
- node.object.name === 'process' &&
59
- node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
60
- node.property.name === 'env') {
61
- return true;
62
- }
63
- return false;
64
- }
65
- function containsProcessEnv(node) {
66
- const text = sourceCode.getText(node);
67
- return text.includes('process.env');
68
- }
69
- function isLoggingCall(node) {
70
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
71
- const obj = node.callee.object;
72
- const prop = node.callee.property;
73
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
74
- return false;
75
- const methodName = prop.name;
76
- if (!LOGGING_FUNCTIONS.has(methodName))
77
- return false;
78
- if (obj.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && obj.name === 'console') {
79
- return true;
80
- }
81
- if (obj.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && /log(ger)?/i.test(obj.name)) {
82
- return true;
83
- }
84
- }
85
- return false;
86
- }
87
- return {
88
- CallExpression(node) {
89
- if (!isLoggingCall(node))
90
- return;
91
- for (const arg of node.arguments) {
92
- if (isProcessEnv(arg)) {
93
- context.report({
94
- node: arg,
95
- messageId: 'envLogging',
96
- suggest: [{ messageId: 'removeEnvLogging', fix: () => null }],
97
- });
98
- }
99
- else if (containsProcessEnv(arg)) {
100
- const text = sourceCode.getText(arg);
101
- if (/process\.env\s*[,)\]]/.test(text) || /JSON\.stringify\s*\(\s*process\.env\s*\)/.test(text)) {
102
- context.report({
103
- node: arg,
104
- messageId: 'envLogging',
105
- suggest: [{ messageId: 'removeEnvLogging', fix: () => null }],
106
- });
107
- }
108
- }
109
- }
110
- },
111
- };
112
- },
113
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noEnvLogging=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const LOGGING_FUNCTIONS=new Set(["log","info","warn","error","debug","trace"]);exports.noEnvLogging=(0,eslint_devkit_1.createRule)({name:"no-env-logging",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-env-logging.md",description:"Detects logging of process.env which may expose secrets",cwe:"CWE-532",cvss:5.3},hasSuggestions:true,messages:{envLogging:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Environment Variable Logging",cwe:"CWE-532",description:"Logging process.env may expose secrets (API keys, passwords, tokens)",severity:"HIGH",fix:"Remove process.env from log statements or log specific non-sensitive values",documentationLink:"https://cwe.mitre.org/data/definitions/532.html"}),removeEnvLogging:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Remove Env Logging",description:"Remove environment variable logging",severity:"LOW",fix:'Log specific values instead: console.log("Region:", process.env.AWS_REGION)',documentationLink:"https://cwe.mitre.org/data/definitions/532.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{}}const sourceCode=context.sourceCode;function isProcessEnv(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.object.name==="process"&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.property.name==="env"){return true}return false}function containsProcessEnv(node){const text=sourceCode.getText(node);return text.includes("process.env")}function isLoggingCall(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const obj=node.callee.object;const prop=node.callee.property;if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const methodName=prop.name;if(!LOGGING_FUNCTIONS.has(methodName))return false;if(obj.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&obj.name==="console"){return true}if(obj.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/log(ger)?/i.test(obj.name)){return true}}return false}return{CallExpression(node){if(!isLoggingCall(node))return;for(const arg of node.arguments){if(isProcessEnv(arg)){context.report({node:arg,messageId:"envLogging",suggest:[{messageId:"removeEnvLogging",fix:()=>null}]})}else if(containsProcessEnv(arg)){const text=sourceCode.getText(arg);if(/process\.env\s*[,)\]]/.test(text)||/JSON\.stringify\s*\(\s*process\.env\s*\)/.test(text)){context.report({node:arg,messageId:"envLogging",suggest:[{messageId:"removeEnvLogging",fix:()=>null}]})}}}}}}});
@@ -1,135 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noErrorSwallowing = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
6
- name: 'no-error-swallowing',
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-error-swallowing.md',
11
- description: 'Detects empty catch blocks and missing error logging in Lambda handlers',
12
- cwe: 'CWE-390',
13
- cvss: 5,
14
- },
15
- hasSuggestions: true,
16
- messages: {
17
- emptyCatchBlock: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.WARNING,
19
- issueName: 'Error Swallowing',
20
- cwe: 'CWE-390',
21
- cvss: 5.0,
22
- description: 'Catch block swallows error without logging. Security incidents may go undetected.',
23
- severity: 'MEDIUM',
24
- fix: 'Log the error with context: console.error("Operation failed", { error, awsRequestId: context.awsRequestId })',
25
- documentationLink: 'https://cwe.mitre.org/data/definitions/390.html',
26
- }),
27
- addErrorLogging: (0, eslint_devkit_1.formatLLMMessage)({
28
- icon: eslint_devkit_1.MessageIcons.INFO,
29
- issueName: 'Add Error Logging',
30
- description: 'Log errors with context for security monitoring',
31
- severity: 'LOW',
32
- fix: 'console.error("Error:", error); // or use structured logger',
33
- documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html',
34
- }),
35
- },
36
- schema: [
37
- {
38
- type: 'object',
39
- properties: {
40
- allowInTests: {
41
- type: 'boolean',
42
- default: true,
43
- },
44
- allowWithComment: {
45
- type: 'boolean',
46
- default: true,
47
- },
48
- },
49
- additionalProperties: false,
50
- },
51
- ],
52
- },
53
- defaultOptions: [{ allowInTests: true, allowWithComment: true }],
54
- create(context, [options = {}]) {
55
- const { allowInTests = true, allowWithComment = true } = options;
56
- const filename = context.filename;
57
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
58
- if (allowInTests && isTestFile) {
59
- return {};
60
- }
61
- function hasLogging(block) {
62
- const sourceCode = context.sourceCode;
63
- const blockText = sourceCode.getText(block);
64
- if (/console\.\s*(log|error|warn|info|debug)\s*\(/.test(blockText)) {
65
- return true;
66
- }
67
- if (/(logger|log|winston|pino|bunyan)\.\s*(error|warn|info|debug|log)\s*\(/.test(blockText)) {
68
- return true;
69
- }
70
- if (/\b(log|error|warn)\w*\s*\(/.test(blockText)) {
71
- return true;
72
- }
73
- return false;
74
- }
75
- function hasIntentionalComment(node) {
76
- if (!allowWithComment)
77
- return false;
78
- const sourceCode = context.sourceCode;
79
- const comments = sourceCode.getCommentsInside(node.body);
80
- return comments.some((comment) => /intentional|expected|ignore|suppress|handled|silent/i.test(comment.value));
81
- }
82
- function hasThrow(block) {
83
- return block.body.some((stmt) => stmt.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement);
84
- }
85
- function hasReturn(block) {
86
- return block.body.some((stmt) => stmt.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
87
- }
88
- return {
89
- CatchClause(node) {
90
- const body = node.body;
91
- if (body.body.length === 0) {
92
- if (!hasIntentionalComment(node)) {
93
- context.report({
94
- node,
95
- messageId: 'emptyCatchBlock',
96
- suggest: [
97
- {
98
- messageId: 'addErrorLogging',
99
- fix: (fixer) => {
100
- const errorParam = node.param?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
101
- ? node.param.name
102
- : 'error';
103
- return fixer.replaceText(body, `{ console.error('Error:', ${errorParam}); }`);
104
- },
105
- },
106
- ],
107
- });
108
- }
109
- return;
110
- }
111
- if (hasThrow(body)) {
112
- return;
113
- }
114
- if (!hasLogging(body)) {
115
- if (hasReturn(body)) {
116
- const returnStmt = body.body.find((s) => s.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
117
- if (returnStmt?.argument) {
118
- const sourceCode = context.sourceCode;
119
- const returnText = sourceCode.getText(returnStmt.argument);
120
- if (/500|error|fail/i.test(returnText)) {
121
- return;
122
- }
123
- }
124
- }
125
- if (!hasIntentionalComment(node)) {
126
- context.report({
127
- node,
128
- messageId: 'emptyCatchBlock',
129
- });
130
- }
131
- }
132
- },
133
- };
134
- },
135
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noErrorSwallowing=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noErrorSwallowing=(0,eslint_devkit_1.createRule)({name:"no-error-swallowing",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-error-swallowing.md",description:"Detects empty catch blocks and missing error logging in Lambda handlers",cwe:"CWE-390",cvss:5},hasSuggestions:true,messages:{emptyCatchBlock:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Error Swallowing",cwe:"CWE-390",cvss:5,description:"Catch block swallows error without logging. Security incidents may go undetected.",severity:"MEDIUM",fix:'Log the error with context: console.error("Operation failed", { error, awsRequestId: context.awsRequestId })',documentationLink:"https://cwe.mitre.org/data/definitions/390.html"}),addErrorLogging:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Error Logging",description:"Log errors with context for security monitoring",severity:"LOW",fix:'console.error("Error:", error); // or use structured logger',documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},allowWithComment:{type:"boolean",default:true,description:"Allow an empty catch block that carries an explanatory comment"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,allowWithComment:true}],create(context,[options={}]){const{allowInTests=true,allowWithComment=true}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}function hasLogging(block){const sourceCode=context.sourceCode;const blockText=sourceCode.getText(block);if(/console\.\s*(log|error|warn|info|debug)\s*\(/.test(blockText)){return true}if(/(logger|log|winston|pino|bunyan)\.\s*(error|warn|info|debug|log)\s*\(/.test(blockText)){return true}if(/\b(log|error|warn)\w*\s*\(/.test(blockText)){return true}return false}function hasIntentionalComment(node){if(!allowWithComment)return false;const sourceCode=context.sourceCode;const comments=sourceCode.getCommentsInside(node.body);return comments.some(comment=>/intentional|expected|ignore|suppress|handled|silent/i.test(comment.value))}function hasThrow(block){return block.body.some(stmt=>stmt.type===eslint_devkit_1.AST_NODE_TYPES.ThrowStatement)}function hasReturn(block){return block.body.some(stmt=>stmt.type===eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)}return{CatchClause(node){const body=node.body;if(body.body.length===0){if(!hasIntentionalComment(node)){context.report({node,messageId:"emptyCatchBlock",suggest:[{messageId:"addErrorLogging",fix:fixer=>{const errorParam=node.param?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.param.name:"error";return fixer.replaceText(body,`{ console.error('Error:', ${errorParam}); }`)}}]})}return}if(hasThrow(body)){return}if(!hasLogging(body)){if(hasReturn(body)){const returnStmt=body.body.find(s=>s.type===eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);if(returnStmt?.argument){const sourceCode=context.sourceCode;const returnText=sourceCode.getText(returnStmt.argument);if(/500|error|fail/i.test(returnText)){return}}}if(!hasIntentionalComment(node)){context.report({node,messageId:"emptyCatchBlock"})}}}}}});
@@ -1,120 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noExposedDebugEndpoints = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const DEFAULT_DEBUG_PATHS = ['/debug', '/__debug__', '/admin', '/_admin', '/test', '/health'];
6
- exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
7
- name: 'no-exposed-debug-endpoints',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-debug-endpoints.md',
12
- description: 'Detect debug endpoints without auth in AWS Lambda handlers',
13
- cwe: 'CWE-489',
14
- cvss: 7.5,
15
- },
16
- messages: {
17
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.SECURITY,
19
- issueName: 'Exposed Debug Endpoint',
20
- cwe: 'CWE-489',
21
- description: 'Debug endpoint exposed without authentication',
22
- severity: 'HIGH',
23
- fix: 'Remove debug endpoints from production or add authentication',
24
- documentationLink: 'https://cwe.mitre.org/data/definitions/489.html',
25
- })
26
- },
27
- schema: [
28
- {
29
- type: 'object',
30
- properties: {
31
- endpoints: {
32
- type: 'array',
33
- items: { type: 'string' },
34
- description: 'Custom list of debug/admin endpoints to flag'
35
- },
36
- ignoreFiles: {
37
- type: 'array',
38
- items: { type: 'string' },
39
- description: 'List of files or patterns to ignore'
40
- }
41
- },
42
- additionalProperties: false
43
- }
44
- ],
45
- },
46
- defaultOptions: [{}],
47
- create(context) {
48
- const options = context.options[0] || {};
49
- const debugPaths = options.endpoints || DEFAULT_DEBUG_PATHS;
50
- const ignoreFiles = options.ignoreFiles || [];
51
- const filename = context.filename;
52
- if (ignoreFiles.some(pattern => filename.includes(pattern))) {
53
- return {};
54
- }
55
- function report(node) {
56
- context.report({ node, messageId: 'violationDetected' });
57
- }
58
- return {
59
- Property(node) {
60
- if (node.key.type === 'Identifier' && node.key.name === 'path' &&
61
- node.value.type === 'Literal' && typeof node.value.value === 'string') {
62
- const path = node.value.value.toLowerCase();
63
- if (debugPaths.some(dp => path.includes(dp.toLowerCase()))) {
64
- let parent = node.parent;
65
- while (parent) {
66
- if (parent.type === 'Property' && parent.key.type === 'Identifier' &&
67
- ['http', 'httpApi'].includes(parent.key.name)) {
68
- report(node.value);
69
- return;
70
- }
71
- parent = parent.parent;
72
- }
73
- }
74
- }
75
- },
76
- BinaryExpression(node) {
77
- if (node.operator === '===' || node.operator === '==' || node.operator === '!==' || node.operator === '!=') {
78
- const checkNode = (side) => {
79
- if (side.type === 'Literal' && typeof side.value === 'string') {
80
- const val = side.value.toLowerCase();
81
- if (debugPaths.some(dp => val.includes(dp.toLowerCase()))) {
82
- const other = side === node.left ? node.right : node.left;
83
- if (other.type === 'MemberExpression' &&
84
- other.object.type === 'Identifier' &&
85
- (other.object.name === 'event' || other.object.name === 'evt') &&
86
- other.property.type === 'Identifier' &&
87
- ['path', 'rawPath', 'resource', 'routeKey'].includes(other.property.name)) {
88
- report(side);
89
- }
90
- }
91
- }
92
- };
93
- checkNode(node.left);
94
- checkNode(node.right);
95
- }
96
- },
97
- Literal(node) {
98
- if (typeof node.value === 'string') {
99
- const path = node.value.toLowerCase();
100
- if (debugPaths.some(dp => path === dp.toLowerCase())) {
101
- const parent = node.parent;
102
- if (parent && parent.type === 'BinaryExpression' &&
103
- (parent.left === node || parent.right === node)) {
104
- const other = parent.left === node ? parent.right : parent.left;
105
- if (other.type === 'MemberExpression' &&
106
- other.object.type === 'Identifier' &&
107
- (other.object.name === 'event' || other.object.name === 'evt')) {
108
- return;
109
- }
110
- }
111
- if (parent && parent.type === 'Property' && parent.key.type === 'Identifier' && parent.key.name === 'path') {
112
- return;
113
- }
114
- report(node);
115
- }
116
- }
117
- },
118
- };
119
- },
120
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExposedDebugEndpoints=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DEFAULT_DEBUG_PATHS=["/debug","/__debug__","/admin","/_admin","/test","/health"];exports.noExposedDebugEndpoints=(0,eslint_devkit_1.createRule)({name:"no-exposed-debug-endpoints",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-debug-endpoints.md",description:"Detect debug endpoints without auth in AWS Lambda handlers",cwe:"CWE-489",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Exposed Debug Endpoint",cwe:"CWE-489",description:"Debug endpoint exposed without authentication",severity:"HIGH",fix:"Remove debug endpoints from production or add authentication",documentationLink:"https://cwe.mitre.org/data/definitions/489.html"})},schema:[{type:"object",properties:{endpoints:{type:"array",items:{type:"string"},description:"Custom list of debug/admin endpoints to flag"},ignoreFiles:{type:"array",items:{type:"string"},description:"List of files or patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{}],create(context){const options=context.options[0]||{};const debugPaths=options.endpoints||DEFAULT_DEBUG_PATHS;const ignoreFiles=options.ignoreFiles||[];const filename=context.filename;if(ignoreFiles.some(pattern=>filename.includes(pattern))){return{}}function report(node){context.report({node,messageId:"violationDetected"})}return{Property(node){if(node.key.type==="Identifier"&&node.key.name==="path"&&node.value.type==="Literal"&&typeof node.value.value==="string"){const path=node.value.value.toLowerCase();if(debugPaths.some(dp=>path.includes(dp.toLowerCase()))){let parent=node.parent;while(parent){if(parent.type==="Property"&&parent.key.type==="Identifier"&&["http","httpApi"].includes(parent.key.name)){report(node.value);return}parent=parent.parent}}}},BinaryExpression(node){if(node.operator==="==="||node.operator==="=="||node.operator==="!=="||node.operator==="!="){const checkNode=side=>{if(side.type==="Literal"&&typeof side.value==="string"){const val=side.value.toLowerCase();if(debugPaths.some(dp=>val.includes(dp.toLowerCase()))){const other=side===node.left?node.right:node.left;if(other.type==="MemberExpression"&&other.object.type==="Identifier"&&(other.object.name==="event"||other.object.name==="evt")&&other.property.type==="Identifier"&&["path","rawPath","resource","routeKey"].includes(other.property.name)){report(side)}}}};checkNode(node.left);checkNode(node.right)}},Literal(node){if(typeof node.value==="string"){const path=node.value.toLowerCase();if(debugPaths.some(dp=>path===dp.toLowerCase())){const parent=node.parent;if(parent&&parent.type==="BinaryExpression"&&(parent.left===node||parent.right===node)){const other=parent.left===node?parent.right:parent.left;if(other.type==="MemberExpression"&&other.object.type==="Identifier"&&(other.object.name==="event"||other.object.name==="evt")){return}}if(parent&&parent.type==="Property"&&parent.key.type==="Identifier"&&parent.key.name==="path"){return}report(node)}}}}}});