eslint-plugin-express-security 1.2.2 → 1.3.0
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 +105 -0
- package/README.md +47 -25
- package/package.json +21 -5
- package/src/index.js +19 -1
- package/src/oxlint.d.ts +20 -0
- package/src/oxlint.js +21 -0
- package/src/rules/no-cors-credentials-wildcard/index.js +3 -0
- package/src/rules/no-exposed-debug-endpoints/index.js +4 -0
- package/src/rules/no-express-unsafe-regex-route/index.js +5 -2
- package/src/rules/no-graphql-introspection-production/index.js +3 -0
- package/src/rules/no-insecure-cookie-options/index.js +3 -0
- package/src/rules/no-missing-cors-check/index.d.ts +28 -0
- package/src/rules/no-missing-cors-check/index.js +402 -0
- package/src/rules/no-missing-csrf-protection/index.d.ts +30 -0
- package/src/rules/no-missing-csrf-protection/index.js +188 -0
- package/src/rules/no-missing-security-headers/index.d.ts +26 -0
- package/src/rules/no-missing-security-headers/index.js +226 -0
- package/src/rules/no-permissive-cors/index.js +3 -0
- package/src/rules/no-user-controlled-redirect/index.d.ts +44 -0
- package/src/rules/no-user-controlled-redirect/index.js +142 -0
- package/src/rules/require-csrf-protection/index.js +3 -0
- package/src/rules/require-express-body-parser-limits/index.js +5 -2
- package/src/rules/require-helmet/index.js +4 -0
- package/src/rules/require-rate-limiting/index.js +3 -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
|
+
npm 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,105 @@
|
|
|
1
|
+
## [1.2.3] - 2026-02-08
|
|
2
|
+
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#169](https://github.com/ofri-peretz/eslint/pull/169) [`ae39ec5`](https://github.com/ofri-peretz/eslint/commit/ae39ec52bf619351e6217a823014fc05bb97d618) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - feat: add `no-user-controlled-redirect` rule — structural CWE-601 open redirect detection
|
|
8
|
+
|
|
9
|
+
Fires on `res.redirect(req.query.*)`, `res.redirect(req.body.*)`, and `res.redirect(req.params.*)` — an AST-structural check that passes the naming-heuristic litmus test (rename `res`/`req` to any identifier and the rule still fires, because detection is on the member-access chain, not on variable names). Severity: `error` in flagship config.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#143](https://github.com/ofri-peretz/eslint/pull/143) [`213cde1`](https://github.com/ofri-peretz/eslint/commit/213cde190ff2aea49ca7c1b533170940f879d9b4) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - fix(no-missing-null-checks): eliminate 53 false positives via three new narrowing patterns
|
|
14
|
+
|
|
15
|
+
Rules that were recognized as null guards are now correctly identified as safe:
|
|
16
|
+
1. **Truthy if guard** — `if (obj) { obj.prop }` — direct truthy check proves non-null. Also covers chains: `if (response)` protects `response.data.items`.
|
|
17
|
+
2. **Short-circuit AND** — `obj && obj.prop` — right side of `&&` only runs when left is truthy.
|
|
18
|
+
3. **Ternary consequent** — `obj ? obj.prop : fallback` — truthy test guards the consequent.
|
|
19
|
+
|
|
20
|
+
Also: bumped `beforeAll` timeout to 30 seconds in 7 compatibility test files (`__compatibility__/*.spec.ts`). Native-addon packages routinely exceed the previous 10-second default on a cold ESM load.
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`736a5fe`](https://github.com/ofri-peretz/eslint/commit/736a5fed47e673f6157ea900b29fe2a54e4bc7df)]:
|
|
23
|
+
- @interlace/eslint-devkit@1.4.1
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- align codecov component IDs with full package names ([2831b968](https://github.com/ofri-peretz/eslint/commit/2831b968))
|
|
28
|
+
|
|
29
|
+
### Documentation
|
|
30
|
+
|
|
31
|
+
- fix changelog header format across all packages ([c3a15082](https://github.com/ofri-peretz/eslint/commit/c3a15082))
|
|
32
|
+
|
|
33
|
+
### ❤️ Thank You
|
|
34
|
+
|
|
35
|
+
- Ofri Peretz
|
|
36
|
+
|
|
37
|
+
## [1.2.2] - 2026-02-06
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
- align codecov component names and update docs components ([0a59a86c](https://github.com/ofri-peretz/eslint/commit/0a59a86c))
|
|
42
|
+
|
|
43
|
+
### ❤️ Thank You
|
|
44
|
+
|
|
45
|
+
- Ofri Peretz
|
|
46
|
+
|
|
47
|
+
## [1.2.1] - 2026-02-02
|
|
48
|
+
|
|
49
|
+
This was a version bump only for eslint-plugin-express-security to align it with other projects, there were no code changes.
|
|
50
|
+
|
|
51
|
+
# Changelog
|
|
52
|
+
|
|
53
|
+
All notable changes to `eslint-plugin-express-security` will be documented in this file.
|
|
54
|
+
|
|
55
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
56
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
57
|
+
|
|
58
|
+
### Documentation
|
|
59
|
+
|
|
60
|
+
- 📘 Launched new documentation site: [eslint.interlace.tools](https://eslint.interlace.tools/)
|
|
61
|
+
|
|
62
|
+
## [1.0.0] - 2025-12-29
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
|
|
66
|
+
#### Headers & CORS Rules (4)
|
|
67
|
+
|
|
68
|
+
- `require-helmet` - Require helmet middleware for security headers (CWE-693)
|
|
69
|
+
- `no-permissive-cors` - Detect wildcard CORS origins (CWE-942)
|
|
70
|
+
- `no-cors-credentials-wildcard` - Block credentials: true with wildcard origin (CWE-942)
|
|
71
|
+
- `require-express-body-parser-limits` - Require body parser size limits (CWE-770)
|
|
72
|
+
|
|
73
|
+
#### CSRF & Cookies Rules (2)
|
|
74
|
+
|
|
75
|
+
- `require-csrf-protection` - Require CSRF middleware for state-changing routes (CWE-352)
|
|
76
|
+
- `no-insecure-cookie-options` - Detect missing Secure/HttpOnly cookie attributes (CWE-614)
|
|
77
|
+
|
|
78
|
+
#### Rate Limiting & DoS Rules (2)
|
|
79
|
+
|
|
80
|
+
- `require-rate-limiting` - Require rate limiting middleware (CWE-770)
|
|
81
|
+
- `no-express-unsafe-regex-route` - Detect ReDoS-vulnerable regex patterns (CWE-1333)
|
|
82
|
+
|
|
83
|
+
#### GraphQL Rules (1)
|
|
84
|
+
|
|
85
|
+
- `no-graphql-introspection-production` - Disable GraphQL introspection in production (CWE-200)
|
|
86
|
+
|
|
87
|
+
#### Presets (4)
|
|
88
|
+
|
|
89
|
+
- `recommended` - Balanced security defaults
|
|
90
|
+
- `strict` - All 9 rules as errors
|
|
91
|
+
- `api` - HTTP/API security rules only
|
|
92
|
+
- `graphql` - GraphQL-specific rules only
|
|
93
|
+
|
|
94
|
+
#### Features
|
|
95
|
+
|
|
96
|
+
- LLM-optimized error messages with CWE references
|
|
97
|
+
- OWASP Top 10 2021 alignment (A01, A03, A05, A07)
|
|
98
|
+
- Middleware-aware detection (helmet, cors, csurf, express-rate-limit)
|
|
99
|
+
- TypeScript support with exported option types
|
|
100
|
+
- Comprehensive test coverage (132 tests, 93.15% line coverage)
|
|
101
|
+
|
|
102
|
+
### Security
|
|
103
|
+
|
|
104
|
+
- Covers 6 CWEs: 200, 352, 614, 693, 770, 942, 1333
|
|
105
|
+
- Maps to OWASP Top 10 2021: A01, A03, A05, A07
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://eslint.interlace.tools" target="blank"><img src="https://eslint.interlace.tools/eslint-interlace-logo-light.svg" alt="ESLint Interlace Logo" width="120" /></a>
|
|
2
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security" target="blank"><img src="https://eslint.interlace.tools/eslint-interlace-logo-light.svg" alt="ESLint Interlace Logo" width="120" /></a>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
|
+
> ⭐ If this plugin caught a real bug for you, [**star the repo**](https://github.com/ofri-peretz/eslint) — it's the signal that keeps these rules maintained.
|
|
18
|
+
|
|
17
19
|
## Description
|
|
18
20
|
|
|
19
21
|
This plugin provides Comprehensive security rules for Express.js applications, mapping to OWASP Top 10.
|
|
20
|
-
By using this plugin, you can proactively identify and mitigate security risks across your entire codebase.
|
|
21
22
|
|
|
22
23
|
## Philosophy
|
|
23
24
|
|
|
@@ -25,12 +26,12 @@ By using this plugin, you can proactively identify and mitigate security risks a
|
|
|
25
26
|
|
|
26
27
|
## Getting Started
|
|
27
28
|
|
|
28
|
-
- To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-express-security), visit [eslint.interlace.tools](https://eslint.interlace.tools). 📚
|
|
29
|
-
- 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-express-security), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools). 📚
|
|
30
|
-
- [가이드](https://eslint.interlace.tools/docs/security/plugin-express-security) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools)에서 확인하실 수 있습니다. 📚
|
|
31
|
-
- [ガイド](https://eslint.interlace.tools/docs/security/plugin-express-security)は [eslint.interlace.tools](https://eslint.interlace.tools)でご確認ください。 📚
|
|
32
|
-
- Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-express-security), visita [eslint.interlace.tools](https://eslint.interlace.tools). 📚
|
|
33
|
-
- للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-express-security)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools). 📚
|
|
29
|
+
- To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security). 📚
|
|
30
|
+
- 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security). 📚
|
|
31
|
+
- [가이드](https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security)에서 확인하실 수 있습니다. 📚
|
|
32
|
+
- [ガイド](https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security)は [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security)でご確認ください。 📚
|
|
33
|
+
- Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security), visita [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security). 📚
|
|
34
|
+
- للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security). 📚
|
|
34
35
|
|
|
35
36
|
```bash
|
|
36
37
|
npm install eslint-plugin-express-security --save-dev
|
|
@@ -54,6 +55,14 @@ npm install eslint-plugin-express-security --save-dev
|
|
|
54
55
|
|
|
55
56
|
---
|
|
56
57
|
|
|
58
|
+
## 📦 Compatibility
|
|
59
|
+
| Package | Version |
|
|
60
|
+
| :--- | :--- |
|
|
61
|
+
| ESLint | `^8.0.0 \|\| ^9.0.0 \|\| ^10.0.0` |
|
|
62
|
+
| Node.js | `>=18.0.0` |
|
|
63
|
+
|
|
64
|
+
See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) — current ecosystem share data, the 20% gate, and the forward-looking exception that covers v10.
|
|
65
|
+
|
|
57
66
|
## Rules
|
|
58
67
|
|
|
59
68
|
**Legend**
|
|
@@ -61,24 +70,28 @@ npm install eslint-plugin-express-security --save-dev
|
|
|
61
70
|
| Icon | Description |
|
|
62
71
|
| :---: | :--- |
|
|
63
72
|
| 💼 | **Recommended**: Included in the recommended preset. |
|
|
64
|
-
| ⚠️ | **Warns**: Set
|
|
73
|
+
| ⚠️ | **Warns**: Set to warn in recommended preset. |
|
|
65
74
|
| 🔧 | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
|
|
66
75
|
| 💡 | **Suggestions**: Providing code suggestions in IDE. |
|
|
67
76
|
| 🚫 | **Deprecated**: This rule is deprecated. |
|
|
68
|
-
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
| [no-
|
|
76
|
-
| [no-
|
|
77
|
-
| [
|
|
78
|
-
| [
|
|
79
|
-
| [
|
|
80
|
-
| [
|
|
81
|
-
|
|
77
|
+
| 🟢 | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
|
|
78
|
+
| 🟡 | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
|
|
79
|
+
| 🟠 | **Type-aware (graceful)**: requires TS program; silent without it. |
|
|
80
|
+
|
|
81
|
+
<!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
|
|
82
|
+
| Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
|
|
83
|
+
| :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
|
84
|
+
| [no-cors-credentials-wildcard](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/no-cors-credentials-wildcard?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-942 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
85
|
+
| [no-exposed-debug-endpoints](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/no-exposed-debug-endpoints?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-489 | A05:2021 | | Identifies potential debug, administration, or testing endpoints that are often left exposed in production… | 🟢 | | | | | |
|
|
86
|
+
| [no-express-unsafe-regex-route](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/no-express-unsafe-regex-route?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-1333 | | | This rule detects Regular Expression Denial of Service (ReDoS) vulnerabilities in Express route patterns | 🟢 | | | | | |
|
|
87
|
+
| [no-graphql-introspection-production](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/no-graphql-introspection-production?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-200 | | | This rule detects GraphQL servers with introspection enabled in production | 🟢 | | | | | |
|
|
88
|
+
| [no-insecure-cookie-options](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/no-insecure-cookie-options?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-614 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | 💼 | | | | |
|
|
89
|
+
| [no-permissive-cors](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/no-permissive-cors?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-942 | | | Detects overly permissive CORS configurations in Express.js applications | 🟢 | 💼 | | | | |
|
|
90
|
+
| [require-csrf-protection](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/require-csrf-protection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-352 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | 💼 | | | | |
|
|
91
|
+
| [require-express-body-parser-limits](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/require-express-body-parser-limits?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-400 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
92
|
+
| [require-helmet](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/require-helmet?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-693 | | | This rule detects Express.js applications that are missing the helmet middleware | 🟢 | 💼 | | | | |
|
|
93
|
+
| [require-rate-limiting](https://eslint.interlace.tools/docs/security/plugin-express-security/rules/require-rate-limiting?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security) | CWE-770 | | | This rule detects Express.js applications missing rate limiting middleware | 🟢 | 💼 | | | | |
|
|
94
|
+
<!-- AUTO-GENERATED:RULES_TABLE:END -->
|
|
82
95
|
## 🔗 Related ESLint Plugins
|
|
83
96
|
|
|
84
97
|
Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
@@ -87,7 +100,7 @@ Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with L
|
|
|
87
100
|
| :--- | :---: | :--- |
|
|
88
101
|
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [](https://www.npmjs.com/package/eslint-plugin-secure-coding) | General security rules & OWASP guidelines. |
|
|
89
102
|
| [`eslint-plugin-pg`](https://www.npmjs.com/package/eslint-plugin-pg) | [](https://www.npmjs.com/package/eslint-plugin-pg) | PostgreSQL security & best practices. |
|
|
90
|
-
| [`eslint-plugin-
|
|
103
|
+
| [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) | [](https://www.npmjs.com/package/eslint-plugin-node-security) | Node.js core-module security (fs, child_process, vm, crypto, Buffer). |
|
|
91
104
|
| [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) | [](https://www.npmjs.com/package/eslint-plugin-jwt) | JWT security & best practices. |
|
|
92
105
|
| [`eslint-plugin-browser-security`](https://www.npmjs.com/package/eslint-plugin-browser-security) | [](https://www.npmjs.com/package/eslint-plugin-browser-security) | Browser-specific security & XSS prevention. |
|
|
93
106
|
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | [](https://www.npmjs.com/package/eslint-plugin-express-security) | Express.js security hardening rules. |
|
|
@@ -97,10 +110,19 @@ Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with L
|
|
|
97
110
|
| [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security hardening. |
|
|
98
111
|
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://www.npmjs.com/package/eslint-plugin-import-next) | Next-gen import sorting & architecture. |
|
|
99
112
|
|
|
113
|
+
<!-- INTERLACE:STAR_CTA:START -->
|
|
114
|
+
## ⭐ Support & follow
|
|
115
|
+
|
|
116
|
+
If this plugin caught a real bug for you, **[star the repo](https://github.com/ofri-peretz/eslint)** — stars are the signal that keeps the Interlace ESLint ecosystem maintained — and **[follow the writeups on Dev.to](https://dev.to/ofri-peretz)** for the benchmarks and security research behind these rules.
|
|
117
|
+
|
|
118
|
+
[](https://github.com/ofri-peretz/eslint)
|
|
119
|
+
|
|
120
|
+
<!-- INTERLACE:STAR_CTA:END -->
|
|
121
|
+
|
|
100
122
|
## 📄 License
|
|
101
123
|
|
|
102
124
|
MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
103
125
|
|
|
104
126
|
<p align="center">
|
|
105
|
-
<a href="https://eslint.interlace.tools/docs/security/plugin-express-security"><img src="https://eslint.interlace.tools/images/og-express-security.png" alt="ESLint Interlace Plugin" width="100%" /></a>
|
|
127
|
+
<a href="https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-express-security"><img src="https://eslint.interlace.tools/images/og-express-security.png" alt="ESLint Interlace Plugin" width="100%" /></a>
|
|
106
128
|
</p>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-express-security",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
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
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
"./types": {
|
|
14
14
|
"types": "./src/types/index.d.ts",
|
|
15
15
|
"default": "./src/types/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./oxlint": {
|
|
18
|
+
"types": "./src/oxlint.d.ts",
|
|
19
|
+
"default": "./src/oxlint.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"author": "Ofri Peretz <ofriperetzdev@gmail.com>",
|
|
19
23
|
"license": "MIT",
|
|
20
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://eslint.interlace.tools/docs/security/plugin-express-security?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-express-security",
|
|
21
25
|
"repository": {
|
|
22
26
|
"type": "git",
|
|
23
27
|
"url": "https://github.com/ofri-peretz/eslint",
|
|
@@ -64,9 +68,11 @@
|
|
|
64
68
|
},
|
|
65
69
|
"dependencies": {
|
|
66
70
|
"tslib": "^2.3.0",
|
|
67
|
-
"@interlace/eslint-devkit": "^1.
|
|
71
|
+
"@interlace/eslint-devkit": "^1.4.1"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0"
|
|
68
75
|
},
|
|
69
|
-
"peerDependencies": {},
|
|
70
76
|
"peerDependenciesMeta": {
|
|
71
77
|
"express": {
|
|
72
78
|
"optional": true
|
|
@@ -87,5 +93,15 @@
|
|
|
87
93
|
"devDependencies": {
|
|
88
94
|
"@typescript-eslint/parser": "^8.46.2",
|
|
89
95
|
"@typescript-eslint/rule-tester": "^8.46.2"
|
|
96
|
+
},
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "tsx ../../scripts/build-package.ts",
|
|
99
|
+
"test": "vitest run",
|
|
100
|
+
"test:coverage": "vitest run --coverage",
|
|
101
|
+
"typecheck": "tsc -p tsconfig.lib.json --noEmit"
|
|
102
|
+
},
|
|
103
|
+
"funding": {
|
|
104
|
+
"type": "github",
|
|
105
|
+
"url": "https://github.com/ofri-peretz/eslint"
|
|
90
106
|
}
|
|
91
|
-
}
|
|
107
|
+
}
|
package/src/index.js
CHANGED
|
@@ -21,6 +21,12 @@ const no_cors_credentials_wildcard_1 = require("./rules/no-cors-credentials-wild
|
|
|
21
21
|
const require_express_body_parser_limits_1 = require("./rules/require-express-body-parser-limits");
|
|
22
22
|
const no_express_unsafe_regex_route_1 = require("./rules/no-express-unsafe-regex-route");
|
|
23
23
|
const no_exposed_debug_endpoints_1 = require("./rules/no-exposed-debug-endpoints");
|
|
24
|
+
// Migrated from browser-security — these check server-side Express patterns, not browser APIs
|
|
25
|
+
const no_missing_cors_check_1 = require("./rules/no-missing-cors-check");
|
|
26
|
+
const no_missing_csrf_protection_1 = require("./rules/no-missing-csrf-protection");
|
|
27
|
+
const no_missing_security_headers_1 = require("./rules/no-missing-security-headers");
|
|
28
|
+
// Structural redirect safety — structural-api, enforcement-grade
|
|
29
|
+
const no_user_controlled_redirect_1 = require("./rules/no-user-controlled-redirect");
|
|
24
30
|
/**
|
|
25
31
|
* Collection of all Express security ESLint rules
|
|
26
32
|
*/
|
|
@@ -40,6 +46,12 @@ exports.rules = {
|
|
|
40
46
|
'require-express-body-parser-limits': require_express_body_parser_limits_1.requireExpressBodyParserLimits,
|
|
41
47
|
'no-express-unsafe-regex-route': no_express_unsafe_regex_route_1.noExpressUnsafeRegexRoute,
|
|
42
48
|
'no-exposed-debug-endpoints': no_exposed_debug_endpoints_1.noExposedDebugEndpoints,
|
|
49
|
+
// Migrated from browser-security (server-side Express checks)
|
|
50
|
+
'no-missing-cors-check': no_missing_cors_check_1.noMissingCorsCheck,
|
|
51
|
+
'no-missing-csrf-protection': no_missing_csrf_protection_1.noMissingCsrfProtection,
|
|
52
|
+
'no-missing-security-headers': no_missing_security_headers_1.noMissingSecurityHeaders,
|
|
53
|
+
// Open redirect — structural-api (fires on res.redirect(req.query.*) AST shape)
|
|
54
|
+
'no-user-controlled-redirect': no_user_controlled_redirect_1.noUserControlledRedirect,
|
|
43
55
|
};
|
|
44
56
|
/**
|
|
45
57
|
* ESLint Plugin object
|
|
@@ -47,7 +59,7 @@ exports.rules = {
|
|
|
47
59
|
exports.plugin = {
|
|
48
60
|
meta: {
|
|
49
61
|
name: 'eslint-plugin-express-security',
|
|
50
|
-
version: '
|
|
62
|
+
version: '1.3.0',
|
|
51
63
|
},
|
|
52
64
|
rules: exports.rules,
|
|
53
65
|
};
|
|
@@ -70,6 +82,12 @@ const recommendedRules = {
|
|
|
70
82
|
'express-security/require-express-body-parser-limits': 'warn',
|
|
71
83
|
'express-security/no-express-unsafe-regex-route': 'error',
|
|
72
84
|
'express-security/no-exposed-debug-endpoints': 'error',
|
|
85
|
+
// Migrated from browser-security
|
|
86
|
+
'express-security/no-missing-cors-check': 'warn',
|
|
87
|
+
'express-security/no-missing-csrf-protection': 'warn',
|
|
88
|
+
'express-security/no-missing-security-headers': 'warn',
|
|
89
|
+
// Open redirect — structural, CWE-601
|
|
90
|
+
'express-security/no-user-controlled-redirect': 'error',
|
|
73
91
|
};
|
|
74
92
|
/**
|
|
75
93
|
* Preset configurations for Express security rules
|
package/src/oxlint.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* oxlint sub-export.
|
|
8
|
+
*
|
|
9
|
+
* Consumers wire oxlint to this entry via:
|
|
10
|
+
* { "jsPlugins": ["eslint-plugin-express-security/oxlint"] }
|
|
11
|
+
*
|
|
12
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-express-security/oxlint')` and reads
|
|
13
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
14
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
15
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
16
|
+
*
|
|
17
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
18
|
+
*/
|
|
19
|
+
import { plugin } from './index';
|
|
20
|
+
export = plugin;
|
package/src/oxlint.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* oxlint sub-export.
|
|
9
|
+
*
|
|
10
|
+
* Consumers wire oxlint to this entry via:
|
|
11
|
+
* { "jsPlugins": ["eslint-plugin-express-security/oxlint"] }
|
|
12
|
+
*
|
|
13
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-express-security/oxlint')` and reads
|
|
14
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
15
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
16
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
17
|
+
*
|
|
18
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
19
|
+
*/
|
|
20
|
+
const index_1 = require("./index");
|
|
21
|
+
module.exports = index_1.plugin;
|
|
@@ -71,7 +71,10 @@ exports.noCorsCredentialsWildcard = (0, eslint_devkit_1.createRule)({
|
|
|
71
71
|
meta: {
|
|
72
72
|
type: 'problem',
|
|
73
73
|
docs: {
|
|
74
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-cors-credentials-wildcard.md',
|
|
74
75
|
description: 'Disallow credentials: true with wildcard CORS origin (CVE-2024-25124)',
|
|
76
|
+
cwe: 'CWE-942',
|
|
77
|
+
cvss: 9.5,
|
|
75
78
|
},
|
|
76
79
|
hasSuggestions: true,
|
|
77
80
|
messages: {
|
|
@@ -16,7 +16,10 @@ exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
|
|
|
16
16
|
meta: {
|
|
17
17
|
type: 'problem',
|
|
18
18
|
docs: {
|
|
19
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-exposed-debug-endpoints.md',
|
|
19
20
|
description: 'Detect debug endpoints without auth in Express applications',
|
|
21
|
+
cwe: 'CWE-489',
|
|
22
|
+
cvss: 7.5,
|
|
20
23
|
},
|
|
21
24
|
messages: {
|
|
22
25
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -61,6 +64,7 @@ exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
|
|
|
61
64
|
function report(node) {
|
|
62
65
|
context.report({ node, messageId: 'violationDetected' });
|
|
63
66
|
}
|
|
67
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
64
68
|
const isExpressRouteCall = (node) => {
|
|
65
69
|
return (node.callee.type === 'MemberExpression' &&
|
|
66
70
|
node.callee.object.type === 'Identifier' &&
|
|
@@ -10,7 +10,7 @@ const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
|
10
10
|
/**
|
|
11
11
|
* HTTP method names used for routing
|
|
12
12
|
*/
|
|
13
|
-
const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'all', 'use'];
|
|
13
|
+
const HTTP_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'all', 'use']);
|
|
14
14
|
/**
|
|
15
15
|
* Patterns that indicate potential ReDoS vulnerability
|
|
16
16
|
* These are simplified heuristics - a full ReDoS detector would be more complex
|
|
@@ -50,7 +50,10 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
|
|
|
50
50
|
meta: {
|
|
51
51
|
type: 'problem',
|
|
52
52
|
docs: {
|
|
53
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-express-unsafe-regex-route.md',
|
|
53
54
|
description: 'Disallow ReDoS-vulnerable regular expressions in Express.js route patterns',
|
|
55
|
+
cwe: 'CWE-1333',
|
|
56
|
+
cvss: 7.5,
|
|
54
57
|
},
|
|
55
58
|
hasSuggestions: true,
|
|
56
59
|
messages: {
|
|
@@ -116,7 +119,7 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
|
|
|
116
119
|
if (property.type !== 'Identifier') {
|
|
117
120
|
return;
|
|
118
121
|
}
|
|
119
|
-
if (!HTTP_METHODS.
|
|
122
|
+
if (!HTTP_METHODS.has(property.name)) {
|
|
120
123
|
return;
|
|
121
124
|
}
|
|
122
125
|
// Check the route argument (first argument)
|
|
@@ -39,7 +39,10 @@ exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
|
|
|
39
39
|
meta: {
|
|
40
40
|
type: 'problem',
|
|
41
41
|
docs: {
|
|
42
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-graphql-introspection-production.md',
|
|
42
43
|
description: 'Disallow GraphQL introspection in production environments',
|
|
44
|
+
cwe: 'CWE-200',
|
|
45
|
+
cvss: 5,
|
|
43
46
|
},
|
|
44
47
|
hasSuggestions: true,
|
|
45
48
|
messages: {
|
|
@@ -42,7 +42,10 @@ exports.noInsecureCookieOptions = (0, eslint_devkit_1.createRule)({
|
|
|
42
42
|
meta: {
|
|
43
43
|
type: 'problem',
|
|
44
44
|
docs: {
|
|
45
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-insecure-cookie-options.md',
|
|
45
46
|
description: 'Require secure cookie flags (httpOnly, secure, sameSite) in Express.js',
|
|
47
|
+
cwe: 'CWE-614',
|
|
48
|
+
cvss: 7.5,
|
|
46
49
|
},
|
|
47
50
|
hasSuggestions: true,
|
|
48
51
|
messages: {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-missing-cors-check
|
|
8
|
+
* Detects missing CORS validation (wildcard CORS, missing origin check)
|
|
9
|
+
* CWE-346: Origin Validation Error
|
|
10
|
+
*
|
|
11
|
+
* @see https://cwe.mitre.org/data/definitions/346.html
|
|
12
|
+
* @see https://owasp.org/www-community/attacks/CORS_Misconfiguration
|
|
13
|
+
*/
|
|
14
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
15
|
+
type MessageIds = 'missingCorsCheck' | 'useOriginValidation' | 'useCorsMiddleware';
|
|
16
|
+
export interface Options {
|
|
17
|
+
/** Allow missing CORS checks in test files. Default: false */
|
|
18
|
+
allowInTests?: boolean;
|
|
19
|
+
/** Trusted CORS libraries. Default: ['cors', '@koa/cors', 'express-cors'] */
|
|
20
|
+
trustedLibraries?: string[];
|
|
21
|
+
/** Additional safe patterns to ignore. Default: [] */
|
|
22
|
+
ignorePatterns?: string[];
|
|
23
|
+
}
|
|
24
|
+
type RuleOptions = [Options?];
|
|
25
|
+
export declare const noMissingCorsCheck: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
export {};
|