eslint-plugin-jwt-security 2.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 +102 -0
- package/CHANGELOG.md +161 -0
- package/LICENSE +23 -0
- package/README.md +158 -0
- package/dist/AGENTS.md +102 -0
- package/dist/CHANGELOG.md +161 -0
- package/dist/LICENSE +23 -0
- package/dist/README.md +158 -0
- package/dist/package.json +125 -0
- package/dist/src/index.d.ts +101 -0
- package/dist/src/index.js +171 -0
- package/dist/src/oxlint.d.ts +20 -0
- package/dist/src/oxlint.js +21 -0
- package/dist/src/rules/no-algorithm-confusion/index.d.ts +24 -0
- package/dist/src/rules/no-algorithm-confusion/index.js +165 -0
- package/dist/src/rules/no-algorithm-none/index.d.ts +24 -0
- package/dist/src/rules/no-algorithm-none/index.js +222 -0
- package/dist/src/rules/no-decode-without-verify/index.d.ts +23 -0
- package/dist/src/rules/no-decode-without-verify/index.js +131 -0
- package/dist/src/rules/no-hardcoded-secret/index.d.ts +23 -0
- package/dist/src/rules/no-hardcoded-secret/index.js +189 -0
- package/dist/src/rules/no-sensitive-payload/index.d.ts +20 -0
- package/dist/src/rules/no-sensitive-payload/index.js +103 -0
- package/dist/src/rules/no-timestamp-manipulation/index.d.ts +23 -0
- package/dist/src/rules/no-timestamp-manipulation/index.js +97 -0
- package/dist/src/rules/no-weak-secret/index.d.ts +23 -0
- package/dist/src/rules/no-weak-secret/index.js +165 -0
- package/dist/src/rules/require-algorithm-whitelist/index.d.ts +24 -0
- package/dist/src/rules/require-algorithm-whitelist/index.js +113 -0
- package/dist/src/rules/require-audience-validation/index.d.ts +20 -0
- package/dist/src/rules/require-audience-validation/index.js +100 -0
- package/dist/src/rules/require-expiration/index.d.ts +23 -0
- package/dist/src/rules/require-expiration/index.js +136 -0
- package/dist/src/rules/require-issued-at/index.d.ts +23 -0
- package/dist/src/rules/require-issued-at/index.js +113 -0
- package/dist/src/rules/require-issuer-validation/index.d.ts +20 -0
- package/dist/src/rules/require-issuer-validation/index.js +100 -0
- package/dist/src/rules/require-max-age/index.d.ts +24 -0
- package/dist/src/rules/require-max-age/index.js +93 -0
- package/dist/src/types/index.d.ts +82 -0
- package/dist/src/types/index.js +7 -0
- package/dist/src/utils/index.d.ts +98 -0
- package/dist/src/utils/index.js +238 -0
- package/package.json +125 -0
- package/src/__compatibility__/jwt-interface.spec.ts +192 -0
- package/src/index.test.ts +47 -0
- package/src/index.ts +209 -0
- package/src/oxlint.test.ts +61 -0
- package/src/oxlint.ts +23 -0
- package/src/rules/no-algorithm-confusion/index.ts +208 -0
- package/src/rules/no-algorithm-confusion/no-algorithm-confusion.test.ts +106 -0
- package/src/rules/no-algorithm-none/index.ts +270 -0
- package/src/rules/no-algorithm-none/no-algorithm-none.test.ts +146 -0
- package/src/rules/no-decode-without-verify/index.ts +162 -0
- package/src/rules/no-decode-without-verify/no-decode-without-verify.test.ts +76 -0
- package/src/rules/no-hardcoded-secret/index.ts +230 -0
- package/src/rules/no-hardcoded-secret/no-hardcoded-secret.test.ts +97 -0
- package/src/rules/no-sensitive-payload/index.ts +123 -0
- package/src/rules/no-sensitive-payload/no-sensitive-payload.test.ts +157 -0
- package/src/rules/no-timestamp-manipulation/index.ts +118 -0
- package/src/rules/no-timestamp-manipulation/no-timestamp-manipulation.test.ts +54 -0
- package/src/rules/no-weak-secret/index.ts +204 -0
- package/src/rules/no-weak-secret/no-weak-secret.test.ts +114 -0
- package/src/rules/require-algorithm-whitelist/index.ts +145 -0
- package/src/rules/require-algorithm-whitelist/require-algorithm-whitelist.test.ts +72 -0
- package/src/rules/require-audience-validation/index.ts +120 -0
- package/src/rules/require-audience-validation/require-audience-validation.test.ts +68 -0
- package/src/rules/require-expiration/index.ts +170 -0
- package/src/rules/require-expiration/require-expiration.test.ts +135 -0
- package/src/rules/require-issued-at/index.ts +143 -0
- package/src/rules/require-issued-at/require-issued-at.test.ts +64 -0
- package/src/rules/require-issuer-validation/index.ts +120 -0
- package/src/rules/require-issuer-validation/require-issuer-validation.test.ts +68 -0
- package/src/rules/require-max-age/index.ts +117 -0
- package/src/rules/require-max-age/require-max-age.test.ts +69 -0
- package/src/tests/coverage-dual-layer.test.ts +323 -0
- package/src/types/index.ts +107 -0
- package/src/utils/index.ts +285 -0
- package/src/utils/utils.test.ts +324 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
> Context for AI coding agents working on eslint-plugin-jwt-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-jwt-security
|
|
13
|
+
|
|
14
|
+
# Run tests
|
|
15
|
+
nx test eslint-plugin-jwt-security
|
|
16
|
+
|
|
17
|
+
# Run tests with coverage
|
|
18
|
+
nx test eslint-plugin-jwt-security --coverage
|
|
19
|
+
|
|
20
|
+
# Lint this package
|
|
21
|
+
nx lint eslint-plugin-jwt-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
|
+
|
|
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-jwt-security --testPathPattern="no-algorithm-none"`
|
|
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 configs
|
|
46
|
+
└── rules/ # 13 rule directories
|
|
47
|
+
└── [rule-name]/
|
|
48
|
+
├── index.ts # Rule implementation
|
|
49
|
+
└── *.test.ts # Rule tests
|
|
50
|
+
docs/rules/ # Markdown documentation per rule
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Plugin Purpose
|
|
54
|
+
|
|
55
|
+
Comprehensive JWT security ESLint plugin with **13 rules** covering algorithm attacks, replay prevention, and claim validation. Targets 6 major Node.js JWT libraries.
|
|
56
|
+
|
|
57
|
+
## Rule Categories
|
|
58
|
+
|
|
59
|
+
| Category | Rules | CWEs |
|
|
60
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ |
|
|
61
|
+
| Algorithm Attacks | `no-algorithm-none`, `no-algorithm-confusion` | 347 |
|
|
62
|
+
| Verification & Secrets | `require-algorithm-whitelist`, `no-decode-without-verify`, `no-weak-secret`, `no-hardcoded-secret`, `no-timestamp-manipulation` | 326, 345, 757, 798 |
|
|
63
|
+
| Claims | `require-expiration`, `require-issued-at`, `require-issuer-validation`, `require-audience-validation`, `require-max-age`, `no-sensitive-payload` | 287, 294, 359, 613 |
|
|
64
|
+
|
|
65
|
+
## Library Detection
|
|
66
|
+
|
|
67
|
+
The plugin detects these method calls:
|
|
68
|
+
|
|
69
|
+
- **Sign**: `jwt.sign()`, `signJWT()`, `SignJWT()`
|
|
70
|
+
- **Verify**: `jwt.verify()`, `jwtVerify()`, `verifyJWT()`
|
|
71
|
+
- **Decode**: `jwt.decode()`, `jwtDecode()`, `decodeJWT()`
|
|
72
|
+
|
|
73
|
+
## Common Fix Patterns
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// Algorithm None Attack (CVE-2022-23540)
|
|
77
|
+
// BAD: jwt.verify(token, secret, { algorithms: ['none'] })
|
|
78
|
+
// GOOD: jwt.verify(token, secret, { algorithms: ['RS256'] })
|
|
79
|
+
|
|
80
|
+
// Algorithm Confusion
|
|
81
|
+
// BAD: jwt.verify(token, publicKey, { algorithms: ['HS256'] })
|
|
82
|
+
// GOOD: jwt.verify(token, publicKey, { algorithms: ['RS256'] })
|
|
83
|
+
|
|
84
|
+
// Hardcoded Secret
|
|
85
|
+
// BAD: jwt.sign(payload, 'my-secret-key')
|
|
86
|
+
// GOOD: jwt.sign(payload, process.env.JWT_SECRET)
|
|
87
|
+
|
|
88
|
+
// Missing Expiration
|
|
89
|
+
// BAD: jwt.sign({ sub: 'user' }, secret)
|
|
90
|
+
// GOOD: jwt.sign({ sub: 'user' }, secret, { expiresIn: '1h' })
|
|
91
|
+
|
|
92
|
+
// Replay Attack Prevention
|
|
93
|
+
// BAD: jwt.sign(payload, secret, { noTimestamp: true })
|
|
94
|
+
// GOOD: jwt.sign(payload, secret)
|
|
95
|
+
// GOOD: jwt.verify(token, secret, { maxAge: '1h' })
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Security Considerations
|
|
99
|
+
|
|
100
|
+
- CWE coverage: 287, 294, 326, 345, 347, 359, 613, 757, 798
|
|
101
|
+
- Detects CVE-2022-23540 (Algorithm None attack)
|
|
102
|
+
- Covers 6 major JWT libraries: jsonwebtoken, jose, jwt-decode, node-jose, jwt-simple, jsonwebtoken-esm
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
## [2.2.3] - 2026-02-08
|
|
2
|
+
|
|
3
|
+
## 2.2.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#294](https://github.com/ofri-peretz/eslint/pull/294) [`659f6dc`](https://github.com/ofri-peretz/eslint/commit/659f6dc0181b03b675f72b5949fcf123dd066358) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Rewrite `description` and `keywords` on every published package for npm search discovery. npm ranks on name, description, and keywords, and the registry only picks up these fields at publish — so this is metadata-only and takes effect for each package on its next release.
|
|
8
|
+
|
|
9
|
+
**Descriptions now lead with the search phrase.** Every one starts `ESLint plugin for <the thing you'd search>` instead of a brand-first or category-first framing, and names the concrete vulnerabilities the plugin actually detects. Three were corrected while doing so:
|
|
10
|
+
|
|
11
|
+
- `eslint-plugin-import-next` claimed "100x faster no-cycle detection". No 100x measurement exists: `CLAIMS.md` records **3.1x end-to-end** (8x in pure rule execution) on a 5,483-file React codebase, and the highest number in any benchmark result is 54.9x on the synthetic corpus. The description now states the real-codebase figure.
|
|
12
|
+
- `eslint-plugin-secure-coding` claimed SQL injection, XSS and CSRF coverage — none of which are its rules. It now names what it does detect: LDAP, XPath, XXE, GraphQL and template injection, unsafe deserialization, ReDoS, missing authentication, and PII in logs.
|
|
13
|
+
- `eslint-plugin-secure-coding` ("89 rules") and `eslint-plugin-react-a11y` ("37 rules") hard-coded rule counts that had drifted from reality. Counts are generated into `interlace-numbers.json`; hand-typed copies are removed rather than corrected.
|
|
14
|
+
|
|
15
|
+
**Keywords now match the vocabulary of the plugins that rank.** `eslint-plugin-security`, `eslint-plugin-jsx-a11y`, `eslint-plugin-n` and `eslint-plugin-import` all carry the `eslint` / `eslintplugin` / `eslint-plugin` trio — six of our packages were missing `eslintplugin`, and every one now carries all three plus `static-analysis`, `linting` and `code-quality`. Security plugins add `sast`, `appsec` and `vulnerability`; `node-security` and `secure-coding` also carry `nodesecurity`, the exact keyword `eslint-plugin-security` ranks on. Each plugin gained the CWE identifiers and attack names for what it detects (`cwe-78` command injection, `cwe-22` path traversal, `cwe-89` SQL injection, `cwe-79` XSS, `cwe-347` JWT algorithm confusion, `cwe-352` CSRF, `cwe-943` NoSQL injection), and `node-security` gained the crypto vocabulary it had been missing entirely despite absorbing the crypto rule set (`crypto`, `cryptography`, `weak-hash`, `md5`, `sha1`, `timing-attack`).
|
|
16
|
+
|
|
17
|
+
No rule behavior, exports, or configuration changes.
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`e1cdf83`](https://github.com/ofri-peretz/eslint/commit/e1cdf83e3db761907f0ab06f7fc6c1f1da7513a5), [`659f6dc`](https://github.com/ofri-peretz/eslint/commit/659f6dc0181b03b675f72b5949fcf123dd066358)]:
|
|
20
|
+
- @interlace/eslint-devkit@1.4.3
|
|
21
|
+
|
|
22
|
+
## 2.2.8
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- [#269](https://github.com/ofri-peretz/eslint/pull/269) [`7028fe2`](https://github.com/ofri-peretz/eslint/commit/7028fe2668a42266d831014184dcef70e73101ad) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - docs: dual-logo README header (Interlace mark + ESLint mark side by side) and closing Interlace footer — refreshes the README rendered on npmjs.com. No runtime changes.
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`7028fe2`](https://github.com/ofri-peretz/eslint/commit/7028fe2668a42266d831014184dcef70e73101ad)]:
|
|
29
|
+
- @interlace/eslint-devkit@1.4.2
|
|
30
|
+
|
|
31
|
+
## 2.2.7
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- [#252](https://github.com/ofri-peretz/eslint/pull/252) [`d67e395`](https://github.com/ofri-peretz/eslint/commit/d67e3953c2748ad36e6aebe0f24b1d04e518b4d0) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Fix Codecov badge showing "unknown" — switch from flag to component URL format
|
|
36
|
+
|
|
37
|
+
## 2.2.6
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- [#225](https://github.com/ofri-peretz/eslint/pull/225) [`34ff5a8`](https://github.com/ofri-peretz/eslint/commit/34ff5a8e6f5126c5d1c0a524759e0af2b5476b46) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - CI-only: pin all coverage thresholds at 100% (integration target, merges last).
|
|
42
|
+
|
|
43
|
+
## 2.2.5
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- [#213](https://github.com/ofri-peretz/eslint/pull/213) [`391dbe6`](https://github.com/ofri-peretz/eslint/commit/391dbe6b39f78d549379218567cb959649f8c614) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Align every security rule's `meta.docs.cvss` to the CVSS its finding actually
|
|
48
|
+
emits. The emitted machine-readable message sources its `CVSS:x` from
|
|
49
|
+
`CWE_MAPPING` via `formatLLMMessage` → `enrichFromCWE`, but the static
|
|
50
|
+
`meta.docs.cvss` documentation field had drifted on 45 rules across these 7
|
|
51
|
+
plugins — e.g. `no-hardcoded-credentials` documented `9.5` while emitting
|
|
52
|
+
`CVSS:9.8` (the value the published article and SARIF/LLM consumers already
|
|
53
|
+
read).
|
|
54
|
+
|
|
55
|
+
This corrects the **documentation metadata only** — no emitted finding changes.
|
|
56
|
+
Locked by `security-cvss-docs-consistency.lock.test.ts` (cross-plugin: every
|
|
57
|
+
security rule's `meta.docs.cvss` must equal the CVSS it emits), the
|
|
58
|
+
`no-hardcoded-credentials` rule lock (real ESLint `Linter` emission), and a
|
|
59
|
+
devkit `enrichFromCWE` contract test pinning `CWE-798 → 9.8`.
|
|
60
|
+
|
|
61
|
+
Follow-up (not in scope): 50 security rules document a CVSS that never appears
|
|
62
|
+
in any emitted message (their messages carry no CWE), and several rules emit the
|
|
63
|
+
generic CWE score where a rule-specific score may be warranted — both change
|
|
64
|
+
emitted output and are separate decisions.
|
|
65
|
+
|
|
66
|
+
## 2.2.4
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- [#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
|
|
71
|
+
|
|
72
|
+
Rules that were recognized as null guards are now correctly identified as safe:
|
|
73
|
+
1. **Truthy if guard** — `if (obj) { obj.prop }` — direct truthy check proves non-null. Also covers chains: `if (response)` protects `response.data.items`.
|
|
74
|
+
2. **Short-circuit AND** — `obj && obj.prop` — right side of `&&` only runs when left is truthy.
|
|
75
|
+
3. **Ternary consequent** — `obj ? obj.prop : fallback` — truthy test guards the consequent.
|
|
76
|
+
|
|
77
|
+
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.
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [[`736a5fe`](https://github.com/ofri-peretz/eslint/commit/736a5fed47e673f6157ea900b29fe2a54e4bc7df)]:
|
|
80
|
+
- @interlace/eslint-devkit@1.4.1
|
|
81
|
+
|
|
82
|
+
### Bug Fixes
|
|
83
|
+
|
|
84
|
+
- align codecov component IDs with full package names ([2831b968](https://github.com/ofri-peretz/eslint/commit/2831b968))
|
|
85
|
+
|
|
86
|
+
### Documentation
|
|
87
|
+
|
|
88
|
+
- fix changelog header format across all packages ([c3a15082](https://github.com/ofri-peretz/eslint/commit/c3a15082))
|
|
89
|
+
|
|
90
|
+
### ❤️ Thank You
|
|
91
|
+
|
|
92
|
+
- Ofri Peretz
|
|
93
|
+
|
|
94
|
+
## [2.2.2] - 2026-02-06
|
|
95
|
+
|
|
96
|
+
### Bug Fixes
|
|
97
|
+
|
|
98
|
+
- align codecov component names and update docs components ([0a59a86c](https://github.com/ofri-peretz/eslint/commit/0a59a86c))
|
|
99
|
+
|
|
100
|
+
### ❤️ Thank You
|
|
101
|
+
|
|
102
|
+
- Ofri Peretz
|
|
103
|
+
|
|
104
|
+
## [2.2.1] - 2026-02-02
|
|
105
|
+
|
|
106
|
+
This was a version bump only for eslint-plugin-jwt-security to align it with other projects, there were no code changes.
|
|
107
|
+
|
|
108
|
+
# Changelog
|
|
109
|
+
|
|
110
|
+
All notable changes to eslint-plugin-jwt-security will be documented in this file.
|
|
111
|
+
|
|
112
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
113
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
114
|
+
|
|
115
|
+
## [1.0.0] - 2025-12-29
|
|
116
|
+
|
|
117
|
+
### Added
|
|
118
|
+
|
|
119
|
+
#### Core Security Rules (7)
|
|
120
|
+
|
|
121
|
+
- `no-algorithm-none` - Prevent `alg:"none"` attack (CVE-2022-23540, CWE-347)
|
|
122
|
+
- `no-algorithm-confusion` - Prevent RS256→HS256 key confusion (CWE-347)
|
|
123
|
+
- `require-algorithm-whitelist` - Require explicit algorithm specification (CWE-757)
|
|
124
|
+
- `no-decode-without-verify` - Prevent trusting decoded payloads (CWE-345)
|
|
125
|
+
- `no-weak-secret` - Require 256-bit minimum secrets (CWE-326)
|
|
126
|
+
- `no-hardcoded-secret` - Prevent secrets in source code (CWE-798)
|
|
127
|
+
- `require-expiration` - Require `exp` claim or `expiresIn` (CWE-613)
|
|
128
|
+
|
|
129
|
+
#### 2025 Research Rules (6)
|
|
130
|
+
|
|
131
|
+
Based on LightSEC 2025 "Back to the Future" attack research:
|
|
132
|
+
|
|
133
|
+
- `require-issued-at` - Require `iat` claim for freshness (CWE-294)
|
|
134
|
+
- `require-issuer-validation` - Require issuer validation (CWE-287)
|
|
135
|
+
- `require-audience-validation` - Require audience validation (CWE-287)
|
|
136
|
+
- `no-timestamp-manipulation` - Prevent `noTimestamp: true` (CWE-294)
|
|
137
|
+
- `require-max-age` - Require maxAge for replay prevention (CWE-294)
|
|
138
|
+
- `no-sensitive-payload` - Prevent PII in token payload (CWE-359)
|
|
139
|
+
|
|
140
|
+
#### Configuration Presets
|
|
141
|
+
|
|
142
|
+
- `recommended` - Balanced security (critical=error, high=warn)
|
|
143
|
+
- `strict` - Maximum security with all 13 rules enabled
|
|
144
|
+
- `legacy` - Migration mode with only critical rules
|
|
145
|
+
|
|
146
|
+
#### Library Support
|
|
147
|
+
|
|
148
|
+
- jsonwebtoken
|
|
149
|
+
- jose
|
|
150
|
+
- express-jwt
|
|
151
|
+
- @nestjs/jwt
|
|
152
|
+
- jwks-rsa
|
|
153
|
+
- jwt-decode
|
|
154
|
+
|
|
155
|
+
### Features
|
|
156
|
+
|
|
157
|
+
- AI-optimized error messages using `formatLLMMessage`
|
|
158
|
+
- CWE references for all rules (9 CWEs covered)
|
|
159
|
+
- OWASP Top 10 2021 coverage matrix (6 categories)
|
|
160
|
+
- Full TypeScript support
|
|
161
|
+
- Comprehensive test coverage (248 edge case tests)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="90" /></a>
|
|
3
|
+
|
|
4
|
+
<a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/eslint-logo.svg" alt="ESLint" height="90" /></a>
|
|
5
|
+
|
|
6
|
+
<a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/oxlint-logo.svg" alt="oxlint" height="90" /></a>
|
|
7
|
+
|
|
8
|
+
<a href="https://www.npmjs.com/package/jsonwebtoken" target="_blank"><img src="https://eslint.interlace.tools/jwt-logo.svg" alt="JSON Web Tokens" height="90" /></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
Security validation for JSON Web Tokens (JWT) implementation (signing, verification).
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-jwt-security" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-jwt-security.svg" alt="NPM Version" /></a>
|
|
17
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-jwt-security" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-jwt-security.svg" alt="NPM Downloads" /></a>
|
|
18
|
+
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
19
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=eslint-plugin-jwt-security" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=eslint-plugin-jwt-security" alt="Codecov" /></a>
|
|
20
|
+
<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>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
> ⭐ 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.
|
|
24
|
+
|
|
25
|
+
## Description
|
|
26
|
+
|
|
27
|
+
This plugin provides Security validation for JSON Web Tokens (JWT) implementation (signing, verification).
|
|
28
|
+
|
|
29
|
+
## Philosophy
|
|
30
|
+
|
|
31
|
+
**Interlace** fosters **strength through integration**. Instead of stacking isolated rules, we **interlace** security directly into your workflow to create a resilient fabric of code. We believe tools should **guide rather than gatekeep**, providing educational feedback that strengthens the developer with every interaction.
|
|
32
|
+
|
|
33
|
+
## Getting Started
|
|
34
|
+
|
|
35
|
+
- To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-jwt?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security). 📚
|
|
36
|
+
- 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-jwt?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security). 📚
|
|
37
|
+
- [가이드](https://eslint.interlace.tools/docs/security/plugin-jwt?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security)에서 확인하실 수 있습니다. 📚
|
|
38
|
+
- [ガイド](https://eslint.interlace.tools/docs/security/plugin-jwt?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security)は [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security)でご確認ください。 📚
|
|
39
|
+
- Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-jwt?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security), visita [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security). 📚
|
|
40
|
+
- للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-jwt?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security). 📚
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install eslint-plugin-jwt-security --save-dev
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## ⚙️ Configuration Presets
|
|
47
|
+
| Preset | Description |
|
|
48
|
+
| :------------ | :-------------------------------------------------------- |
|
|
49
|
+
| `recommended` | Recommended preset - balanced security |
|
|
50
|
+
| `strict` | Strict preset - maximum security (includes 2025 research) |
|
|
51
|
+
| `legacy` | Legacy preset - migration mode |
|
|
52
|
+
| `all` | All rules preset |
|
|
53
|
+
|
|
54
|
+
## 📚 Supported Libraries
|
|
55
|
+
| Library | npm | Downloads | Detection |
|
|
56
|
+
| :------------- | :-------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------- | :------------------------------ |
|
|
57
|
+
| `jsonwebtoken` | [](https://www.npmjs.com/package/jsonwebtoken) | [](https://www.npmjs.com/package/jsonwebtoken) | Signing, Verification, Decoding |
|
|
58
|
+
| `jose` | [](https://www.npmjs.com/package/jose) | [](https://www.npmjs.com/package/jose) | Verification (Fix Suggestion) |
|
|
59
|
+
| `jwt-decode` | [](https://www.npmjs.com/package/jwt-decode) | [](https://www.npmjs.com/package/jwt-decode) | Unsafe Decoding |
|
|
60
|
+
|
|
61
|
+
## 🤖 AI-Optimized Messages
|
|
62
|
+
Every rule uses `formatLLMMessage` for structured output:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
🔒 CWE-347 OWASP:A02-Crypto CVSS:9.8 | Using alg:"none" bypasses signature verification
|
|
66
|
+
Fix: Remove "none" and use RS256, ES256, or other secure algorithms
|
|
67
|
+
https://nvd.nist.gov/vuln/detail/CVE-2022-23540
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
By providing this structured context (CWE, OWASP, Fix), we enable AI tools to **reason** about the security flaw rather than hallucinating. This allows Copilot/Cursor to suggest the _exact_ correct fix immediately.
|
|
71
|
+
|
|
72
|
+
By structuring errors with specific CWE codes, OWASP categories, and direct fix suggestions, this format allows AI coding assistants to autonomously identify, explain, and resolve security vulnerabilities with high confidence.
|
|
73
|
+
|
|
74
|
+
## 💡 What You Get
|
|
75
|
+
- **13 Security Rules** - Algorithm attacks, replay prevention, claim validation
|
|
76
|
+
- **6 JWT Libraries** - jsonwebtoken, jose, express-jwt, @nestjs/jwt, jwks-rsa, jwt-decode
|
|
77
|
+
- **2025 Research** - "Back to the Future" replay attack prevention (LightSEC 2025)
|
|
78
|
+
- **AI-Optimized** - Structured messages for GitHub Copilot, Cursor, Claude assistance
|
|
79
|
+
- **CWE References** - Every rule maps to Common Weakness Enumeration
|
|
80
|
+
|
|
81
|
+
## 📦 Compatibility
|
|
82
|
+
| Package | Version |
|
|
83
|
+
| :--- | :--- |
|
|
84
|
+
| ESLint | `^8.0.0 \|\| ^9.0.0 \|\| ^10.0.0` |
|
|
85
|
+
| Node.js | `>=18.0.0` |
|
|
86
|
+
|
|
87
|
+
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.
|
|
88
|
+
|
|
89
|
+
## Rules
|
|
90
|
+
|
|
91
|
+
**Legend**
|
|
92
|
+
|
|
93
|
+
| Icon | Description |
|
|
94
|
+
| :---: | :--- |
|
|
95
|
+
| 💼 | **Recommended**: Included in the recommended preset. |
|
|
96
|
+
| ⚠️ | **Warns**: Set to warn in recommended preset. |
|
|
97
|
+
| 🔧 | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
|
|
98
|
+
| 💡 | **Suggestions**: Providing code suggestions in IDE. |
|
|
99
|
+
| 🚫 | **Deprecated**: This rule is deprecated. |
|
|
100
|
+
| 🟢 | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
|
|
101
|
+
| 🟡 | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
|
|
102
|
+
| 🟠 | **Type-aware (graceful)**: requires TS program; silent without it. |
|
|
103
|
+
|
|
104
|
+
<!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
|
|
105
|
+
| Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
|
|
106
|
+
| :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
|
107
|
+
| [no-algorithm-confusion](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/no-algorithm-confusion?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-347 | | | This rule detects algorithm confusion attacks where symmetric algorithms (HS256, HS384, HS512) are used wit… | 🟢 | | | | | |
|
|
108
|
+
| [no-algorithm-none](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/no-algorithm-none?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-347 | | | This rule detects attempts to use the none algorithm which completely bypasses JWT signature verification | 🟢 | | | | | |
|
|
109
|
+
| [no-decode-without-verify](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/no-decode-without-verify?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-345 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
110
|
+
| [no-hardcoded-secret](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/no-hardcoded-secret?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-798 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
111
|
+
| [no-sensitive-payload](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/no-sensitive-payload?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-359 | | | JWT payloads are NOT encrypted, only base64-encoded | 🟢 | | | | | |
|
|
112
|
+
| [no-timestamp-manipulation](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/no-timestamp-manipulation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-294 | | | This rule detects noTimestamp: true which disables automatic iat (issued at) claim generation | 🟢 | | | | | |
|
|
113
|
+
| [no-weak-secret](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/no-weak-secret?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-326 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
114
|
+
| [require-algorithm-whitelist](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/require-algorithm-whitelist?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-757 | | | This rule enforces explicit algorithm specification in verify() calls | 🟢 | | | | | |
|
|
115
|
+
| [require-audience-validation](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/require-audience-validation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-287 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
116
|
+
| [require-expiration](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/require-expiration?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-613 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
117
|
+
| [require-issued-at](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/require-issued-at?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-294 | | | This rule ensures tokens have the iat claim for freshness validation | 🟢 | | | | | |
|
|
118
|
+
| [require-issuer-validation](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/require-issuer-validation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-287 | | | The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance: | 🟢 | | | | | |
|
|
119
|
+
| [require-max-age](https://eslint.interlace.tools/docs/security/plugin-jwt/rules/require-max-age?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security) | CWE-294 | | | This rule mandates maxAge in verify operations | 🟢 | | | | | |
|
|
120
|
+
<!-- AUTO-GENERATED:RULES_TABLE:END -->
|
|
121
|
+
## 🔗 Related ESLint Plugins
|
|
122
|
+
|
|
123
|
+
Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
124
|
+
|
|
125
|
+
| Plugin | Downloads | Description |
|
|
126
|
+
| :--- | :---: | :--- |
|
|
127
|
+
| [`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. |
|
|
128
|
+
| [`eslint-plugin-pg`](https://www.npmjs.com/package/eslint-plugin-pg) | [](https://www.npmjs.com/package/eslint-plugin-pg) | PostgreSQL security & best practices. |
|
|
129
|
+
| [`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). |
|
|
130
|
+
| [`eslint-plugin-jwt-security`](https://www.npmjs.com/package/eslint-plugin-jwt-security) | [](https://www.npmjs.com/package/eslint-plugin-jwt-security) | JWT security & best practices. |
|
|
131
|
+
| [`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. |
|
|
132
|
+
| [`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. |
|
|
133
|
+
| [`eslint-plugin-lambda-security`](https://www.npmjs.com/package/eslint-plugin-lambda-security) | [](https://www.npmjs.com/package/eslint-plugin-lambda-security) | AWS Lambda security best practices. |
|
|
134
|
+
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | [](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security rules & patterns. |
|
|
135
|
+
| [`eslint-plugin-mongodb-security`](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | [](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | MongoDB security best practices. |
|
|
136
|
+
| [`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. |
|
|
137
|
+
| [`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. |
|
|
138
|
+
|
|
139
|
+
<!-- INTERLACE:STAR_CTA:START -->
|
|
140
|
+
## ⭐ Support & follow
|
|
141
|
+
|
|
142
|
+
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.
|
|
143
|
+
|
|
144
|
+
[](https://github.com/ofri-peretz/eslint)
|
|
145
|
+
|
|
146
|
+
<!-- INTERLACE:STAR_CTA:END -->
|
|
147
|
+
|
|
148
|
+
## 📄 License
|
|
149
|
+
|
|
150
|
+
MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
151
|
+
|
|
152
|
+
<p align="center">
|
|
153
|
+
<a href="https://eslint.interlace.tools/docs/security/plugin-jwt?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security"><img src="https://eslint.interlace.tools/images/og-jwt.png" alt="ESLint Interlace Plugin" width="100%" /></a>
|
|
154
|
+
</p>
|
|
155
|
+
|
|
156
|
+
<p align="center">
|
|
157
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-jwt-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="70" /></a>
|
|
158
|
+
</p>
|
package/dist/AGENTS.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
> Context for AI coding agents working on eslint-plugin-jwt-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-jwt-security
|
|
13
|
+
|
|
14
|
+
# Run tests
|
|
15
|
+
nx test eslint-plugin-jwt-security
|
|
16
|
+
|
|
17
|
+
# Run tests with coverage
|
|
18
|
+
nx test eslint-plugin-jwt-security --coverage
|
|
19
|
+
|
|
20
|
+
# Lint this package
|
|
21
|
+
nx lint eslint-plugin-jwt-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
|
+
|
|
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-jwt-security --testPathPattern="no-algorithm-none"`
|
|
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 configs
|
|
46
|
+
└── rules/ # 13 rule directories
|
|
47
|
+
└── [rule-name]/
|
|
48
|
+
├── index.ts # Rule implementation
|
|
49
|
+
└── *.test.ts # Rule tests
|
|
50
|
+
docs/rules/ # Markdown documentation per rule
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Plugin Purpose
|
|
54
|
+
|
|
55
|
+
Comprehensive JWT security ESLint plugin with **13 rules** covering algorithm attacks, replay prevention, and claim validation. Targets 6 major Node.js JWT libraries.
|
|
56
|
+
|
|
57
|
+
## Rule Categories
|
|
58
|
+
|
|
59
|
+
| Category | Rules | CWEs |
|
|
60
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ |
|
|
61
|
+
| Algorithm Attacks | `no-algorithm-none`, `no-algorithm-confusion` | 347 |
|
|
62
|
+
| Verification & Secrets | `require-algorithm-whitelist`, `no-decode-without-verify`, `no-weak-secret`, `no-hardcoded-secret`, `no-timestamp-manipulation` | 326, 345, 757, 798 |
|
|
63
|
+
| Claims | `require-expiration`, `require-issued-at`, `require-issuer-validation`, `require-audience-validation`, `require-max-age`, `no-sensitive-payload` | 287, 294, 359, 613 |
|
|
64
|
+
|
|
65
|
+
## Library Detection
|
|
66
|
+
|
|
67
|
+
The plugin detects these method calls:
|
|
68
|
+
|
|
69
|
+
- **Sign**: `jwt.sign()`, `signJWT()`, `SignJWT()`
|
|
70
|
+
- **Verify**: `jwt.verify()`, `jwtVerify()`, `verifyJWT()`
|
|
71
|
+
- **Decode**: `jwt.decode()`, `jwtDecode()`, `decodeJWT()`
|
|
72
|
+
|
|
73
|
+
## Common Fix Patterns
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// Algorithm None Attack (CVE-2022-23540)
|
|
77
|
+
// BAD: jwt.verify(token, secret, { algorithms: ['none'] })
|
|
78
|
+
// GOOD: jwt.verify(token, secret, { algorithms: ['RS256'] })
|
|
79
|
+
|
|
80
|
+
// Algorithm Confusion
|
|
81
|
+
// BAD: jwt.verify(token, publicKey, { algorithms: ['HS256'] })
|
|
82
|
+
// GOOD: jwt.verify(token, publicKey, { algorithms: ['RS256'] })
|
|
83
|
+
|
|
84
|
+
// Hardcoded Secret
|
|
85
|
+
// BAD: jwt.sign(payload, 'my-secret-key')
|
|
86
|
+
// GOOD: jwt.sign(payload, process.env.JWT_SECRET)
|
|
87
|
+
|
|
88
|
+
// Missing Expiration
|
|
89
|
+
// BAD: jwt.sign({ sub: 'user' }, secret)
|
|
90
|
+
// GOOD: jwt.sign({ sub: 'user' }, secret, { expiresIn: '1h' })
|
|
91
|
+
|
|
92
|
+
// Replay Attack Prevention
|
|
93
|
+
// BAD: jwt.sign(payload, secret, { noTimestamp: true })
|
|
94
|
+
// GOOD: jwt.sign(payload, secret)
|
|
95
|
+
// GOOD: jwt.verify(token, secret, { maxAge: '1h' })
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Security Considerations
|
|
99
|
+
|
|
100
|
+
- CWE coverage: 287, 294, 326, 345, 347, 359, 613, 757, 798
|
|
101
|
+
- Detects CVE-2022-23540 (Algorithm None attack)
|
|
102
|
+
- Covers 6 major JWT libraries: jsonwebtoken, jose, jwt-decode, node-jose, jwt-simple, jsonwebtoken-esm
|