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