eslint-plugin-lambda-security 1.0.2 → 1.0.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/LICENSE +21 -0
- package/README.md +38 -17
- package/package.json +4 -13
- package/src/index.d.ts +54 -1
- package/src/index.js +65 -3
- package/src/rules/no-error-swallowing/index.d.ts +7 -0
- package/src/rules/no-error-swallowing/index.js +188 -0
- package/src/rules/no-exposed-error-details/index.d.ts +5 -0
- package/src/rules/no-exposed-error-details/index.js +157 -0
- package/src/rules/no-missing-authorization-check/index.d.ts +7 -0
- package/src/rules/no-missing-authorization-check/index.js +216 -0
- package/src/rules/no-overly-permissive-iam-policy/index.d.ts +5 -0
- package/src/rules/no-overly-permissive-iam-policy/index.js +135 -0
- package/src/rules/no-unbounded-batch-processing/index.d.ts +7 -0
- package/src/rules/no-unbounded-batch-processing/index.js +166 -0
- package/src/rules/no-unvalidated-event-body/index.d.ts +7 -0
- package/src/rules/no-unvalidated-event-body/index.js +266 -0
- package/src/rules/no-user-controlled-requests/index.d.ts +5 -0
- package/src/rules/no-user-controlled-requests/index.js +263 -0
- package/src/rules/require-timeout-handling/index.d.ts +5 -0
- package/src/rules/require-timeout-handling/index.js +167 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/eslint-plugin-lambda-security)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
[](https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=lambda_security)
|
|
9
|
+
[](https://github.com/ofri-peretz/eslint)
|
|
9
10
|
|
|
10
11
|
> **Serverless-first security:** This plugin provides security rules for **AWS Lambda**, **Middy.js**, **Serverless Framework**, **AWS SAM**, and **AWS SDK v3**.
|
|
11
12
|
> With **5 security rules** mapped to OWASP Serverless Top 10, CWE and CVSS, it transforms your linter into a serverless security auditor that AI assistants can understand and fix.
|
|
@@ -44,20 +45,20 @@ src/handlers/api.ts
|
|
|
44
45
|
|
|
45
46
|
| OWASP Category | Coverage | Rules |
|
|
46
47
|
| -------------------------------------- | :------: | -------------------------------------------------------------------------------- |
|
|
47
|
-
| **SAS-1: Injection** |
|
|
48
|
+
| **SAS-1: Injection** | ✅ | `no-unvalidated-event-body` |
|
|
48
49
|
| **SAS-2: Broken Authentication** | ✅ | `no-hardcoded-credentials-sdk` |
|
|
49
50
|
| **SAS-3: Sensitive Data Exposure** | ✅ | `no-env-logging`, `no-secrets-in-env` |
|
|
50
51
|
| **SAS-4: Security Misconfiguration** | ✅ | `no-permissive-cors-*` |
|
|
51
|
-
| **SAS-5: Broken Access Control** |
|
|
52
|
-
| **SAS-6: Insufficient Logging** |
|
|
53
|
-
| **SAS-7: Denial of Service** |
|
|
54
|
-
| **SAS-8: Server-Side Request Forgery** |
|
|
55
|
-
| **SAS-9: Functions Misconfiguration** |
|
|
56
|
-
| **SAS-10: Improper Crypto** |
|
|
52
|
+
| **SAS-5: Broken Access Control** | ✅ | `no-missing-authorization-check`, `no-overly-permissive-iam-policy` |
|
|
53
|
+
| **SAS-6: Insufficient Logging** | ✅ | `no-error-swallowing` |
|
|
54
|
+
| **SAS-7: Denial of Service** | ✅ | `require-timeout-handling`, `no-unbounded-batch-processing` |
|
|
55
|
+
| **SAS-8: Server-Side Request Forgery** | ✅ | `no-user-controlled-requests` |
|
|
56
|
+
| **SAS-9: Functions Misconfiguration** | ✅ | `no-exposed-error-details` |
|
|
57
|
+
| **SAS-10: Improper Crypto** | ➡️ | Use [`eslint-plugin-crypto`](https://www.npmjs.com/package/eslint-plugin-crypto) |
|
|
57
58
|
|
|
58
59
|
---
|
|
59
60
|
|
|
60
|
-
## 🔐
|
|
61
|
+
## 🔐 13 Security Rules
|
|
61
62
|
|
|
62
63
|
💼 = Set in `recommended` | ⚠️ = Warns in `recommended` | 🔧 = Auto-fixable | 💡 = Suggestions
|
|
63
64
|
|
|
@@ -76,6 +77,24 @@ src/handlers/api.ts
|
|
|
76
77
|
| [no-permissive-cors-response](#no-permissive-cors-response) | CWE-942 | SAS-4 | 9.1 | Wildcard CORS in Lambda response headers | 💼 | | 🔧 | |
|
|
77
78
|
| [no-permissive-cors-middy](#no-permissive-cors-middy) | CWE-942 | SAS-4 | 9.1 | Permissive CORS in @middy/http-cors middleware | 💼 | | | |
|
|
78
79
|
|
|
80
|
+
### Input Validation & Access Control (4 rules)
|
|
81
|
+
|
|
82
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
83
|
+
| ------------------------------- | ------- | ----- | ---- | --------------------------------------------------- | --- | --- | --- | --- |
|
|
84
|
+
| no-unvalidated-event-body | CWE-20 | SAS-1 | 8.0 | Lambda handlers using event body without validation | | ⚠️ | | 💡 |
|
|
85
|
+
| no-missing-authorization-check | CWE-862 | SAS-5 | 7.5 | Lambda handlers without authorization checks | | ⚠️ | | 💡 |
|
|
86
|
+
| no-overly-permissive-iam-policy | CWE-732 | SAS-5 | 6.5 | IAM policies with wildcard permissions | 💼 | | | 💡 |
|
|
87
|
+
| no-user-controlled-requests | CWE-918 | SAS-8 | 9.1 | HTTP requests with user-controlled URLs (SSRF) | 💼 | | | 💡 |
|
|
88
|
+
|
|
89
|
+
### Security Operations (4 rules)
|
|
90
|
+
|
|
91
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
92
|
+
| ----------------------------- | ------- | ----- | ---- | -------------------------------------------- | --- | --- | --- | --- |
|
|
93
|
+
| no-error-swallowing | CWE-390 | SAS-6 | 5.0 | Empty catch blocks and missing error logging | | ⚠️ | | 💡 |
|
|
94
|
+
| require-timeout-handling | CWE-400 | SAS-7 | 6.0 | External calls without timeout handling | | ⚠️ | | 💡 |
|
|
95
|
+
| no-unbounded-batch-processing | CWE-770 | SAS-7 | 5.5 | Processing batch records without size limits | | ⚠️ | | 💡 |
|
|
96
|
+
| no-exposed-error-details | CWE-209 | SAS-9 | 4.3 | Exposing internal error details in responses | | ⚠️ | | 💡 |
|
|
97
|
+
|
|
79
98
|
---
|
|
80
99
|
|
|
81
100
|
## 🔍 Rule Details
|
|
@@ -332,15 +351,17 @@ This plugin is optimized for ESLint's [Model Context Protocol (MCP)](https://esl
|
|
|
332
351
|
|
|
333
352
|
Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
334
353
|
|
|
335
|
-
| Plugin | Description
|
|
336
|
-
| ---------------------------------------------------------------------------------------------------- |
|
|
337
|
-
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) |
|
|
338
|
-
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | Express.js security (CORS, cookies, CSRF, helmet)
|
|
339
|
-
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security (guards, validation pipes, throttler)
|
|
340
|
-
| [`eslint-plugin-
|
|
341
|
-
| [`eslint-plugin-
|
|
342
|
-
| [`eslint-plugin-
|
|
343
|
-
| [`eslint-plugin-
|
|
354
|
+
| Plugin | Downloads | Description | Rules |
|
|
355
|
+
| ---------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------ | :---: |
|
|
356
|
+
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [](https://npmjs.com/package/eslint-plugin-secure-coding) | Universal security (OWASP Top 10 Web + Mobile) | 89 |
|
|
357
|
+
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | [](https://npmjs.com/package/eslint-plugin-express-security) | Express.js security (CORS, cookies, CSRF, helmet) | 8 |
|
|
358
|
+
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | [](https://npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security (guards, validation pipes, throttler) | 5 |
|
|
359
|
+
| [`eslint-plugin-browser-security`](https://www.npmjs.com/package/eslint-plugin-browser-security) | [](https://npmjs.com/package/eslint-plugin-browser-security) | Browser security (XSS, postMessage, storage, cookies) | 21 |
|
|
360
|
+
| [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) | [](https://npmjs.com/package/eslint-plugin-jwt) | JWT security (algorithm confusion, weak secrets, claims) | 13 |
|
|
361
|
+
| [`eslint-plugin-crypto`](https://www.npmjs.com/package/eslint-plugin-crypto) | [](https://npmjs.com/package/eslint-plugin-crypto) | Cryptographic best practices (weak algorithms, key handling) | 24 |
|
|
362
|
+
| [`eslint-plugin-pg`](https://www.npmjs.com/package/eslint-plugin-pg) | [](https://npmjs.com/package/eslint-plugin-pg) | PostgreSQL/node-postgres security | 13 |
|
|
363
|
+
| [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [](https://npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security (OWASP LLM + Agentic Top 10) | 19 |
|
|
364
|
+
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://npmjs.com/package/eslint-plugin-import-next) | High-performance import linting | 12 |
|
|
344
365
|
|
|
345
366
|
---
|
|
346
367
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-lambda-security",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Security-focused ESLint plugin for AWS Lambda and Middy applications. Detects insecure API Gateway responses, missing security headers, CORS misconfigurations, input validation issues, and more.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -63,9 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@interlace/eslint-devkit": "^1.2.1",
|
|
66
|
-
"tslib": "^2.3.0"
|
|
67
|
-
"vitest": "^4.0.6",
|
|
68
|
-
"@nx/vite": "^22.0.3"
|
|
66
|
+
"tslib": "^2.3.0"
|
|
69
67
|
},
|
|
70
68
|
"peerDependencies": {},
|
|
71
69
|
"peerDependenciesMeta": {
|
|
@@ -85,15 +83,8 @@
|
|
|
85
83
|
"optional": true
|
|
86
84
|
}
|
|
87
85
|
},
|
|
88
|
-
"scripts": {
|
|
89
|
-
"test": "vitest run",
|
|
90
|
-
"test:watch": "vitest watch",
|
|
91
|
-
"test:coverage": "vitest run --coverage"
|
|
92
|
-
},
|
|
93
86
|
"devDependencies": {
|
|
94
87
|
"@typescript-eslint/parser": "^8.46.2",
|
|
95
|
-
"@typescript-eslint/rule-tester": "^8.46.2"
|
|
96
|
-
"@vitest/coverage-v8": "^4.0.6",
|
|
97
|
-
"vitest": "^4.0.6"
|
|
88
|
+
"@typescript-eslint/rule-tester": "^8.46.2"
|
|
98
89
|
}
|
|
99
|
-
}
|
|
90
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -3,7 +3,20 @@
|
|
|
3
3
|
* Security-focused ESLint rules for AWS Lambda and Middy applications
|
|
4
4
|
*
|
|
5
5
|
* Detects insecure API Gateway responses, missing security headers,
|
|
6
|
-
* CORS misconfigurations, input validation issues,
|
|
6
|
+
* CORS misconfigurations, input validation issues, authorization gaps,
|
|
7
|
+
* SSRF vulnerabilities, and more.
|
|
8
|
+
*
|
|
9
|
+
* OWASP Serverless Top 10 Coverage:
|
|
10
|
+
* - SAS-1: Injection ✅ (no-unvalidated-event-body)
|
|
11
|
+
* - SAS-2: Broken Authentication ✅ (no-hardcoded-credentials-sdk)
|
|
12
|
+
* - SAS-3: Sensitive Data Exposure ✅ (no-env-logging, no-secrets-in-env)
|
|
13
|
+
* - SAS-4: Security Misconfiguration ✅ (no-permissive-cors-*)
|
|
14
|
+
* - SAS-5: Broken Access Control ✅ (no-missing-authorization-check, no-overly-permissive-iam-policy)
|
|
15
|
+
* - SAS-6: Insufficient Logging ✅ (no-error-swallowing)
|
|
16
|
+
* - SAS-7: Denial of Service ✅ (require-timeout-handling, no-unbounded-batch-processing)
|
|
17
|
+
* - SAS-8: Server-Side Request Forgery ✅ (no-user-controlled-requests)
|
|
18
|
+
* - SAS-9: Functions Misconfiguration ✅ (no-exposed-error-details)
|
|
19
|
+
* - SAS-10: Improper Crypto ➡️ (Use eslint-plugin-crypto)
|
|
7
20
|
*/
|
|
8
21
|
declare const _default: {
|
|
9
22
|
rules: {
|
|
@@ -12,6 +25,14 @@ declare const _default: {
|
|
|
12
25
|
'no-permissive-cors-middy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
13
26
|
'no-secrets-in-env': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
14
27
|
'no-env-logging': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
28
|
+
'no-unvalidated-event-body': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
29
|
+
'no-missing-authorization-check': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
30
|
+
'no-overly-permissive-iam-policy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
31
|
+
'no-error-swallowing': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
32
|
+
'require-timeout-handling': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
33
|
+
'no-unbounded-batch-processing': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
34
|
+
'no-user-controlled-requests': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
35
|
+
'no-exposed-error-details': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
15
36
|
};
|
|
16
37
|
configs: {
|
|
17
38
|
recommended: {
|
|
@@ -24,6 +45,14 @@ declare const _default: {
|
|
|
24
45
|
'no-permissive-cors-middy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
25
46
|
'no-secrets-in-env': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
26
47
|
'no-env-logging': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
48
|
+
'no-unvalidated-event-body': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
49
|
+
'no-missing-authorization-check': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
50
|
+
'no-overly-permissive-iam-policy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
51
|
+
'no-error-swallowing': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
52
|
+
'require-timeout-handling': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
53
|
+
'no-unbounded-batch-processing': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
54
|
+
'no-user-controlled-requests': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
55
|
+
'no-exposed-error-details': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
27
56
|
};
|
|
28
57
|
};
|
|
29
58
|
};
|
|
@@ -32,7 +61,15 @@ declare const _default: {
|
|
|
32
61
|
'lambda-security/no-permissive-cors-response': string;
|
|
33
62
|
'lambda-security/no-permissive-cors-middy': string;
|
|
34
63
|
'lambda-security/no-secrets-in-env': string;
|
|
64
|
+
'lambda-security/no-user-controlled-requests': string;
|
|
65
|
+
'lambda-security/no-overly-permissive-iam-policy': string;
|
|
66
|
+
'lambda-security/no-unvalidated-event-body': string;
|
|
67
|
+
'lambda-security/no-missing-authorization-check': string;
|
|
68
|
+
'lambda-security/no-exposed-error-details': string;
|
|
35
69
|
'lambda-security/no-env-logging': string;
|
|
70
|
+
'lambda-security/no-error-swallowing': string;
|
|
71
|
+
'lambda-security/require-timeout-handling': string;
|
|
72
|
+
'lambda-security/no-unbounded-batch-processing': string;
|
|
36
73
|
};
|
|
37
74
|
};
|
|
38
75
|
strict: {
|
|
@@ -45,6 +82,14 @@ declare const _default: {
|
|
|
45
82
|
'no-permissive-cors-middy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
46
83
|
'no-secrets-in-env': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
47
84
|
'no-env-logging': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
85
|
+
'no-unvalidated-event-body': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
86
|
+
'no-missing-authorization-check': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
87
|
+
'no-overly-permissive-iam-policy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
88
|
+
'no-error-swallowing': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
89
|
+
'require-timeout-handling': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
90
|
+
'no-unbounded-batch-processing': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
91
|
+
'no-user-controlled-requests': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
92
|
+
'no-exposed-error-details': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
48
93
|
};
|
|
49
94
|
};
|
|
50
95
|
};
|
|
@@ -54,6 +99,14 @@ declare const _default: {
|
|
|
54
99
|
'lambda-security/no-permissive-cors-middy': string;
|
|
55
100
|
'lambda-security/no-secrets-in-env': string;
|
|
56
101
|
'lambda-security/no-env-logging': string;
|
|
102
|
+
'lambda-security/no-unvalidated-event-body': string;
|
|
103
|
+
'lambda-security/no-missing-authorization-check': string;
|
|
104
|
+
'lambda-security/no-overly-permissive-iam-policy': string;
|
|
105
|
+
'lambda-security/no-error-swallowing': string;
|
|
106
|
+
'lambda-security/require-timeout-handling': string;
|
|
107
|
+
'lambda-security/no-unbounded-batch-processing': string;
|
|
108
|
+
'lambda-security/no-user-controlled-requests': string;
|
|
109
|
+
'lambda-security/no-exposed-error-details': string;
|
|
57
110
|
};
|
|
58
111
|
};
|
|
59
112
|
};
|
package/src/index.js
CHANGED
|
@@ -4,20 +4,62 @@
|
|
|
4
4
|
* Security-focused ESLint rules for AWS Lambda and Middy applications
|
|
5
5
|
*
|
|
6
6
|
* Detects insecure API Gateway responses, missing security headers,
|
|
7
|
-
* CORS misconfigurations, input validation issues,
|
|
7
|
+
* CORS misconfigurations, input validation issues, authorization gaps,
|
|
8
|
+
* SSRF vulnerabilities, and more.
|
|
9
|
+
*
|
|
10
|
+
* OWASP Serverless Top 10 Coverage:
|
|
11
|
+
* - SAS-1: Injection ✅ (no-unvalidated-event-body)
|
|
12
|
+
* - SAS-2: Broken Authentication ✅ (no-hardcoded-credentials-sdk)
|
|
13
|
+
* - SAS-3: Sensitive Data Exposure ✅ (no-env-logging, no-secrets-in-env)
|
|
14
|
+
* - SAS-4: Security Misconfiguration ✅ (no-permissive-cors-*)
|
|
15
|
+
* - SAS-5: Broken Access Control ✅ (no-missing-authorization-check, no-overly-permissive-iam-policy)
|
|
16
|
+
* - SAS-6: Insufficient Logging ✅ (no-error-swallowing)
|
|
17
|
+
* - SAS-7: Denial of Service ✅ (require-timeout-handling, no-unbounded-batch-processing)
|
|
18
|
+
* - SAS-8: Server-Side Request Forgery ✅ (no-user-controlled-requests)
|
|
19
|
+
* - SAS-9: Functions Misconfiguration ✅ (no-exposed-error-details)
|
|
20
|
+
* - SAS-10: Improper Crypto ➡️ (Use eslint-plugin-crypto)
|
|
8
21
|
*/
|
|
9
|
-
// P0 Critical Rules
|
|
22
|
+
// Original P0 Critical Rules
|
|
10
23
|
const no_hardcoded_credentials_sdk_1 = require("./rules/no-hardcoded-credentials-sdk");
|
|
11
24
|
const no_permissive_cors_response_1 = require("./rules/no-permissive-cors-response");
|
|
12
25
|
const no_permissive_cors_middy_1 = require("./rules/no-permissive-cors-middy");
|
|
13
26
|
const no_secrets_in_env_1 = require("./rules/no-secrets-in-env");
|
|
14
27
|
const no_env_logging_1 = require("./rules/no-env-logging");
|
|
28
|
+
// SAS-1: Injection
|
|
29
|
+
const no_unvalidated_event_body_1 = require("./rules/no-unvalidated-event-body");
|
|
30
|
+
// SAS-5: Broken Access Control
|
|
31
|
+
const no_missing_authorization_check_1 = require("./rules/no-missing-authorization-check");
|
|
32
|
+
const no_overly_permissive_iam_policy_1 = require("./rules/no-overly-permissive-iam-policy");
|
|
33
|
+
// SAS-6: Insufficient Logging
|
|
34
|
+
const no_error_swallowing_1 = require("./rules/no-error-swallowing");
|
|
35
|
+
// SAS-7: Denial of Service
|
|
36
|
+
const require_timeout_handling_1 = require("./rules/require-timeout-handling");
|
|
37
|
+
const no_unbounded_batch_processing_1 = require("./rules/no-unbounded-batch-processing");
|
|
38
|
+
// SAS-8: Server-Side Request Forgery
|
|
39
|
+
const no_user_controlled_requests_1 = require("./rules/no-user-controlled-requests");
|
|
40
|
+
// SAS-9: Functions Misconfiguration
|
|
41
|
+
const no_exposed_error_details_1 = require("./rules/no-exposed-error-details");
|
|
15
42
|
const rules = {
|
|
43
|
+
// Original rules
|
|
16
44
|
'no-hardcoded-credentials-sdk': no_hardcoded_credentials_sdk_1.noHardcodedCredentialsSdk,
|
|
17
45
|
'no-permissive-cors-response': no_permissive_cors_response_1.noPermissiveCorsResponse,
|
|
18
46
|
'no-permissive-cors-middy': no_permissive_cors_middy_1.noPermissiveCorsMidly,
|
|
19
47
|
'no-secrets-in-env': no_secrets_in_env_1.noSecretsInEnv,
|
|
20
48
|
'no-env-logging': no_env_logging_1.noEnvLogging,
|
|
49
|
+
// SAS-1: Injection
|
|
50
|
+
'no-unvalidated-event-body': no_unvalidated_event_body_1.noUnvalidatedEventBody,
|
|
51
|
+
// SAS-5: Broken Access Control
|
|
52
|
+
'no-missing-authorization-check': no_missing_authorization_check_1.noMissingAuthorizationCheck,
|
|
53
|
+
'no-overly-permissive-iam-policy': no_overly_permissive_iam_policy_1.noOverlyPermissiveIamPolicy,
|
|
54
|
+
// SAS-6: Insufficient Logging
|
|
55
|
+
'no-error-swallowing': no_error_swallowing_1.noErrorSwallowing,
|
|
56
|
+
// SAS-7: Denial of Service
|
|
57
|
+
'require-timeout-handling': require_timeout_handling_1.requireTimeoutHandling,
|
|
58
|
+
'no-unbounded-batch-processing': no_unbounded_batch_processing_1.noUnboundedBatchProcessing,
|
|
59
|
+
// SAS-8: SSRF
|
|
60
|
+
'no-user-controlled-requests': no_user_controlled_requests_1.noUserControlledRequests,
|
|
61
|
+
// SAS-9: Functions Misconfiguration
|
|
62
|
+
'no-exposed-error-details': no_exposed_error_details_1.noExposedErrorDetails,
|
|
21
63
|
};
|
|
22
64
|
const configs = {
|
|
23
65
|
recommended: {
|
|
@@ -26,11 +68,22 @@ const configs = {
|
|
|
26
68
|
'lambda-security': { rules },
|
|
27
69
|
},
|
|
28
70
|
rules: {
|
|
71
|
+
// Critical: Always error
|
|
29
72
|
'lambda-security/no-hardcoded-credentials-sdk': 'error',
|
|
30
73
|
'lambda-security/no-permissive-cors-response': 'error',
|
|
31
74
|
'lambda-security/no-permissive-cors-middy': 'error',
|
|
32
75
|
'lambda-security/no-secrets-in-env': 'error',
|
|
76
|
+
'lambda-security/no-user-controlled-requests': 'error',
|
|
77
|
+
'lambda-security/no-overly-permissive-iam-policy': 'error',
|
|
78
|
+
// High: Warn in recommended
|
|
79
|
+
'lambda-security/no-unvalidated-event-body': 'warn',
|
|
80
|
+
'lambda-security/no-missing-authorization-check': 'warn',
|
|
81
|
+
'lambda-security/no-exposed-error-details': 'warn',
|
|
82
|
+
// Medium: Warn in recommended
|
|
33
83
|
'lambda-security/no-env-logging': 'warn',
|
|
84
|
+
'lambda-security/no-error-swallowing': 'warn',
|
|
85
|
+
'lambda-security/require-timeout-handling': 'warn',
|
|
86
|
+
'lambda-security/no-unbounded-batch-processing': 'warn',
|
|
34
87
|
},
|
|
35
88
|
},
|
|
36
89
|
strict: {
|
|
@@ -39,11 +92,20 @@ const configs = {
|
|
|
39
92
|
'lambda-security': { rules },
|
|
40
93
|
},
|
|
41
94
|
rules: {
|
|
95
|
+
// All rules as errors in strict mode
|
|
42
96
|
'lambda-security/no-hardcoded-credentials-sdk': 'error',
|
|
43
97
|
'lambda-security/no-permissive-cors-response': 'error',
|
|
44
98
|
'lambda-security/no-permissive-cors-middy': 'error',
|
|
45
99
|
'lambda-security/no-secrets-in-env': 'error',
|
|
46
100
|
'lambda-security/no-env-logging': 'error',
|
|
101
|
+
'lambda-security/no-unvalidated-event-body': 'error',
|
|
102
|
+
'lambda-security/no-missing-authorization-check': 'error',
|
|
103
|
+
'lambda-security/no-overly-permissive-iam-policy': 'error',
|
|
104
|
+
'lambda-security/no-error-swallowing': 'error',
|
|
105
|
+
'lambda-security/require-timeout-handling': 'error',
|
|
106
|
+
'lambda-security/no-unbounded-batch-processing': 'error',
|
|
107
|
+
'lambda-security/no-user-controlled-requests': 'error',
|
|
108
|
+
'lambda-security/no-exposed-error-details': 'error',
|
|
47
109
|
},
|
|
48
110
|
},
|
|
49
111
|
};
|
|
@@ -52,6 +114,6 @@ module.exports = {
|
|
|
52
114
|
configs,
|
|
53
115
|
meta: {
|
|
54
116
|
name: 'eslint-plugin-lambda-security',
|
|
55
|
-
version: '
|
|
117
|
+
version: '1.1.0',
|
|
56
118
|
},
|
|
57
119
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** Allow in test files. Default: true */
|
|
3
|
+
allowInTests?: boolean;
|
|
4
|
+
/** Allow comments as documentation of intentional swallowing. Default: true */
|
|
5
|
+
allowWithComment?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const noErrorSwallowing: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
description: 'Detects empty catch blocks and missing error logging in Lambda handlers',
|
|
11
|
+
},
|
|
12
|
+
hasSuggestions: true,
|
|
13
|
+
messages: {
|
|
14
|
+
emptyCatchBlock: (0, eslint_devkit_1.formatLLMMessage)({
|
|
15
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
16
|
+
issueName: 'Error Swallowing',
|
|
17
|
+
cwe: 'CWE-390',
|
|
18
|
+
cvss: 5.0,
|
|
19
|
+
description: 'Catch block swallows error without logging. Security incidents may go undetected.',
|
|
20
|
+
severity: 'MEDIUM',
|
|
21
|
+
fix: 'Log the error with context: console.error("Operation failed", { error, awsRequestId: context.awsRequestId })',
|
|
22
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/390.html',
|
|
23
|
+
}),
|
|
24
|
+
addErrorLogging: (0, eslint_devkit_1.formatLLMMessage)({
|
|
25
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
26
|
+
issueName: 'Add Error Logging',
|
|
27
|
+
description: 'Log errors with context for security monitoring',
|
|
28
|
+
severity: 'LOW',
|
|
29
|
+
fix: 'console.error("Error:", error); // or use structured logger',
|
|
30
|
+
documentationLink: 'https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html',
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
schema: [
|
|
34
|
+
{
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
allowInTests: {
|
|
38
|
+
type: 'boolean',
|
|
39
|
+
default: true,
|
|
40
|
+
},
|
|
41
|
+
allowWithComment: {
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
default: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
defaultOptions: [{ allowInTests: true, allowWithComment: true }],
|
|
51
|
+
create(context, [options = {}]) {
|
|
52
|
+
const { allowInTests = true, allowWithComment = true } = options;
|
|
53
|
+
const filename = context.filename || context.getFilename();
|
|
54
|
+
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
55
|
+
if (allowInTests && isTestFile) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if a catch block has any logging
|
|
60
|
+
*/
|
|
61
|
+
function hasLogging(block) {
|
|
62
|
+
let found = false;
|
|
63
|
+
function checkNode(node) {
|
|
64
|
+
if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
|
|
65
|
+
const callee = node.callee;
|
|
66
|
+
// console.log, console.error, console.warn
|
|
67
|
+
if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
68
|
+
callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
69
|
+
callee.object.name === 'console') {
|
|
70
|
+
found = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// logger.error, logger.warn, etc.
|
|
74
|
+
if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
75
|
+
callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
76
|
+
['logger', 'log', 'winston', 'pino', 'bunyan'].includes(callee.object.name)) {
|
|
77
|
+
found = true;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Direct function call that includes 'log' or 'error'
|
|
81
|
+
if (callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
82
|
+
/log|error|warn/i.test(callee.name)) {
|
|
83
|
+
found = true;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Recursively check child nodes
|
|
88
|
+
for (const key of Object.keys(node)) {
|
|
89
|
+
const child = node[key];
|
|
90
|
+
if (child && typeof child === 'object' && 'type' in child) {
|
|
91
|
+
checkNode(child);
|
|
92
|
+
}
|
|
93
|
+
else if (Array.isArray(child)) {
|
|
94
|
+
for (const item of child) {
|
|
95
|
+
if (item !== null && item !== undefined && typeof item === 'object' && 'type' in item) {
|
|
96
|
+
checkNode(item);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const stmt of block.body) {
|
|
103
|
+
checkNode(stmt);
|
|
104
|
+
}
|
|
105
|
+
return found;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check if block has comments indicating intentional swallowing
|
|
109
|
+
*/
|
|
110
|
+
function hasIntentionalComment(node) {
|
|
111
|
+
if (!allowWithComment)
|
|
112
|
+
return false;
|
|
113
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
114
|
+
const comments = sourceCode.getCommentsInside(node.body);
|
|
115
|
+
return comments.some((comment) => /intentional|expected|ignore|suppress|handled|silent/i.test(comment.value));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if catch has throw/rethrow
|
|
119
|
+
*/
|
|
120
|
+
function hasThrow(block) {
|
|
121
|
+
return block.body.some((stmt) => stmt.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if catch has return (might be valid in some contexts)
|
|
125
|
+
*/
|
|
126
|
+
function hasReturn(block) {
|
|
127
|
+
return block.body.some((stmt) => stmt.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
CatchClause(node) {
|
|
131
|
+
const body = node.body;
|
|
132
|
+
// Empty catch block
|
|
133
|
+
if (body.body.length === 0) {
|
|
134
|
+
if (!hasIntentionalComment(node)) {
|
|
135
|
+
context.report({
|
|
136
|
+
node,
|
|
137
|
+
messageId: 'emptyCatchBlock',
|
|
138
|
+
suggest: [
|
|
139
|
+
{
|
|
140
|
+
messageId: 'addErrorLogging',
|
|
141
|
+
fix: (fixer) => {
|
|
142
|
+
const errorParam = node.param?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
|
|
143
|
+
? node.param.name
|
|
144
|
+
: 'error';
|
|
145
|
+
return fixer.replaceText(body, `{ console.error('Error:', ${errorParam}); }`);
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// Has throw - OK, error is propagated
|
|
154
|
+
if (hasThrow(body)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// Check if there's logging
|
|
158
|
+
if (!hasLogging(body)) {
|
|
159
|
+
// If there's a return with error context, that's also OK
|
|
160
|
+
if (hasReturn(body)) {
|
|
161
|
+
// Check if return includes error info
|
|
162
|
+
const returnStmt = body.body.find((s) => s.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
|
|
163
|
+
if (returnStmt?.argument) {
|
|
164
|
+
// Check if return includes status 500 or error body
|
|
165
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
166
|
+
const returnText = sourceCode.getText(returnStmt.argument);
|
|
167
|
+
if (/500|error|fail/i.test(returnText)) {
|
|
168
|
+
return; // Acceptable error handling
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!hasIntentionalComment(node)) {
|
|
173
|
+
context.report({
|
|
174
|
+
node,
|
|
175
|
+
messageId: 'emptyCatchBlock',
|
|
176
|
+
suggest: [
|
|
177
|
+
{
|
|
178
|
+
messageId: 'addErrorLogging',
|
|
179
|
+
fix: () => null,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
});
|