eslint-plugin-express-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 +100 -0
- package/CHANGELOG.md +51 -0
- package/README.md +424 -0
- package/package.json +99 -0
- package/src/index.d.ts +35 -0
- package/src/index.js +144 -0
- package/src/index.js.map +1 -0
- package/src/rules/no-cors-credentials-wildcard/index.d.ts +5 -0
- package/src/rules/no-cors-credentials-wildcard/index.js +142 -0
- package/src/rules/no-cors-credentials-wildcard/index.js.map +1 -0
- package/src/rules/no-express-unsafe-regex-route/index.d.ts +5 -0
- package/src/rules/no-express-unsafe-regex-route/index.js +181 -0
- package/src/rules/no-express-unsafe-regex-route/index.js.map +1 -0
- package/src/rules/no-graphql-introspection-production/index.d.ts +7 -0
- package/src/rules/no-graphql-introspection-production/index.js +161 -0
- package/src/rules/no-graphql-introspection-production/index.js.map +1 -0
- package/src/rules/no-insecure-cookie-options/index.d.ts +13 -0
- package/src/rules/no-insecure-cookie-options/index.js +162 -0
- package/src/rules/no-insecure-cookie-options/index.js.map +1 -0
- package/src/rules/no-permissive-cors/index.d.ts +9 -0
- package/src/rules/no-permissive-cors/index.js +205 -0
- package/src/rules/no-permissive-cors/index.js.map +1 -0
- package/src/rules/require-csrf-protection/index.d.ts +9 -0
- package/src/rules/require-csrf-protection/index.js +240 -0
- package/src/rules/require-csrf-protection/index.js.map +1 -0
- package/src/rules/require-express-body-parser-limits/index.d.ts +9 -0
- package/src/rules/require-express-body-parser-limits/index.js +201 -0
- package/src/rules/require-express-body-parser-limits/index.js.map +1 -0
- package/src/rules/require-helmet/index.d.ts +9 -0
- package/src/rules/require-helmet/index.js +185 -0
- package/src/rules/require-helmet/index.js.map +1 -0
- package/src/rules/require-rate-limiting/index.d.ts +12 -0
- package/src/rules/require-rate-limiting/index.js +142 -0
- package/src/rules/require-rate-limiting/index.js.map +1 -0
- package/src/types/index.d.ts +27 -0
- package/src/types/index.js +3 -0
- package/src/types/index.js.map +1 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
> Context for AI coding agents working on eslint-plugin-express-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-express-security
|
|
13
|
+
|
|
14
|
+
# Run tests
|
|
15
|
+
nx test eslint-plugin-express-security
|
|
16
|
+
|
|
17
|
+
# Run tests with coverage
|
|
18
|
+
nx test eslint-plugin-express-security --coverage
|
|
19
|
+
|
|
20
|
+
# Lint this package
|
|
21
|
+
nx lint eslint-plugin-express-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 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
|
+
- Detect Express objects through heuristics (variable naming, import analysis)
|
|
33
|
+
|
|
34
|
+
## Testing Instructions
|
|
35
|
+
|
|
36
|
+
- Tests use `@typescript-eslint/rule-tester` with Vitest
|
|
37
|
+
- Each rule has `index.ts` (implementation) and `*.test.ts` (tests) in same directory
|
|
38
|
+
- Run specific rule test: `nx test eslint-plugin-express-security --testPathPattern="require-helmet"`
|
|
39
|
+
- Coverage target: ≥90% lines, ≥95% functions
|
|
40
|
+
- All tests must pass before committing
|
|
41
|
+
|
|
42
|
+
## Project Structure
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
src/
|
|
46
|
+
├── index.ts # Plugin entry, exports rules and 4 configs
|
|
47
|
+
├── types/index.ts # Exported rule option types
|
|
48
|
+
└── rules/ # 9 rule directories
|
|
49
|
+
└── [rule-name]/
|
|
50
|
+
├── index.ts # Rule implementation
|
|
51
|
+
└── *.test.ts # Rule tests
|
|
52
|
+
docs/rules/ # Markdown documentation per rule
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Plugin Purpose
|
|
56
|
+
|
|
57
|
+
Security-focused ESLint plugin with **9 rules** for Express.js applications. Covers security headers (helmet), CORS misconfigurations, CSRF protection, cookie security, rate limiting, ReDoS prevention, and GraphQL security.
|
|
58
|
+
|
|
59
|
+
## Rule Categories
|
|
60
|
+
|
|
61
|
+
| Category | Rules | CWEs |
|
|
62
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------ | ------------- |
|
|
63
|
+
| Headers & CORS | `require-helmet`, `no-permissive-cors`, `no-cors-credentials-wildcard`, `require-express-body-parser-limits` | 693, 770, 942 |
|
|
64
|
+
| CSRF & Cookies | `require-csrf-protection`, `no-insecure-cookie-options` | 352, 614 |
|
|
65
|
+
| Rate Limiting & DoS | `require-rate-limiting`, `no-express-unsafe-regex-route` | 770, 1333 |
|
|
66
|
+
| GraphQL | `no-graphql-introspection-production` | 200 |
|
|
67
|
+
|
|
68
|
+
## Common Fix Patterns
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Helmet
|
|
72
|
+
// BAD: const app = express()
|
|
73
|
+
// GOOD: const app = express(); app.use(helmet())
|
|
74
|
+
|
|
75
|
+
// CORS
|
|
76
|
+
// BAD: app.use(cors({ origin: '*' }))
|
|
77
|
+
// GOOD: app.use(cors({ origin: ['https://your-app.com'] }))
|
|
78
|
+
|
|
79
|
+
// CSRF
|
|
80
|
+
// BAD: app.post('/api/transfer', handler)
|
|
81
|
+
// GOOD: app.use(csurf({ cookie: true })); app.post('/api/transfer', handler)
|
|
82
|
+
|
|
83
|
+
// Cookies
|
|
84
|
+
// BAD: res.cookie('session', token)
|
|
85
|
+
// GOOD: res.cookie('session', token, { httpOnly: true, secure: true, sameSite: 'strict' })
|
|
86
|
+
|
|
87
|
+
// Rate limiting
|
|
88
|
+
// BAD: app.post('/api/login', handler)
|
|
89
|
+
// GOOD: app.use('/api/', rateLimit({ windowMs: 15*60*1000, max: 100 }))
|
|
90
|
+
|
|
91
|
+
// Body parser limits
|
|
92
|
+
// BAD: app.use(express.json())
|
|
93
|
+
// GOOD: app.use(express.json({ limit: '100kb' }))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Security Considerations
|
|
97
|
+
|
|
98
|
+
- All rules map to OWASP Top 10 2021: A01, A03, A05, A07
|
|
99
|
+
- CWE coverage: 200, 352, 614, 693, 770, 942, 1333
|
|
100
|
+
- Middleware-aware detection: helmet, cors, csurf, express-rate-limit
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `eslint-plugin-express-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
|
+
#### Headers & CORS Rules (4)
|
|
13
|
+
|
|
14
|
+
- `require-helmet` - Require helmet middleware for security headers (CWE-693)
|
|
15
|
+
- `no-permissive-cors` - Detect wildcard CORS origins (CWE-942)
|
|
16
|
+
- `no-cors-credentials-wildcard` - Block credentials: true with wildcard origin (CWE-942)
|
|
17
|
+
- `require-express-body-parser-limits` - Require body parser size limits (CWE-770)
|
|
18
|
+
|
|
19
|
+
#### CSRF & Cookies Rules (2)
|
|
20
|
+
|
|
21
|
+
- `require-csrf-protection` - Require CSRF middleware for state-changing routes (CWE-352)
|
|
22
|
+
- `no-insecure-cookie-options` - Detect missing Secure/HttpOnly cookie attributes (CWE-614)
|
|
23
|
+
|
|
24
|
+
#### Rate Limiting & DoS Rules (2)
|
|
25
|
+
|
|
26
|
+
- `require-rate-limiting` - Require rate limiting middleware (CWE-770)
|
|
27
|
+
- `no-express-unsafe-regex-route` - Detect ReDoS-vulnerable regex patterns (CWE-1333)
|
|
28
|
+
|
|
29
|
+
#### GraphQL Rules (1)
|
|
30
|
+
|
|
31
|
+
- `no-graphql-introspection-production` - Disable GraphQL introspection in production (CWE-200)
|
|
32
|
+
|
|
33
|
+
#### Presets (4)
|
|
34
|
+
|
|
35
|
+
- `recommended` - Balanced security defaults
|
|
36
|
+
- `strict` - All 9 rules as errors
|
|
37
|
+
- `api` - HTTP/API security rules only
|
|
38
|
+
- `graphql` - GraphQL-specific rules only
|
|
39
|
+
|
|
40
|
+
#### Features
|
|
41
|
+
|
|
42
|
+
- LLM-optimized error messages with CWE references
|
|
43
|
+
- OWASP Top 10 2021 alignment (A01, A03, A05, A07)
|
|
44
|
+
- Middleware-aware detection (helmet, cors, csurf, express-rate-limit)
|
|
45
|
+
- TypeScript support with exported option types
|
|
46
|
+
- Comprehensive test coverage (132 tests, 93.15% line coverage)
|
|
47
|
+
|
|
48
|
+
### Security
|
|
49
|
+
|
|
50
|
+
- Covers 6 CWEs: 200, 352, 614, 693, 770, 942, 1333
|
|
51
|
+
- Maps to OWASP Top 10 2021: A01, A03, A05, A07
|
package/README.md
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
# eslint-plugin-express-security
|
|
2
|
+
|
|
3
|
+
**Feature-based security rules that AI assistants can actually understand and fix.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/eslint-plugin-express-security)
|
|
6
|
+
[](https://www.npmjs.com/package/eslint-plugin-express-security)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=express_security)
|
|
9
|
+
|
|
10
|
+
> **Express-first security:** This plugin provides comprehensive security rules for **Express.js** applications.
|
|
11
|
+
> With **8 security rules** mapped to OWASP Top 10, CWE and CVSS, it transforms your linter into an Express security auditor that AI assistants can understand and fix.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 💡 What you get
|
|
16
|
+
|
|
17
|
+
- **Express-focused coverage:** 8 rules targeting Express-specific vulnerabilities (CORS, CSRF, cookies, headers, rate limiting).
|
|
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 Top 10 Web 2021, CWE tagging, CVSS scoring in every finding for compliance mapping.
|
|
20
|
+
- **Tiered presets:** `recommended`, `strict`, `api`, `graphql` for fast policy rollout.
|
|
21
|
+
- **Middleware-aware:** Detects helmet, cors, csurf, express-rate-limit, body-parser patterns.
|
|
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/app.ts
|
|
28
|
+
18:5 error 🔒 CWE-942 OWASP:A05 CVSS:9.1 | Permissive CORS with wildcard origin | CRITICAL [SOC2,PCI-DSS]
|
|
29
|
+
Fix: Specify allowed origins: cors({ origin: ['https://your-app.com'] }) | https://owasp.org/...
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Each message includes:**
|
|
33
|
+
|
|
34
|
+
- 🔒 **CWE reference** - vulnerability classification
|
|
35
|
+
- 📋 **OWASP category** - 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 Top 10 Coverage Matrix
|
|
44
|
+
|
|
45
|
+
| OWASP Category | Coverage | Rules |
|
|
46
|
+
| ----------------------------- | :------: | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
+
| **A01:2021** Access Control | ✅ | `no-graphql-introspection-production` |
|
|
48
|
+
| **A03:2021** Injection | ✅ | `no-express-unsafe-regex-route` (ReDoS) |
|
|
49
|
+
| **A05:2021** Misconfiguration | ✅ | `require-helmet`, `no-permissive-cors`, `no-cors-credentials-wildcard`, `require-rate-limiting`, `require-express-body-parser-limits` |
|
|
50
|
+
| **A07:2021** Auth/Session | ✅ | `require-csrf-protection`, `no-insecure-cookie-options` |
|
|
51
|
+
|
|
52
|
+
> [!TIP]
|
|
53
|
+
> For **complete OWASP coverage**, combine with [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) which provides 78 additional rules covering all OWASP categories.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 🔐 8 Security Rules
|
|
58
|
+
|
|
59
|
+
💼 = Set in `recommended` | ⚠️ = Warns in `recommended` | 🔧 = Auto-fixable | 💡 = Suggestions
|
|
60
|
+
|
|
61
|
+
### Headers & CORS (4 rules)
|
|
62
|
+
|
|
63
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
64
|
+
| ------------------------------------------------------------------------- | ------- | ----- | ---- | -------------------------------------- | --- | --- | --- | --- |
|
|
65
|
+
| [require-helmet](#require-helmet) | CWE-693 | A05 | 7.1 | Require helmet() middleware | 💼 | | | |
|
|
66
|
+
| [no-permissive-cors](#no-permissive-cors) | CWE-942 | A05 | 9.1 | Detect wildcard CORS origins | 💼 | | | |
|
|
67
|
+
| [no-cors-credentials-wildcard](#no-cors-credentials-wildcard) | CWE-942 | A05 | 9.1 | Block credentials: true + origin: "\*" | 💼 | | | |
|
|
68
|
+
| [require-express-body-parser-limits](#require-express-body-parser-limits) | CWE-770 | A05 | 7.5 | Require body parser size limits | | ⚠️ | | |
|
|
69
|
+
|
|
70
|
+
### CSRF & Cookies (2 rules)
|
|
71
|
+
|
|
72
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
73
|
+
| --------------------------------------------------------- | ------- | ----- | ---- | ------------------------------ | --- | --- | --- | --- |
|
|
74
|
+
| [require-csrf-protection](#require-csrf-protection) | CWE-352 | A07 | 8.8 | Require CSRF middleware | | ⚠️ | | |
|
|
75
|
+
| [no-insecure-cookie-options](#no-insecure-cookie-options) | CWE-614 | A07 | 5.3 | Detect missing Secure/HttpOnly | 💼 | | | |
|
|
76
|
+
|
|
77
|
+
### Rate Limiting & DoS (2 rules)
|
|
78
|
+
|
|
79
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
80
|
+
| --------------------------------------------------------------- | -------- | ----- | ---- | -------------------------------- | --- | --- | --- | --- |
|
|
81
|
+
| [require-rate-limiting](#require-rate-limiting) | CWE-770 | A05 | 7.5 | Require rate limiting middleware | | ⚠️ | | |
|
|
82
|
+
| [no-express-unsafe-regex-route](#no-express-unsafe-regex-route) | CWE-1333 | A03 | 7.5 | Detect ReDoS in route patterns | 💼 | | | |
|
|
83
|
+
|
|
84
|
+
### GraphQL (1 rule)
|
|
85
|
+
|
|
86
|
+
| Rule | CWE | OWASP | CVSS | Description | 💼 | ⚠️ | 🔧 | 💡 |
|
|
87
|
+
| --------------------------------------------------------------------------- | ------- | ----- | ---- | ------------------------------------- | --- | --- | --- | --- |
|
|
88
|
+
| [no-graphql-introspection-production](#no-graphql-introspection-production) | CWE-200 | A01 | 5.3 | Disable GraphQL introspection in prod | | ⚠️ | | |
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 🔍 Rule Details
|
|
93
|
+
|
|
94
|
+
### `require-helmet`
|
|
95
|
+
|
|
96
|
+
Requires helmet() middleware for security headers.
|
|
97
|
+
|
|
98
|
+
**❌ Incorrect**
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
const app = express();
|
|
102
|
+
app.get('/', handler); // No helmet middleware
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**✅ Correct**
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
import helmet from 'helmet';
|
|
109
|
+
|
|
110
|
+
const app = express();
|
|
111
|
+
app.use(helmet()); // Adds 11+ security headers
|
|
112
|
+
app.get('/', handler);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### `no-permissive-cors`
|
|
118
|
+
|
|
119
|
+
Detects wildcard CORS configuration that allows any origin.
|
|
120
|
+
|
|
121
|
+
**❌ Incorrect**
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
app.use(cors({ origin: '*' }));
|
|
125
|
+
app.use(cors()); // Defaults to '*'
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**✅ Correct**
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
app.use(
|
|
132
|
+
cors({
|
|
133
|
+
origin: ['https://your-app.com', 'https://admin.your-app.com'],
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Or use dynamic validation
|
|
138
|
+
app.use(
|
|
139
|
+
cors({
|
|
140
|
+
origin: (origin, callback) => {
|
|
141
|
+
if (allowedOrigins.includes(origin)) {
|
|
142
|
+
callback(null, true);
|
|
143
|
+
} else {
|
|
144
|
+
callback(new Error('Not allowed by CORS'));
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### `no-cors-credentials-wildcard`
|
|
154
|
+
|
|
155
|
+
Blocks the dangerous combination of `credentials: true` with wildcard origins.
|
|
156
|
+
|
|
157
|
+
**❌ Incorrect**
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
// CRITICAL: This exposes credentials to any origin!
|
|
161
|
+
app.use(
|
|
162
|
+
cors({
|
|
163
|
+
origin: '*',
|
|
164
|
+
credentials: true,
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**✅ Correct**
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
app.use(
|
|
173
|
+
cors({
|
|
174
|
+
origin: 'https://your-app.com',
|
|
175
|
+
credentials: true,
|
|
176
|
+
}),
|
|
177
|
+
);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### `require-csrf-protection`
|
|
183
|
+
|
|
184
|
+
Requires CSRF protection middleware for state-changing routes.
|
|
185
|
+
|
|
186
|
+
**❌ Incorrect**
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
app.post('/api/transfer', handler); // No CSRF protection
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**✅ Correct**
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
import csurf from 'csurf';
|
|
196
|
+
|
|
197
|
+
app.use(csurf({ cookie: true }));
|
|
198
|
+
app.post('/api/transfer', handler);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### `no-insecure-cookie-options`
|
|
204
|
+
|
|
205
|
+
Detects cookies missing Secure, HttpOnly, or SameSite attributes.
|
|
206
|
+
|
|
207
|
+
**❌ Incorrect**
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
res.cookie('session', token); // Missing security attributes
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**✅ Correct**
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
res.cookie('session', token, {
|
|
217
|
+
httpOnly: true,
|
|
218
|
+
secure: true,
|
|
219
|
+
sameSite: 'strict',
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
### `require-rate-limiting`
|
|
226
|
+
|
|
227
|
+
Requires rate limiting middleware to prevent DoS attacks.
|
|
228
|
+
|
|
229
|
+
**❌ Incorrect**
|
|
230
|
+
|
|
231
|
+
```javascript
|
|
232
|
+
app.post('/api/login', handler); // No rate limiting
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**✅ Correct**
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
import rateLimit from 'express-rate-limit';
|
|
239
|
+
|
|
240
|
+
const limiter = rateLimit({
|
|
241
|
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
242
|
+
max: 100, // limit each IP to 100 requests per windowMs
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
app.use('/api/', limiter);
|
|
246
|
+
app.post('/api/login', handler);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
### `require-express-body-parser-limits`
|
|
252
|
+
|
|
253
|
+
Requires size limits on body parser to prevent DoS via large payloads.
|
|
254
|
+
|
|
255
|
+
**❌ Incorrect**
|
|
256
|
+
|
|
257
|
+
```javascript
|
|
258
|
+
app.use(express.json()); // No size limit
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**✅ Correct**
|
|
262
|
+
|
|
263
|
+
```javascript
|
|
264
|
+
app.use(express.json({ limit: '100kb' }));
|
|
265
|
+
app.use(express.urlencoded({ limit: '100kb', extended: true }));
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### `no-express-unsafe-regex-route`
|
|
271
|
+
|
|
272
|
+
Detects ReDoS-vulnerable regex patterns in Express routes.
|
|
273
|
+
|
|
274
|
+
**❌ Incorrect**
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
// Catastrophic backtracking possible
|
|
278
|
+
app.get('/api/:id(\\d+)+', handler);
|
|
279
|
+
app.get(/^\/user\/(.*)$/, handler);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
**✅ Correct**
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
app.get('/api/:id(\\d{1,10})', handler); // Bounded
|
|
286
|
+
app.get('/user/:userId', handler); // Named parameter
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### `no-graphql-introspection-production`
|
|
292
|
+
|
|
293
|
+
Disables GraphQL introspection queries in production.
|
|
294
|
+
|
|
295
|
+
**❌ Incorrect**
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
const server = new ApolloServer({
|
|
299
|
+
typeDefs,
|
|
300
|
+
resolvers,
|
|
301
|
+
introspection: true, // Exposes schema in production
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**✅ Correct**
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
const server = new ApolloServer({
|
|
309
|
+
typeDefs,
|
|
310
|
+
resolvers,
|
|
311
|
+
introspection: process.env.NODE_ENV !== 'production',
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## 🚀 Quick Start
|
|
318
|
+
|
|
319
|
+
### ESLint Flat Config (Recommended)
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
// eslint.config.js
|
|
323
|
+
import expressSecurity from 'eslint-plugin-express-security';
|
|
324
|
+
|
|
325
|
+
export default [
|
|
326
|
+
expressSecurity.configs.recommended,
|
|
327
|
+
// ... other configs
|
|
328
|
+
];
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Strict Mode
|
|
332
|
+
|
|
333
|
+
```javascript
|
|
334
|
+
import expressSecurity from 'eslint-plugin-express-security';
|
|
335
|
+
|
|
336
|
+
export default [expressSecurity.configs.strict];
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## 📋 Available Presets
|
|
342
|
+
|
|
343
|
+
| Preset | Description |
|
|
344
|
+
| ----------------- | ----------------------------------------------------------------------- |
|
|
345
|
+
| **`recommended`** | Balanced security for Express projects (critical as error, others warn) |
|
|
346
|
+
| **`strict`** | Maximum security enforcement (all rules as errors) |
|
|
347
|
+
| **`api`** | HTTP/API security rules only (CORS, CSRF, cookies, rate limiting) |
|
|
348
|
+
| **`graphql`** | GraphQL-specific security rules only |
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 🏢 Enterprise Integration Example
|
|
353
|
+
|
|
354
|
+
```javascript
|
|
355
|
+
// eslint.config.js
|
|
356
|
+
import expressSecurity from 'eslint-plugin-express-security';
|
|
357
|
+
|
|
358
|
+
export default [
|
|
359
|
+
// Baseline for all Express apps
|
|
360
|
+
expressSecurity.configs.recommended,
|
|
361
|
+
|
|
362
|
+
// Strict mode for payment/auth services
|
|
363
|
+
{
|
|
364
|
+
files: ['services/payments/**', 'services/auth/**'],
|
|
365
|
+
...expressSecurity.configs.strict,
|
|
366
|
+
},
|
|
367
|
+
|
|
368
|
+
// GraphQL security for GraphQL servers
|
|
369
|
+
{
|
|
370
|
+
files: ['services/graphql/**'],
|
|
371
|
+
...expressSecurity.configs.graphql,
|
|
372
|
+
},
|
|
373
|
+
];
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## 🤖 LLM & AI Integration
|
|
379
|
+
|
|
380
|
+
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:
|
|
381
|
+
|
|
382
|
+
- Understand the exact vulnerability type via CWE references
|
|
383
|
+
- Apply the correct fix using structured guidance
|
|
384
|
+
- Provide educational context to developers
|
|
385
|
+
|
|
386
|
+
```json
|
|
387
|
+
// .cursor/mcp.json
|
|
388
|
+
{
|
|
389
|
+
"mcpServers": {
|
|
390
|
+
"eslint": {
|
|
391
|
+
"command": "npx",
|
|
392
|
+
"args": ["@eslint/mcp@latest"]
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## 🔗 Related ESLint Plugins
|
|
401
|
+
|
|
402
|
+
Part of the **Forge-JS ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
403
|
+
|
|
404
|
+
| Plugin | Description | Rules |
|
|
405
|
+
| ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | :---: |
|
|
406
|
+
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | Framework-agnostic security (OWASP Web + Mobile Top 10) | 78 |
|
|
407
|
+
| [`eslint-plugin-lambda-security`](https://www.npmjs.com/package/eslint-plugin-lambda-security) | AWS Lambda/Middy security (API Gateway, headers, validation) | 5 |
|
|
408
|
+
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security (guards, validation pipes, throttler) | 🔜 |
|
|
409
|
+
| [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) | JWT security (algorithm confusion, weak secrets, claims validation) | 13 |
|
|
410
|
+
| [`eslint-plugin-crypto`](https://www.npmjs.com/package/eslint-plugin-crypto) | Cryptographic best practices (weak algorithms, key handling, CVE-specific) | 24 |
|
|
411
|
+
| [`eslint-plugin-pg`](https://www.npmjs.com/package/eslint-plugin-pg) | PostgreSQL/node-postgres security and best practices | 13 |
|
|
412
|
+
| [`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 |
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## 🔒 Privacy
|
|
417
|
+
|
|
418
|
+
This plugin runs **100% locally**. No data ever leaves your machine.
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## 📄 License
|
|
423
|
+
|
|
424
|
+
MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-express-security",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Security-focused ESLint plugin for Express.js applications. Detects insecure cookies, missing security headers, CORS misconfigurations, CSRF vulnerabilities, GraphQL security 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-express-security/README.md",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git",
|
|
24
|
+
"directory": "packages/eslint-plugin-express-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
|
+
"express",
|
|
45
|
+
"expressjs",
|
|
46
|
+
"security",
|
|
47
|
+
"cookies",
|
|
48
|
+
"helmet",
|
|
49
|
+
"cors",
|
|
50
|
+
"csrf",
|
|
51
|
+
"graphql",
|
|
52
|
+
"rate-limiting",
|
|
53
|
+
"headers",
|
|
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
|
+
"express": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"helmet": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"cors": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"csurf": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"express-rate-limit": {
|
|
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
|
+
}
|