eslint-plugin-lambda-security 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +106 -0
- package/CHANGELOG.md +42 -0
- package/README.md +355 -0
- package/package.json +99 -0
- package/src/index.d.ts +65 -0
- package/src/index.js +58 -0
- package/src/index.js.map +1 -0
- package/src/rules/no-env-logging/index.d.ts +5 -0
- package/src/rules/no-env-logging/index.js +129 -0
- package/src/rules/no-env-logging/index.js.map +1 -0
- package/src/rules/no-hardcoded-credentials-sdk/index.d.ts +5 -0
- package/src/rules/no-hardcoded-credentials-sdk/index.js +226 -0
- package/src/rules/no-hardcoded-credentials-sdk/index.js.map +1 -0
- package/src/rules/no-permissive-cors-middy/index.d.ts +5 -0
- package/src/rules/no-permissive-cors-middy/index.js +134 -0
- package/src/rules/no-permissive-cors-middy/index.js.map +1 -0
- package/src/rules/no-permissive-cors-response/index.d.ts +7 -0
- package/src/rules/no-permissive-cors-response/index.js +144 -0
- package/src/rules/no-permissive-cors-response/index.js.map +1 -0
- package/src/rules/no-secrets-in-env/index.d.ts +7 -0
- package/src/rules/no-secrets-in-env/index.js +154 -0
- package/src/rules/no-secrets-in-env/index.js.map +1 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
> Context for AI coding agents working on eslint-plugin-lambda-security
|
|
4
|
+
|
|
5
|
+
## Setup Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies (from monorepo root)
|
|
9
|
+
pnpm install
|
|
10
|
+
|
|
11
|
+
# Build this package
|
|
12
|
+
nx build eslint-plugin-lambda-security
|
|
13
|
+
|
|
14
|
+
# Run tests
|
|
15
|
+
nx test eslint-plugin-lambda-security
|
|
16
|
+
|
|
17
|
+
# Run tests with coverage
|
|
18
|
+
nx test eslint-plugin-lambda-security --coverage
|
|
19
|
+
|
|
20
|
+
# Lint this package
|
|
21
|
+
nx lint eslint-plugin-lambda-security
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Code Style
|
|
25
|
+
|
|
26
|
+
- TypeScript strict mode with `@interlace/eslint-devkit` types
|
|
27
|
+
- Use `AST_NODE_TYPES` constants, never string literals for node types
|
|
28
|
+
- Use `formatLLMMessage()` for all rule error messages
|
|
29
|
+
- Include CWE, CVSS, OWASP Serverless Top 10 in every security message
|
|
30
|
+
- Use `c8 ignore` comments with documented reasons for untestable code
|
|
31
|
+
- Single-pass AST traversal patterns (O(n) complexity)
|
|
32
|
+
|
|
33
|
+
## Testing Instructions
|
|
34
|
+
|
|
35
|
+
- Tests use `@typescript-eslint/rule-tester` with Vitest
|
|
36
|
+
- Each rule has `index.ts` (implementation) and `*.test.ts` (tests) in same directory
|
|
37
|
+
- Run specific rule test: `nx test eslint-plugin-lambda-security --testPathPattern="no-hardcoded-credentials"`
|
|
38
|
+
- Coverage target: ≥90% lines, ≥95% functions
|
|
39
|
+
- All tests must pass before committing
|
|
40
|
+
|
|
41
|
+
## Project Structure
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
src/
|
|
45
|
+
├── index.ts # Plugin entry, exports rules and 2 configs
|
|
46
|
+
├── types/index.ts # Exported rule option types
|
|
47
|
+
└── rules/ # 5 rule directories
|
|
48
|
+
└── [rule-name]/
|
|
49
|
+
├── index.ts # Rule implementation
|
|
50
|
+
└── *.test.ts # Rule tests
|
|
51
|
+
docs/rules/ # Markdown documentation per rule
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Plugin Purpose
|
|
55
|
+
|
|
56
|
+
Security-focused ESLint plugin with **5 rules** for AWS Lambda, Middy, and serverless applications. Covers hardcoded credentials, secrets exposure, environment logging, and CORS misconfigurations.
|
|
57
|
+
|
|
58
|
+
## Rule Categories
|
|
59
|
+
|
|
60
|
+
| Category | Rules | CWEs |
|
|
61
|
+
| --------------------- | --------------------------------------------------------------------- | -------- |
|
|
62
|
+
| Credentials & Secrets | `no-hardcoded-credentials-sdk`, `no-secrets-in-env`, `no-env-logging` | 532, 798 |
|
|
63
|
+
| CORS | `no-permissive-cors-response`, `no-permissive-cors-middy` | 942 |
|
|
64
|
+
|
|
65
|
+
## AWS SDK Clients Detected
|
|
66
|
+
|
|
67
|
+
S3Client, DynamoDBClient, LambdaClient, STSClient, SecretsManagerClient, SQSClient, SNSClient, EC2Client, ECSClient, CloudWatchClient, CloudWatchLogsClient, APIGatewayClient, CognitoIdentityClient, CognitoIdentityProviderClient, EventBridgeClient, StepFunctionsClient, RDSClient, ElastiCacheClient
|
|
68
|
+
|
|
69
|
+
## AWS Access Key Patterns
|
|
70
|
+
|
|
71
|
+
| Pattern | Type |
|
|
72
|
+
| ------- | ------------------------ |
|
|
73
|
+
| `AKIA*` | IAM user access key |
|
|
74
|
+
| `ASIA*` | STS temporary access key |
|
|
75
|
+
| `AIDA*` | IAM user ID |
|
|
76
|
+
|
|
77
|
+
## Common Fix Patterns
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Hardcoded credentials
|
|
81
|
+
// BAD: new S3Client({ credentials: { accessKeyId: 'AKIA...', secretAccessKey: '...' } })
|
|
82
|
+
// GOOD: new S3Client({ region: 'us-east-1' }) // Uses Lambda execution role
|
|
83
|
+
// GOOD: new S3Client({ credentials: fromNodeProviderChain() })
|
|
84
|
+
|
|
85
|
+
// Secrets in env
|
|
86
|
+
// BAD: process.env.DB_PASSWORD = 'my-secret'
|
|
87
|
+
// GOOD: const secret = await client.send(new GetSecretValueCommand({ SecretId: 'my-secret' }))
|
|
88
|
+
|
|
89
|
+
// Logging env
|
|
90
|
+
// BAD: console.log(process.env)
|
|
91
|
+
// GOOD: console.log('Region:', process.env.AWS_REGION)
|
|
92
|
+
|
|
93
|
+
// Lambda CORS
|
|
94
|
+
// BAD: return { headers: { 'Access-Control-Allow-Origin': '*' }, ... }
|
|
95
|
+
// GOOD: return { headers: { 'Access-Control-Allow-Origin': 'https://your-app.com' }, ... }
|
|
96
|
+
|
|
97
|
+
// Middy CORS
|
|
98
|
+
// BAD: middy(handler).use(httpCors())
|
|
99
|
+
// GOOD: middy(handler).use(httpCors({ origins: ['https://your-app.com'] }))
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Security Considerations
|
|
103
|
+
|
|
104
|
+
- All rules map to OWASP Serverless Top 10: SAS-2, SAS-3, SAS-4
|
|
105
|
+
- CWE coverage: 532, 798, 942
|
|
106
|
+
- Real AWS key pattern detection (not just string length checks)
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `eslint-plugin-lambda-security` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-12-29
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
#### Credential & Secrets Protection Rules (3)
|
|
13
|
+
|
|
14
|
+
- `no-hardcoded-credentials-sdk` - Detect hardcoded AWS credentials in SDK v3 clients (CWE-798)
|
|
15
|
+
- `no-secrets-in-env` - Detect secrets hardcoded in environment variables (CWE-798)
|
|
16
|
+
- `no-env-logging` - Detect logging entire process.env object (CWE-532)
|
|
17
|
+
|
|
18
|
+
#### CORS Security Rules (2)
|
|
19
|
+
|
|
20
|
+
- `no-permissive-cors-response` - Detect wildcard CORS in Lambda response headers (CWE-942)
|
|
21
|
+
- `no-permissive-cors-middy` - Detect permissive CORS in @middy/http-cors middleware (CWE-942)
|
|
22
|
+
|
|
23
|
+
#### Presets (2)
|
|
24
|
+
|
|
25
|
+
- `recommended` - Balanced security defaults
|
|
26
|
+
- `strict` - All 5 rules as errors
|
|
27
|
+
|
|
28
|
+
#### Features
|
|
29
|
+
|
|
30
|
+
- LLM-optimized error messages with CWE references
|
|
31
|
+
- OWASP Serverless Top 10 alignment (SAS-2, SAS-3, SAS-4)
|
|
32
|
+
- AWS SDK v3 client detection (S3, DynamoDB, Lambda, STS, etc.)
|
|
33
|
+
- Middy middleware detection (@middy/http-cors)
|
|
34
|
+
- Real AWS access key pattern matching (AKIA*, ASIA*)
|
|
35
|
+
- TypeScript support with exported option types
|
|
36
|
+
- Comprehensive test coverage (78 tests, 97.40% line coverage)
|
|
37
|
+
- Auto-fix for CORS violations
|
|
38
|
+
|
|
39
|
+
### Security
|
|
40
|
+
|
|
41
|
+
- Covers 3 CWEs: 532, 798, 942
|
|
42
|
+
- Maps to OWASP Serverless Top 10: SAS-2, SAS-3, SAS-4
|
package/README.md
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
# eslint-plugin-lambda-security
|
|
2
|
+
|
|
3
|
+
**Feature-based security rules that AI assistants can actually understand and fix.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/eslint-plugin-lambda-security)
|
|
6
|
+
[](https://www.npmjs.com/package/eslint-plugin-lambda-security)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=lambda_security)
|
|
9
|
+
|
|
10
|
+
> **Serverless-first security:** This plugin provides security rules for **AWS Lambda**, **Middy.js**, **Serverless Framework**, **AWS SAM**, and **AWS SDK v3**.
|
|
11
|
+
> 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.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 💡 What you get
|
|
16
|
+
|
|
17
|
+
- **Serverless-focused coverage:** 5 rules targeting Lambda-specific vulnerabilities (credentials, CORS, secrets, logging).
|
|
18
|
+
- **LLM-optimized & MCP-ready:** Structured 2-line messages with CWE + OWASP + CVSS + concrete fixes so humans _and_ AI auto-fixers stay aligned.
|
|
19
|
+
- **Standards aligned:** OWASP Serverless Top 10, CWE tagging, CVSS scoring in every finding for compliance mapping.
|
|
20
|
+
- **Tiered presets:** `recommended`, `strict` for fast policy rollout.
|
|
21
|
+
- **Framework-aware:** Detects Middy middleware, API Gateway response patterns, AWS SDK v3 clients.
|
|
22
|
+
- **Low false positive rate:** Context-aware detection with production heuristics.
|
|
23
|
+
|
|
24
|
+
Every security rule produces a **structured 2-line error message**:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
src/handlers/api.ts
|
|
28
|
+
18:5 error 🔒 CWE-798 OWASP:SAS-2 CVSS:9.8 | Hardcoded AWS credentials detected | CRITICAL [SOC2,PCI-DSS]
|
|
29
|
+
Fix: Use credential provider chain or Lambda execution role | https://owasp.org/...
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Each message includes:**
|
|
33
|
+
|
|
34
|
+
- 🔒 **CWE reference** - vulnerability classification
|
|
35
|
+
- 📋 **OWASP category** - Serverless Top 10 mapping
|
|
36
|
+
- 📊 **CVSS score** - severity rating (0.0-10.0)
|
|
37
|
+
- 🏢 **Compliance tags** - affected frameworks (SOC2, PCI-DSS, HIPAA)
|
|
38
|
+
- ✅ **Fix instruction** - exact code to write
|
|
39
|
+
- 📚 **Documentation link** - learn more
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 📊 OWASP Serverless Top 10 Coverage Matrix
|
|
44
|
+
|
|
45
|
+
| OWASP Category | Coverage | Rules |
|
|
46
|
+
| -------------------------------------- | :------: | -------------------------------------------------------------------------------- |
|
|
47
|
+
| **SAS-1: Injection** | 🔜 | `no-unvalidated-event-body` (planned) |
|
|
48
|
+
| **SAS-2: Broken Authentication** | ✅ | `no-hardcoded-credentials-sdk` |
|
|
49
|
+
| **SAS-3: Sensitive Data Exposure** | ✅ | `no-env-logging`, `no-secrets-in-env` |
|
|
50
|
+
| **SAS-4: Security Misconfiguration** | ✅ | `no-permissive-cors-*` |
|
|
51
|
+
| **SAS-5: Broken Access Control** | 🔜 | Coming soon |
|
|
52
|
+
| **SAS-6: Insufficient Logging** | 🔜 | Coming soon |
|
|
53
|
+
| **SAS-7: Denial of Service** | 🔜 | Coming soon |
|
|
54
|
+
| **SAS-8: Server-Side Request Forgery** | 🔜 | Coming soon |
|
|
55
|
+
| **SAS-9: Functions Misconfiguration** | 🔜 | Coming soon |
|
|
56
|
+
| **SAS-10: Improper Crypto** | 🔜 | Use [`eslint-plugin-crypto`](https://www.npmjs.com/package/eslint-plugin-crypto) |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🔐 5 Security Rules
|
|
61
|
+
|
|
62
|
+
💼 = Set in `recommended` | ⚠️ = Warns in `recommended` | 🔧 = Auto-fixable | 💡 = Suggestions
|
|
63
|
+
|
|
64
|
+
### Credential & Secrets Protection (3 rules)
|
|
65
|
+
|
|
66
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
67
|
+
| ------------------------------------------------------------- | ------- | ----- | ---- | ------------------------------------------- | --- | --- | --- | --- |
|
|
68
|
+
| [no-hardcoded-credentials-sdk](#no-hardcoded-credentials-sdk) | CWE-798 | SAS-2 | 9.8 | Hardcoded AWS credentials in SDK v3 clients | 💼 | | | |
|
|
69
|
+
| [no-secrets-in-env](#no-secrets-in-env) | CWE-798 | SAS-3 | 9.8 | Secrets hardcoded in environment variables | 💼 | | | |
|
|
70
|
+
| [no-env-logging](#no-env-logging) | CWE-532 | SAS-3 | 7.5 | Logging entire `process.env` object | | ⚠️ | | |
|
|
71
|
+
|
|
72
|
+
### CORS Security (2 rules)
|
|
73
|
+
|
|
74
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
75
|
+
| ----------------------------------------------------------- | ------- | ----- | ---- | ---------------------------------------------- | --- | --- | --- | --- |
|
|
76
|
+
| [no-permissive-cors-response](#no-permissive-cors-response) | CWE-942 | SAS-4 | 9.1 | Wildcard CORS in Lambda response headers | 💼 | | 🔧 | |
|
|
77
|
+
| [no-permissive-cors-middy](#no-permissive-cors-middy) | CWE-942 | SAS-4 | 9.1 | Permissive CORS in @middy/http-cors middleware | 💼 | | | |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 🔍 Rule Details
|
|
82
|
+
|
|
83
|
+
### `no-hardcoded-credentials-sdk`
|
|
84
|
+
|
|
85
|
+
Detects hardcoded AWS credentials in AWS SDK v3 client configurations.
|
|
86
|
+
|
|
87
|
+
**❌ Incorrect**
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
// Hardcoded credentials - NEVER do this!
|
|
91
|
+
const client = new S3Client({
|
|
92
|
+
credentials: {
|
|
93
|
+
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
|
|
94
|
+
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**✅ Correct**
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
// Use credential provider chain
|
|
103
|
+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
104
|
+
|
|
105
|
+
const client = new S3Client({
|
|
106
|
+
credentials: fromNodeProviderChain(),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Or let SDK use default chain (recommended for Lambda)
|
|
110
|
+
const client = new S3Client({ region: 'us-east-1' });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Detection Patterns:**
|
|
114
|
+
|
|
115
|
+
- Real AWS access key patterns (AKIA*, ASIA*)
|
|
116
|
+
- Secret access keys with 20+ characters
|
|
117
|
+
- Session tokens with 15+ characters
|
|
118
|
+
- Template literal credential construction
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
### `no-permissive-cors-response`
|
|
123
|
+
|
|
124
|
+
Detects wildcard CORS (`Access-Control-Allow-Origin: '*'`) in Lambda response headers.
|
|
125
|
+
|
|
126
|
+
**❌ Incorrect**
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
return {
|
|
130
|
+
statusCode: 200,
|
|
131
|
+
headers: { 'Access-Control-Allow-Origin': '*' },
|
|
132
|
+
body: JSON.stringify(data),
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**✅ Correct**
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
return {
|
|
140
|
+
statusCode: 200,
|
|
141
|
+
headers: { 'Access-Control-Allow-Origin': 'https://your-app.com' },
|
|
142
|
+
body: JSON.stringify(data),
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Or use dynamic origin from request
|
|
146
|
+
return {
|
|
147
|
+
statusCode: 200,
|
|
148
|
+
headers: { 'Access-Control-Allow-Origin': event.headers.origin },
|
|
149
|
+
body: JSON.stringify(data),
|
|
150
|
+
};
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### `no-permissive-cors-middy`
|
|
156
|
+
|
|
157
|
+
Detects permissive CORS configuration in Middy http-cors middleware.
|
|
158
|
+
|
|
159
|
+
**❌ Incorrect**
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
// Default is permissive!
|
|
163
|
+
middy(handler).use(httpCors());
|
|
164
|
+
|
|
165
|
+
// Explicit wildcard
|
|
166
|
+
middy(handler).use(httpCors({ origin: '*' }));
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**✅ Correct**
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
middy(handler).use(
|
|
173
|
+
httpCors({
|
|
174
|
+
origins: ['https://your-app.com', 'https://app.your-domain.com'],
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### `no-secrets-in-env`
|
|
182
|
+
|
|
183
|
+
Detects secrets hardcoded in environment variable assignments.
|
|
184
|
+
|
|
185
|
+
**❌ Incorrect**
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
process.env.DB_PASSWORD = 'my-secret-password-12345';
|
|
189
|
+
|
|
190
|
+
const envConfig = {
|
|
191
|
+
API_KEY: 'sk-1234567890abcdef1234567890abcdef',
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**✅ Correct**
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
// Read from process.env (populated by Lambda)
|
|
199
|
+
const password = process.env.DB_PASSWORD;
|
|
200
|
+
|
|
201
|
+
// Use AWS Secrets Manager
|
|
202
|
+
import {
|
|
203
|
+
SecretsManagerClient,
|
|
204
|
+
GetSecretValueCommand,
|
|
205
|
+
} from '@aws-sdk/client-secrets-manager';
|
|
206
|
+
|
|
207
|
+
const secret = await client.send(
|
|
208
|
+
new GetSecretValueCommand({ SecretId: 'my-secret' }),
|
|
209
|
+
);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### `no-env-logging`
|
|
215
|
+
|
|
216
|
+
Detects logging of the entire `process.env` object, which may expose secrets.
|
|
217
|
+
|
|
218
|
+
**❌ Incorrect**
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
console.log(process.env);
|
|
222
|
+
console.log(JSON.stringify(process.env));
|
|
223
|
+
logger.info(process.env);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**✅ Correct**
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
// Log specific, non-sensitive values
|
|
230
|
+
console.log('Region:', process.env.AWS_REGION);
|
|
231
|
+
console.log('Environment:', process.env.NODE_ENV);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## 🚀 Quick Start
|
|
237
|
+
|
|
238
|
+
### ESLint Flat Config (Recommended)
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
// eslint.config.js
|
|
242
|
+
import lambdaSecurity from 'eslint-plugin-lambda-security';
|
|
243
|
+
|
|
244
|
+
export default [
|
|
245
|
+
lambdaSecurity.configs.recommended,
|
|
246
|
+
// ... other configs
|
|
247
|
+
];
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Strict Mode
|
|
251
|
+
|
|
252
|
+
```javascript
|
|
253
|
+
import lambdaSecurity from 'eslint-plugin-lambda-security';
|
|
254
|
+
|
|
255
|
+
export default [lambdaSecurity.configs.strict];
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## 📋 Available Presets
|
|
261
|
+
|
|
262
|
+
| Preset | Description |
|
|
263
|
+
| ----------------- | ---------------------------------------------------------------------- |
|
|
264
|
+
| **`recommended`** | Balanced security for Lambda projects (critical as error, others warn) |
|
|
265
|
+
| **`strict`** | Maximum security enforcement (all rules as errors) |
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## ⚙️ Configuration Options
|
|
270
|
+
|
|
271
|
+
All rules accept these common options:
|
|
272
|
+
|
|
273
|
+
```javascript
|
|
274
|
+
{
|
|
275
|
+
rules: {
|
|
276
|
+
'lambda-security/no-hardcoded-credentials-sdk': ['error', {
|
|
277
|
+
allowInTests: true // Default: true - skip test files
|
|
278
|
+
}],
|
|
279
|
+
'lambda-security/no-secrets-in-env': ['error', {
|
|
280
|
+
allowInTests: true,
|
|
281
|
+
additionalPatterns: ['CUSTOM_SECRET_*'] // Additional patterns to detect
|
|
282
|
+
}]
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## 🏢 Enterprise Integration Example
|
|
290
|
+
|
|
291
|
+
```javascript
|
|
292
|
+
// eslint.config.js
|
|
293
|
+
import lambdaSecurity from 'eslint-plugin-lambda-security';
|
|
294
|
+
|
|
295
|
+
export default [
|
|
296
|
+
// Baseline for all Lambda functions
|
|
297
|
+
lambdaSecurity.configs.recommended,
|
|
298
|
+
|
|
299
|
+
// Strict mode for payment/auth handlers
|
|
300
|
+
{
|
|
301
|
+
files: ['functions/payments/**', 'functions/auth/**'],
|
|
302
|
+
...lambdaSecurity.configs.strict,
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## 🤖 LLM & AI Integration
|
|
310
|
+
|
|
311
|
+
This plugin is optimized for ESLint's [Model Context Protocol (MCP)](https://eslint.org/docs/latest/use/mcp), enabling AI assistants like **Cursor**, **GitHub Copilot**, and **Claude** to:
|
|
312
|
+
|
|
313
|
+
- Understand the exact vulnerability type via CWE references
|
|
314
|
+
- Apply the correct fix using structured guidance
|
|
315
|
+
- Provide educational context to developers
|
|
316
|
+
|
|
317
|
+
```json
|
|
318
|
+
// .cursor/mcp.json
|
|
319
|
+
{
|
|
320
|
+
"mcpServers": {
|
|
321
|
+
"eslint": {
|
|
322
|
+
"command": "npx",
|
|
323
|
+
"args": ["@eslint/mcp@latest"]
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## 🔗 Related ESLint Plugins
|
|
332
|
+
|
|
333
|
+
Part of the **Forge-JS ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
334
|
+
|
|
335
|
+
| Plugin | Description | Rules |
|
|
336
|
+
| ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | :---: |
|
|
337
|
+
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | Framework-agnostic security (OWASP Web + Mobile Top 10) | 78 |
|
|
338
|
+
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | Express.js security (CORS, cookies, CSRF, helmet) | 8 |
|
|
339
|
+
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security (guards, validation pipes, throttler) | 🔜 |
|
|
340
|
+
| [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) | JWT security (algorithm confusion, weak secrets, claims validation) | 13 |
|
|
341
|
+
| [`eslint-plugin-crypto`](https://www.npmjs.com/package/eslint-plugin-crypto) | Cryptographic best practices (weak algorithms, key handling, CVE-specific) | 24 |
|
|
342
|
+
| [`eslint-plugin-pg`](https://www.npmjs.com/package/eslint-plugin-pg) | PostgreSQL/node-postgres security and best practices | 13 |
|
|
343
|
+
| [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security (OWASP LLM + Agentic Top 10) | 19 |
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 🔒 Privacy
|
|
348
|
+
|
|
349
|
+
This plugin runs **100% locally**. No data ever leaves your machine.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## 📄 License
|
|
354
|
+
|
|
355
|
+
MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-lambda-security",
|
|
3
|
+
"version": "0.0.1",
|
|
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
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"default": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./types": {
|
|
14
|
+
"types": "./src/types/index.d.ts",
|
|
15
|
+
"default": "./src/types/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"author": "Ofri Peretz <ofriperetzdev@gmail.com>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/README.md",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git",
|
|
24
|
+
"directory": "packages/eslint-plugin-lambda-security"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/ofri-peretz/eslint/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"src/",
|
|
34
|
+
"dist/",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"CHANGELOG.md",
|
|
38
|
+
"AGENTS.md"
|
|
39
|
+
],
|
|
40
|
+
"keywords": [
|
|
41
|
+
"eslint",
|
|
42
|
+
"eslint-plugin",
|
|
43
|
+
"eslintplugin",
|
|
44
|
+
"aws",
|
|
45
|
+
"lambda",
|
|
46
|
+
"aws-lambda",
|
|
47
|
+
"middy",
|
|
48
|
+
"api-gateway",
|
|
49
|
+
"serverless",
|
|
50
|
+
"security",
|
|
51
|
+
"cors",
|
|
52
|
+
"headers",
|
|
53
|
+
"validation",
|
|
54
|
+
"owasp",
|
|
55
|
+
"cwe",
|
|
56
|
+
"llm-optimized",
|
|
57
|
+
"ai-assistant",
|
|
58
|
+
"typescript",
|
|
59
|
+
"static-analysis"
|
|
60
|
+
],
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.0.0"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@interlace/eslint-devkit": "^1.2.1",
|
|
66
|
+
"tslib": "^2.3.0",
|
|
67
|
+
"vitest": "^4.0.6",
|
|
68
|
+
"@nx/vite": "^22.0.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"@aws-sdk/client-lambda": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@middy/core": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@middy/http-cors": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@middy/http-security-headers": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"@middy/validator": {
|
|
85
|
+
"optional": true
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"test": "vitest run",
|
|
90
|
+
"test:watch": "vitest watch",
|
|
91
|
+
"test:coverage": "vitest run --coverage"
|
|
92
|
+
},
|
|
93
|
+
"devDependencies": {
|
|
94
|
+
"@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"
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* eslint-plugin-lambda-security
|
|
3
|
+
* Security-focused ESLint rules for AWS Lambda and Middy applications
|
|
4
|
+
*
|
|
5
|
+
* Detects insecure API Gateway responses, missing security headers,
|
|
6
|
+
* CORS misconfigurations, input validation issues, and more.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: {
|
|
9
|
+
rules: {
|
|
10
|
+
'no-hardcoded-credentials-sdk': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
11
|
+
'no-permissive-cors-response': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
12
|
+
'no-permissive-cors-middy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
13
|
+
'no-secrets-in-env': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
14
|
+
'no-env-logging': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
15
|
+
};
|
|
16
|
+
configs: {
|
|
17
|
+
recommended: {
|
|
18
|
+
name: string;
|
|
19
|
+
plugins: {
|
|
20
|
+
'lambda-security': {
|
|
21
|
+
rules: {
|
|
22
|
+
'no-hardcoded-credentials-sdk': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
23
|
+
'no-permissive-cors-response': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
24
|
+
'no-permissive-cors-middy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
25
|
+
'no-secrets-in-env': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
26
|
+
'no-env-logging': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
rules: {
|
|
31
|
+
'lambda-security/no-hardcoded-credentials-sdk': string;
|
|
32
|
+
'lambda-security/no-permissive-cors-response': string;
|
|
33
|
+
'lambda-security/no-permissive-cors-middy': string;
|
|
34
|
+
'lambda-security/no-secrets-in-env': string;
|
|
35
|
+
'lambda-security/no-env-logging': string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
strict: {
|
|
39
|
+
name: string;
|
|
40
|
+
plugins: {
|
|
41
|
+
'lambda-security': {
|
|
42
|
+
rules: {
|
|
43
|
+
'no-hardcoded-credentials-sdk': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
44
|
+
'no-permissive-cors-response': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
45
|
+
'no-permissive-cors-middy': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
46
|
+
'no-secrets-in-env': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
47
|
+
'no-env-logging': ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
rules: {
|
|
52
|
+
'lambda-security/no-hardcoded-credentials-sdk': string;
|
|
53
|
+
'lambda-security/no-permissive-cors-response': string;
|
|
54
|
+
'lambda-security/no-permissive-cors-middy': string;
|
|
55
|
+
'lambda-security/no-secrets-in-env': string;
|
|
56
|
+
'lambda-security/no-env-logging': string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
meta: {
|
|
61
|
+
name: string;
|
|
62
|
+
version: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export = _default;
|