eslint-plugin-lambda-security 1.3.2 → 1.3.4
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/README.md +1 -1
- package/package.json +3 -3
- 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/README.md
CHANGED
|
@@ -104,7 +104,7 @@ All rules accept these common options:
|
|
|
104
104
|
## 📦 Compatibility
|
|
105
105
|
| Package | Version |
|
|
106
106
|
| :--- | :--- |
|
|
107
|
-
| ESLint | `^8.
|
|
107
|
+
| ESLint | `^8.40.0 \|\| ^9.0.0 \|\| ^10.0.0` |
|
|
108
108
|
| Node.js | `>=18.0.0` |
|
|
109
109
|
|
|
110
110
|
See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) — current ecosystem share data, the 20% gate, and the forward-looking exception that covers v10.
|
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.4",
|
|
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,10 +71,10 @@
|
|
|
71
71
|
"node": ">=18.0.0"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@interlace/eslint-devkit": "^1.
|
|
74
|
+
"@interlace/eslint-devkit": "^1.11.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"eslint": "^8.
|
|
77
|
+
"eslint": "^8.40.0 || ^9.0.0 || ^10.0.0",
|
|
78
78
|
"@aws-sdk/client-lambda": "^3.0.0",
|
|
79
79
|
"@middy/core": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
80
80
|
"@middy/http-cors": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.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.4"},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{}}const LOGGER_OBJECTS=/^(console|logger|log|winston|pino|bunyan|sentry|Sentry)$/;const LOGGER_METHODS=/^(log|error|warn|info|debug|captureException|captureMessage)$/;const LOGGING_FUNCTIONS=/^(log|report|capture|track|record|notify)\w*$/i;const FORWARDING_CALLBACKS=/^(next|reject|callback|cb|done|fail|emit)$/;const RESPONSE_OBJECTS=/^(res|response|reply|ctx)$/;const RESPONSE_METHODS=/^(status|sendStatus|json|send|end|writeHead|render|redirect)$/;function mentions(nodes,name){const stack=[...nodes];while(stack.length>0){const node=stack.pop();if(!node||typeof node.type!=="string")continue;if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.name===name)return true;for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value))stack.push(...value);else if(value&&typeof value==="object")stack.push(value)}}return false}function rootName(node){let current=node;while(current.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression)current=current.object;return current.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?current.name:void 0}function memberNames(node){const names=[];let current=node;while(current.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){if(current.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){names.unshift(current.property.name)}current=current.object}return names}function classifyCall(call,caughtName){const callee=call.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(FORWARDING_CALLBACKS.test(callee.name)){return caughtName!==void 0&&mentions(call.arguments,caughtName)?"forward":void 0}if(LOGGING_FUNCTIONS.test(callee.name))return"log";return void 0}if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return void 0;const names=memberNames(callee);const method=names.at(-1)??"";if(names.length>1&&LOGGER_OBJECTS.test(names.at(-2)??"")&&LOGGER_METHODS.test(method)){return"log"}const root=rootName(callee);if(root===void 0)return void 0;if(LOGGER_OBJECTS.test(root)&&LOGGER_METHODS.test(method))return"log";if(RESPONSE_OBJECTS.test(root)&&names.some(n=>RESPONSE_METHODS.test(n))){return"respond"}return void 0}function analyze(block,caughtName){const result={logs:false,forwards:false,responds:false};const seen=new Set;const visit=node=>{if(!node||typeof node.type!=="string"||seen.has(node))return;seen.add(node);if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const kind=classifyCall(node,caughtName);if(kind==="log")result.logs=true;else if(kind==="forward")result.forwards=true;else if(kind==="respond")result.responds=true}for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value)){for(const item of value)visit(item)}else if(value&&typeof value==="object"){visit(value)}}};visit(block);return result}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 returnsFallback(block){return block.body.some(stmt=>{if(stmt.type!==eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)return false;const value=stmt.argument;if(value===null)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&value.value===null)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&value.name==="undefined"){return false}if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&value.value===true)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const status=value.properties.find(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property&&p.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/^(statusCode|status|ok|allowed|authorized)$/.test(p.key.name));if(status){const literal=status.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal?status.value.value:void 0;if(literal===true)return false;const code=Number(literal);if(code>=200&&code<300)return false}}return true})}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}const caughtName=node.param?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.param.name:void 0;const{logs,forwards,responds}=analyze(body,caughtName);if(logs||forwards||responds||returnsFallback(body)){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)}}}}}});
|