eslint-plugin-lambda-security 1.0.4 → 1.1.1

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.
Files changed (31) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -248
  3. package/package.json +3 -12
  4. package/src/index.d.ts +58 -20
  5. package/src/index.js +70 -3
  6. package/src/rules/no-env-logging/index.d.ts +17 -1
  7. package/src/rules/no-env-logging/index.js +5 -0
  8. package/src/rules/no-error-swallowing/index.d.ts +24 -0
  9. package/src/rules/no-error-swallowing/index.js +197 -0
  10. package/src/rules/no-exposed-error-details/index.d.ts +22 -0
  11. package/src/rules/no-exposed-error-details/index.js +161 -0
  12. package/src/rules/no-hardcoded-credentials-sdk/index.d.ts +18 -1
  13. package/src/rules/no-hardcoded-credentials-sdk/index.js +5 -0
  14. package/src/rules/no-missing-authorization-check/index.d.ts +24 -0
  15. package/src/rules/no-missing-authorization-check/index.js +220 -0
  16. package/src/rules/no-overly-permissive-iam-policy/index.d.ts +22 -0
  17. package/src/rules/no-overly-permissive-iam-policy/index.js +139 -0
  18. package/src/rules/no-permissive-cors-middy/index.d.ts +18 -1
  19. package/src/rules/no-permissive-cors-middy/index.js +5 -0
  20. package/src/rules/no-permissive-cors-response/index.d.ts +18 -1
  21. package/src/rules/no-permissive-cors-response/index.js +5 -0
  22. package/src/rules/no-secrets-in-env/index.d.ts +18 -1
  23. package/src/rules/no-secrets-in-env/index.js +5 -0
  24. package/src/rules/no-unbounded-batch-processing/index.d.ts +24 -0
  25. package/src/rules/no-unbounded-batch-processing/index.js +170 -0
  26. package/src/rules/no-unvalidated-event-body/index.d.ts +24 -0
  27. package/src/rules/no-unvalidated-event-body/index.js +270 -0
  28. package/src/rules/no-user-controlled-requests/index.d.ts +22 -0
  29. package/src/rules/no-user-controlled-requests/index.js +267 -0
  30. package/src/rules/require-timeout-handling/index.d.ts +22 -0
  31. package/src/rules/require-timeout-handling/index.js +171 -0
package/src/index.js CHANGED
@@ -1,23 +1,70 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
2
7
  /**
3
8
  * eslint-plugin-lambda-security
4
9
  * Security-focused ESLint rules for AWS Lambda and Middy applications
5
10
  *
6
11
  * Detects insecure API Gateway responses, missing security headers,
7
- * CORS misconfigurations, input validation issues, and more.
12
+ * CORS misconfigurations, input validation issues, authorization gaps,
13
+ * SSRF vulnerabilities, and more.
14
+ *
15
+ * OWASP Serverless Top 10 Coverage:
16
+ * - SAS-1: Injection ✅ (no-unvalidated-event-body)
17
+ * - SAS-2: Broken Authentication ✅ (no-hardcoded-credentials-sdk)
18
+ * - SAS-3: Sensitive Data Exposure ✅ (no-env-logging, no-secrets-in-env)
19
+ * - SAS-4: Security Misconfiguration ✅ (no-permissive-cors-*)
20
+ * - SAS-5: Broken Access Control ✅ (no-missing-authorization-check, no-overly-permissive-iam-policy)
21
+ * - SAS-6: Insufficient Logging ✅ (no-error-swallowing)
22
+ * - SAS-7: Denial of Service ✅ (require-timeout-handling, no-unbounded-batch-processing)
23
+ * - SAS-8: Server-Side Request Forgery ✅ (no-user-controlled-requests)
24
+ * - SAS-9: Functions Misconfiguration ✅ (no-exposed-error-details)
25
+ * - SAS-10: Improper Crypto ➡️ (Use eslint-plugin-crypto)
8
26
  */
9
- // P0 Critical Rules
27
+ // Original P0 Critical Rules
10
28
  const no_hardcoded_credentials_sdk_1 = require("./rules/no-hardcoded-credentials-sdk");
11
29
  const no_permissive_cors_response_1 = require("./rules/no-permissive-cors-response");
12
30
  const no_permissive_cors_middy_1 = require("./rules/no-permissive-cors-middy");
13
31
  const no_secrets_in_env_1 = require("./rules/no-secrets-in-env");
14
32
  const no_env_logging_1 = require("./rules/no-env-logging");
33
+ // SAS-1: Injection
34
+ const no_unvalidated_event_body_1 = require("./rules/no-unvalidated-event-body");
35
+ // SAS-5: Broken Access Control
36
+ const no_missing_authorization_check_1 = require("./rules/no-missing-authorization-check");
37
+ const no_overly_permissive_iam_policy_1 = require("./rules/no-overly-permissive-iam-policy");
38
+ // SAS-6: Insufficient Logging
39
+ const no_error_swallowing_1 = require("./rules/no-error-swallowing");
40
+ // SAS-7: Denial of Service
41
+ const require_timeout_handling_1 = require("./rules/require-timeout-handling");
42
+ const no_unbounded_batch_processing_1 = require("./rules/no-unbounded-batch-processing");
43
+ // SAS-8: Server-Side Request Forgery
44
+ const no_user_controlled_requests_1 = require("./rules/no-user-controlled-requests");
45
+ // SAS-9: Functions Misconfiguration
46
+ const no_exposed_error_details_1 = require("./rules/no-exposed-error-details");
15
47
  const rules = {
48
+ // Original rules
16
49
  'no-hardcoded-credentials-sdk': no_hardcoded_credentials_sdk_1.noHardcodedCredentialsSdk,
17
50
  'no-permissive-cors-response': no_permissive_cors_response_1.noPermissiveCorsResponse,
18
51
  'no-permissive-cors-middy': no_permissive_cors_middy_1.noPermissiveCorsMidly,
19
52
  'no-secrets-in-env': no_secrets_in_env_1.noSecretsInEnv,
20
53
  'no-env-logging': no_env_logging_1.noEnvLogging,
54
+ // SAS-1: Injection
55
+ 'no-unvalidated-event-body': no_unvalidated_event_body_1.noUnvalidatedEventBody,
56
+ // SAS-5: Broken Access Control
57
+ 'no-missing-authorization-check': no_missing_authorization_check_1.noMissingAuthorizationCheck,
58
+ 'no-overly-permissive-iam-policy': no_overly_permissive_iam_policy_1.noOverlyPermissiveIamPolicy,
59
+ // SAS-6: Insufficient Logging
60
+ 'no-error-swallowing': no_error_swallowing_1.noErrorSwallowing,
61
+ // SAS-7: Denial of Service
62
+ 'require-timeout-handling': require_timeout_handling_1.requireTimeoutHandling,
63
+ 'no-unbounded-batch-processing': no_unbounded_batch_processing_1.noUnboundedBatchProcessing,
64
+ // SAS-8: SSRF
65
+ 'no-user-controlled-requests': no_user_controlled_requests_1.noUserControlledRequests,
66
+ // SAS-9: Functions Misconfiguration
67
+ 'no-exposed-error-details': no_exposed_error_details_1.noExposedErrorDetails,
21
68
  };
22
69
  const configs = {
23
70
  recommended: {
@@ -26,11 +73,22 @@ const configs = {
26
73
  'lambda-security': { rules },
27
74
  },
28
75
  rules: {
76
+ // Critical: Always error
29
77
  'lambda-security/no-hardcoded-credentials-sdk': 'error',
30
78
  'lambda-security/no-permissive-cors-response': 'error',
31
79
  'lambda-security/no-permissive-cors-middy': 'error',
32
80
  'lambda-security/no-secrets-in-env': 'error',
81
+ 'lambda-security/no-user-controlled-requests': 'error',
82
+ 'lambda-security/no-overly-permissive-iam-policy': 'error',
83
+ // High: Warn in recommended
84
+ 'lambda-security/no-unvalidated-event-body': 'warn',
85
+ 'lambda-security/no-missing-authorization-check': 'warn',
86
+ 'lambda-security/no-exposed-error-details': 'warn',
87
+ // Medium: Warn in recommended
33
88
  'lambda-security/no-env-logging': 'warn',
89
+ 'lambda-security/no-error-swallowing': 'warn',
90
+ 'lambda-security/require-timeout-handling': 'warn',
91
+ 'lambda-security/no-unbounded-batch-processing': 'warn',
34
92
  },
35
93
  },
36
94
  strict: {
@@ -39,11 +97,20 @@ const configs = {
39
97
  'lambda-security': { rules },
40
98
  },
41
99
  rules: {
100
+ // All rules as errors in strict mode
42
101
  'lambda-security/no-hardcoded-credentials-sdk': 'error',
43
102
  'lambda-security/no-permissive-cors-response': 'error',
44
103
  'lambda-security/no-permissive-cors-middy': 'error',
45
104
  'lambda-security/no-secrets-in-env': 'error',
46
105
  'lambda-security/no-env-logging': 'error',
106
+ 'lambda-security/no-unvalidated-event-body': 'error',
107
+ 'lambda-security/no-missing-authorization-check': 'error',
108
+ 'lambda-security/no-overly-permissive-iam-policy': 'error',
109
+ 'lambda-security/no-error-swallowing': 'error',
110
+ 'lambda-security/require-timeout-handling': 'error',
111
+ 'lambda-security/no-unbounded-batch-processing': 'error',
112
+ 'lambda-security/no-user-controlled-requests': 'error',
113
+ 'lambda-security/no-exposed-error-details': 'error',
47
114
  },
48
115
  },
49
116
  };
@@ -52,6 +119,6 @@ module.exports = {
52
119
  configs,
53
120
  meta: {
54
121
  name: 'eslint-plugin-lambda-security',
55
- version: '0.0.1',
122
+ version: '1.1.0',
56
123
  },
57
124
  };
@@ -1,5 +1,21 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-env-logging
8
+ * Detects logging of environment variables which may contain secrets
9
+ * CWE-532: Insertion of Sensitive Information into Log File
10
+ *
11
+ * @see https://cwe.mitre.org/data/definitions/532.html
12
+ */
13
+ import type { TSESLint } from '@interlace/eslint-devkit';
14
+ type MessageIds = 'envLogging' | 'removeEnvLogging';
1
15
  export interface Options {
2
16
  /** Allow in test files. Default: true */
3
17
  allowInTests?: boolean;
4
18
  }
5
- export declare const noEnvLogging: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
19
+ type RuleOptions = [Options?];
20
+ export declare const noEnvLogging: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
21
+ export {};
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
8
  exports.noEnvLogging = void 0;
4
9
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-error-swallowing
8
+ * Detects empty catch blocks and missing error logging
9
+ * CWE-390: Detection of Error Condition Without Action
10
+ *
11
+ * @see https://cwe.mitre.org/data/definitions/390.html
12
+ * @see https://owasp.org/www-project-serverless-top-10/
13
+ */
14
+ import type { TSESLint } from '@interlace/eslint-devkit';
15
+ type MessageIds = 'emptyCatchBlock' | 'addErrorLogging';
16
+ export interface Options {
17
+ /** Allow in test files. Default: true */
18
+ allowInTests?: boolean;
19
+ /** Allow comments as documentation of intentional swallowing. Default: true */
20
+ allowWithComment?: boolean;
21
+ }
22
+ type RuleOptions = [Options?];
23
+ export declare const noErrorSwallowing: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
24
+ export {};
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noErrorSwallowing = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
11
+ name: 'no-error-swallowing',
12
+ meta: {
13
+ type: 'problem',
14
+ docs: {
15
+ description: 'Detects empty catch blocks and missing error logging in Lambda handlers',
16
+ },
17
+ hasSuggestions: true,
18
+ messages: {
19
+ emptyCatchBlock: (0, eslint_devkit_1.formatLLMMessage)({
20
+ icon: eslint_devkit_1.MessageIcons.WARNING,
21
+ issueName: 'Error Swallowing',
22
+ cwe: 'CWE-390',
23
+ cvss: 5.0,
24
+ description: 'Catch block swallows error without logging. Security incidents may go undetected.',
25
+ severity: 'MEDIUM',
26
+ fix: 'Log the error with context: console.error("Operation failed", { error, awsRequestId: context.awsRequestId })',
27
+ documentationLink: 'https://cwe.mitre.org/data/definitions/390.html',
28
+ }),
29
+ addErrorLogging: (0, eslint_devkit_1.formatLLMMessage)({
30
+ icon: eslint_devkit_1.MessageIcons.INFO,
31
+ issueName: 'Add Error Logging',
32
+ description: 'Log errors with context for security monitoring',
33
+ severity: 'LOW',
34
+ fix: 'console.error("Error:", error); // or use structured logger',
35
+ documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html',
36
+ }),
37
+ },
38
+ schema: [
39
+ {
40
+ type: 'object',
41
+ properties: {
42
+ allowInTests: {
43
+ type: 'boolean',
44
+ default: true,
45
+ },
46
+ allowWithComment: {
47
+ type: 'boolean',
48
+ default: true,
49
+ },
50
+ },
51
+ additionalProperties: false,
52
+ },
53
+ ],
54
+ },
55
+ defaultOptions: [{ allowInTests: true, allowWithComment: true }],
56
+ create(context, [options = {}]) {
57
+ const { allowInTests = true, allowWithComment = true } = options;
58
+ const filename = context.filename || context.getFilename();
59
+ const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
60
+ if (allowInTests && isTestFile) {
61
+ return {};
62
+ }
63
+ /**
64
+ * Check if a catch block has any logging
65
+ */
66
+ function hasLogging(block) {
67
+ let found = false;
68
+ function checkNode(node) {
69
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
70
+ const callee = node.callee;
71
+ // console.log, console.error, console.warn
72
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
73
+ callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
74
+ callee.object.name === 'console') {
75
+ found = true;
76
+ return;
77
+ }
78
+ // logger.error, logger.warn, etc.
79
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
80
+ callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
81
+ ['logger', 'log', 'winston', 'pino', 'bunyan'].includes(callee.object.name)) {
82
+ found = true;
83
+ return;
84
+ }
85
+ // Direct function call that includes 'log' or 'error'
86
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
87
+ /log|error|warn/i.test(callee.name)) {
88
+ found = true;
89
+ return;
90
+ }
91
+ }
92
+ // Recursively check child nodes
93
+ for (const key of Object.keys(node)) {
94
+ const child = node[key];
95
+ if (child && typeof child === 'object' && 'type' in child) {
96
+ checkNode(child);
97
+ }
98
+ else if (Array.isArray(child)) {
99
+ for (const item of child) {
100
+ // Use Object.prototype.hasOwnProperty to avoid 'in' operator narrowing issues
101
+ if (item !== null &&
102
+ item !== undefined &&
103
+ typeof item === 'object' &&
104
+ Object.prototype.hasOwnProperty.call(item, 'type')) {
105
+ checkNode(item);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ for (const stmt of block.body) {
112
+ checkNode(stmt);
113
+ }
114
+ return found;
115
+ }
116
+ /**
117
+ * Check if block has comments indicating intentional swallowing
118
+ */
119
+ function hasIntentionalComment(node) {
120
+ if (!allowWithComment)
121
+ return false;
122
+ const sourceCode = context.sourceCode || context.getSourceCode();
123
+ const comments = sourceCode.getCommentsInside(node.body);
124
+ return comments.some((comment) => /intentional|expected|ignore|suppress|handled|silent/i.test(comment.value));
125
+ }
126
+ /**
127
+ * Check if catch has throw/rethrow
128
+ */
129
+ function hasThrow(block) {
130
+ return block.body.some((stmt) => stmt.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement);
131
+ }
132
+ /**
133
+ * Check if catch has return (might be valid in some contexts)
134
+ */
135
+ function hasReturn(block) {
136
+ return block.body.some((stmt) => stmt.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
137
+ }
138
+ return {
139
+ CatchClause(node) {
140
+ const body = node.body;
141
+ // Empty catch block
142
+ if (body.body.length === 0) {
143
+ if (!hasIntentionalComment(node)) {
144
+ context.report({
145
+ node,
146
+ messageId: 'emptyCatchBlock',
147
+ suggest: [
148
+ {
149
+ messageId: 'addErrorLogging',
150
+ fix: (fixer) => {
151
+ const errorParam = node.param?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
152
+ ? node.param.name
153
+ : 'error';
154
+ return fixer.replaceText(body, `{ console.error('Error:', ${errorParam}); }`);
155
+ },
156
+ },
157
+ ],
158
+ });
159
+ }
160
+ return;
161
+ }
162
+ // Has throw - OK, error is propagated
163
+ if (hasThrow(body)) {
164
+ return;
165
+ }
166
+ // Check if there's logging
167
+ if (!hasLogging(body)) {
168
+ // If there's a return with error context, that's also OK
169
+ if (hasReturn(body)) {
170
+ // Check if return includes error info
171
+ const returnStmt = body.body.find((s) => s.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
172
+ if (returnStmt?.argument) {
173
+ // Check if return includes status 500 or error body
174
+ const sourceCode = context.sourceCode || context.getSourceCode();
175
+ const returnText = sourceCode.getText(returnStmt.argument);
176
+ if (/500|error|fail/i.test(returnText)) {
177
+ return; // Acceptable error handling
178
+ }
179
+ }
180
+ }
181
+ if (!hasIntentionalComment(node)) {
182
+ context.report({
183
+ node,
184
+ messageId: 'emptyCatchBlock',
185
+ suggest: [
186
+ {
187
+ messageId: 'addErrorLogging',
188
+ fix: () => null,
189
+ },
190
+ ],
191
+ });
192
+ }
193
+ }
194
+ },
195
+ };
196
+ },
197
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-exposed-error-details
8
+ * Detects Lambda handlers exposing internal error details
9
+ * CWE-209: Generation of Error Message Containing Sensitive Information
10
+ *
11
+ * @see https://cwe.mitre.org/data/definitions/209.html
12
+ * @see https://owasp.org/www-project-serverless-top-10/
13
+ */
14
+ import type { TSESLint } from '@interlace/eslint-devkit';
15
+ type MessageIds = 'exposedErrorDetails' | 'sanitizeError';
16
+ export interface Options {
17
+ /** Allow in test files. Default: true */
18
+ allowInTests?: boolean;
19
+ }
20
+ type RuleOptions = [Options?];
21
+ export declare const noExposedErrorDetails: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
22
+ export {};
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noExposedErrorDetails = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ // Properties that expose internal details
11
+ const SENSITIVE_ERROR_PROPERTIES = [
12
+ 'stack',
13
+ 'stackTrace',
14
+ 'trace',
15
+ 'cause',
16
+ '__dirname',
17
+ '__filename',
18
+ 'path',
19
+ 'hostname',
20
+ 'config',
21
+ 'env',
22
+ ];
23
+ exports.noExposedErrorDetails = (0, eslint_devkit_1.createRule)({
24
+ name: 'no-exposed-error-details',
25
+ meta: {
26
+ type: 'problem',
27
+ docs: {
28
+ description: 'Detects Lambda handlers exposing internal error details in responses',
29
+ },
30
+ hasSuggestions: true,
31
+ messages: {
32
+ exposedErrorDetails: (0, eslint_devkit_1.formatLLMMessage)({
33
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
34
+ issueName: 'Exposed Error Details',
35
+ cwe: 'CWE-209',
36
+ cvss: 4.3,
37
+ description: 'Response exposes {{property}} which may leak internal paths, configs, or stack traces.',
38
+ severity: 'MEDIUM',
39
+ fix: 'Return generic error message. Log detailed errors server-side: console.error(error)',
40
+ documentationLink: 'https://cwe.mitre.org/data/definitions/209.html',
41
+ }),
42
+ sanitizeError: (0, eslint_devkit_1.formatLLMMessage)({
43
+ icon: eslint_devkit_1.MessageIcons.INFO,
44
+ issueName: 'Sanitize Error Response',
45
+ description: 'Return a generic error message without internal details',
46
+ severity: 'LOW',
47
+ fix: 'return { statusCode: 500, body: JSON.stringify({ message: "Internal server error" }) }',
48
+ documentationLink: 'https://owasp.org/www-community/Improper_Error_Handling',
49
+ }),
50
+ },
51
+ schema: [
52
+ {
53
+ type: 'object',
54
+ properties: {
55
+ allowInTests: {
56
+ type: 'boolean',
57
+ default: true,
58
+ },
59
+ },
60
+ additionalProperties: false,
61
+ },
62
+ ],
63
+ },
64
+ defaultOptions: [{ allowInTests: true }],
65
+ create(context, [options = {}]) {
66
+ const { allowInTests = true } = options;
67
+ const filename = context.filename || context.getFilename();
68
+ const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
69
+ if (allowInTests && isTestFile) {
70
+ return {};
71
+ }
72
+ // Track if we're inside a return statement that looks like API response
73
+ let insideApiResponse = false;
74
+ /**
75
+ * Check if this return looks like an API Gateway response
76
+ */
77
+ function isApiResponse(node) {
78
+ return node.properties.some((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
79
+ prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
80
+ ['statusCode', 'body', 'headers'].includes(prop.key.name));
81
+ }
82
+ /**
83
+ * Check if member expression accesses sensitive property
84
+ */
85
+ function getSensitiveProperty(node) {
86
+ if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
87
+ if (SENSITIVE_ERROR_PROPERTIES.includes(node.property.name)) {
88
+ return node.property.name;
89
+ }
90
+ }
91
+ return null;
92
+ }
93
+ return {
94
+ ReturnStatement(node) {
95
+ if (node.argument?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression &&
96
+ isApiResponse(node.argument)) {
97
+ insideApiResponse = true;
98
+ }
99
+ },
100
+ 'ReturnStatement:exit'() {
101
+ insideApiResponse = false;
102
+ },
103
+ MemberExpression(node) {
104
+ if (!insideApiResponse)
105
+ return;
106
+ const sensitiveProperty = getSensitiveProperty(node);
107
+ if (sensitiveProperty) {
108
+ // Check if this is in a body property or response
109
+ const parent = node.parent;
110
+ // error.stack in response
111
+ if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.Property ||
112
+ parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
113
+ context.report({
114
+ node,
115
+ messageId: 'exposedErrorDetails',
116
+ data: {
117
+ property: sensitiveProperty,
118
+ },
119
+ suggest: [
120
+ {
121
+ messageId: 'sanitizeError',
122
+ fix: () => null,
123
+ },
124
+ ],
125
+ });
126
+ }
127
+ }
128
+ },
129
+ // JSON.stringify(error) - stringifying entire error object
130
+ CallExpression(node) {
131
+ if (!insideApiResponse)
132
+ return;
133
+ if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
134
+ node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
135
+ node.callee.object.name === 'JSON' &&
136
+ node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
137
+ node.callee.property.name === 'stringify') {
138
+ const arg = node.arguments[0];
139
+ if (arg?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
140
+ // Check if it looks like an error variable
141
+ if (/error|err|e|exception/i.test(arg.name)) {
142
+ context.report({
143
+ node,
144
+ messageId: 'exposedErrorDetails',
145
+ data: {
146
+ property: 'error object',
147
+ },
148
+ suggest: [
149
+ {
150
+ messageId: 'sanitizeError',
151
+ fix: () => null,
152
+ },
153
+ ],
154
+ });
155
+ }
156
+ }
157
+ }
158
+ },
159
+ };
160
+ },
161
+ });
@@ -1,5 +1,22 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-hardcoded-credentials-sdk
8
+ * Detects hardcoded AWS credentials in SDK client configurations
9
+ * CWE-798: Use of Hard-coded Credentials
10
+ *
11
+ * @see https://cwe.mitre.org/data/definitions/798.html
12
+ * @see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-browser-credentials-browser.html
13
+ */
14
+ import type { TSESLint } from '@interlace/eslint-devkit';
15
+ type MessageIds = 'hardcodedCredentials' | 'useCredentialProvider';
1
16
  export interface Options {
2
17
  /** Allow in test files. Default: true */
3
18
  allowInTests?: boolean;
4
19
  }
5
- export declare const noHardcodedCredentialsSdk: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
20
+ type RuleOptions = [Options?];
21
+ export declare const noHardcodedCredentialsSdk: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
22
+ export {};
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
8
  exports.noHardcodedCredentialsSdk = void 0;
4
9
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-missing-authorization-check
8
+ * Detects Lambda handlers without authorization checks
9
+ * CWE-862: Missing Authorization
10
+ *
11
+ * @see https://cwe.mitre.org/data/definitions/862.html
12
+ * @see https://owasp.org/www-project-serverless-top-10/
13
+ */
14
+ import type { TSESLint } from '@interlace/eslint-devkit';
15
+ type MessageIds = 'missingAuthCheck' | 'addAuthCheck';
16
+ export interface Options {
17
+ /** Allow in test files. Default: true */
18
+ allowInTests?: boolean;
19
+ /** Handler file patterns to check. Default: common Lambda patterns */
20
+ handlerPatterns?: string[];
21
+ }
22
+ type RuleOptions = [Options?];
23
+ export declare const noMissingAuthorizationCheck: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
24
+ export {};