eslint-plugin-jwt-security 2.3.0 → 2.3.2
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/README.md +5 -5
- package/package.json +16 -24
- package/src/index.d.ts +17 -0
- package/src/index.js +1 -0
- package/src/oxlint.d.ts +17 -0
- package/src/oxlint.js +1 -0
- package/src/rules/no-algorithm-confusion/index.js +1 -0
- package/src/rules/no-algorithm-none/index.js +1 -0
- package/src/rules/no-decode-without-verify/index.js +1 -0
- package/src/rules/no-hardcoded-secret/index.js +1 -0
- package/src/rules/no-sensitive-payload/index.js +1 -0
- package/src/rules/no-timestamp-manipulation/index.js +1 -0
- package/src/rules/no-weak-secret/index.js +1 -0
- package/src/rules/require-algorithm-whitelist/index.js +1 -0
- package/src/rules/require-audience-validation/index.js +1 -0
- package/src/rules/require-expiration/index.js +1 -0
- package/src/rules/require-issued-at/index.js +1 -0
- package/src/rules/require-issuer-validation/index.js +1 -0
- package/src/rules/require-max-age/index.js +1 -0
- package/src/types/index.js +1 -0
- package/src/utils/index.js +1 -0
- package/AGENTS.md +0 -102
- package/CHANGELOG.md +0 -161
- package/dist/AGENTS.md +0 -102
- package/dist/CHANGELOG.md +0 -161
- package/dist/LICENSE +0 -23
- package/dist/README.md +0 -158
- package/dist/package.json +0 -125
- package/dist/src/index.d.ts +0 -101
- package/dist/src/index.js +0 -171
- package/dist/src/oxlint.d.ts +0 -20
- package/dist/src/oxlint.js +0 -21
- package/dist/src/rules/no-algorithm-confusion/index.d.ts +0 -24
- package/dist/src/rules/no-algorithm-confusion/index.js +0 -165
- package/dist/src/rules/no-algorithm-none/index.d.ts +0 -24
- package/dist/src/rules/no-algorithm-none/index.js +0 -222
- package/dist/src/rules/no-decode-without-verify/index.d.ts +0 -23
- package/dist/src/rules/no-decode-without-verify/index.js +0 -131
- package/dist/src/rules/no-hardcoded-secret/index.d.ts +0 -23
- package/dist/src/rules/no-hardcoded-secret/index.js +0 -189
- package/dist/src/rules/no-sensitive-payload/index.d.ts +0 -20
- package/dist/src/rules/no-sensitive-payload/index.js +0 -103
- package/dist/src/rules/no-timestamp-manipulation/index.d.ts +0 -23
- package/dist/src/rules/no-timestamp-manipulation/index.js +0 -97
- package/dist/src/rules/no-weak-secret/index.d.ts +0 -23
- package/dist/src/rules/no-weak-secret/index.js +0 -165
- package/dist/src/rules/require-algorithm-whitelist/index.d.ts +0 -24
- package/dist/src/rules/require-algorithm-whitelist/index.js +0 -113
- package/dist/src/rules/require-audience-validation/index.d.ts +0 -20
- package/dist/src/rules/require-audience-validation/index.js +0 -100
- package/dist/src/rules/require-expiration/index.d.ts +0 -23
- package/dist/src/rules/require-expiration/index.js +0 -136
- package/dist/src/rules/require-issued-at/index.d.ts +0 -23
- package/dist/src/rules/require-issued-at/index.js +0 -113
- package/dist/src/rules/require-issuer-validation/index.d.ts +0 -20
- package/dist/src/rules/require-issuer-validation/index.js +0 -100
- package/dist/src/rules/require-max-age/index.d.ts +0 -24
- package/dist/src/rules/require-max-age/index.js +0 -93
- package/dist/src/types/index.js +0 -7
- package/dist/src/utils/index.d.ts +0 -98
- package/dist/src/utils/index.js +0 -238
- package/src/__compatibility__/jwt-interface.spec.ts +0 -192
- package/src/index.test.ts +0 -47
- package/src/index.ts +0 -209
- package/src/oxlint.test.ts +0 -61
- package/src/oxlint.ts +0 -23
- package/src/rules/no-algorithm-confusion/index.ts +0 -208
- package/src/rules/no-algorithm-confusion/no-algorithm-confusion.test.ts +0 -106
- package/src/rules/no-algorithm-none/index.ts +0 -270
- package/src/rules/no-algorithm-none/no-algorithm-none.test.ts +0 -146
- package/src/rules/no-decode-without-verify/index.ts +0 -162
- package/src/rules/no-decode-without-verify/no-decode-without-verify.test.ts +0 -76
- package/src/rules/no-hardcoded-secret/index.ts +0 -230
- package/src/rules/no-hardcoded-secret/no-hardcoded-secret.test.ts +0 -97
- package/src/rules/no-sensitive-payload/index.ts +0 -123
- package/src/rules/no-sensitive-payload/no-sensitive-payload.test.ts +0 -157
- package/src/rules/no-timestamp-manipulation/index.ts +0 -118
- package/src/rules/no-timestamp-manipulation/no-timestamp-manipulation.test.ts +0 -54
- package/src/rules/no-weak-secret/index.ts +0 -204
- package/src/rules/no-weak-secret/no-weak-secret.test.ts +0 -114
- package/src/rules/require-algorithm-whitelist/index.ts +0 -145
- package/src/rules/require-algorithm-whitelist/require-algorithm-whitelist.test.ts +0 -72
- package/src/rules/require-audience-validation/index.ts +0 -120
- package/src/rules/require-audience-validation/require-audience-validation.test.ts +0 -68
- package/src/rules/require-expiration/index.ts +0 -170
- package/src/rules/require-expiration/require-expiration.test.ts +0 -135
- package/src/rules/require-issued-at/index.ts +0 -143
- package/src/rules/require-issued-at/require-issued-at.test.ts +0 -64
- package/src/rules/require-issuer-validation/index.ts +0 -120
- package/src/rules/require-issuer-validation/require-issuer-validation.test.ts +0 -68
- package/src/rules/require-max-age/index.ts +0 -117
- package/src/rules/require-max-age/require-max-age.test.ts +0 -69
- package/src/tests/coverage-dual-layer.test.ts +0 -323
- package/src/types/index.ts +0 -107
- package/src/utils/index.ts +0 -285
- package/src/utils/utils.test.ts +0 -324
- /package/{dist/src → src}/types/index.d.ts +0 -0
|
@@ -1,222 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.noAlgorithmNone = void 0;
|
|
9
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
exports.noAlgorithmNone = (0, eslint_devkit_1.createRule)({
|
|
12
|
-
name: 'no-algorithm-none',
|
|
13
|
-
meta: {
|
|
14
|
-
type: 'problem',
|
|
15
|
-
docs: {
|
|
16
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-algorithm-none.md',
|
|
17
|
-
description: 'Disallow JWT "none" algorithm which bypasses signature verification (CVE-2022-23540)',
|
|
18
|
-
cwe: 'CWE-347',
|
|
19
|
-
cvss: 9.5,
|
|
20
|
-
confidence: 'high',
|
|
21
|
-
},
|
|
22
|
-
fixable: undefined,
|
|
23
|
-
hasSuggestions: false,
|
|
24
|
-
messages: {
|
|
25
|
-
algorithmNone: (0, eslint_devkit_1.formatLLMMessage)({
|
|
26
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
27
|
-
issueName: 'JWT Algorithm None Attack',
|
|
28
|
-
cwe: 'CWE-347',
|
|
29
|
-
description: 'Using alg:"none" bypasses signature verification, allowing token forgery',
|
|
30
|
-
severity: 'CRITICAL',
|
|
31
|
-
fix: 'Remove "none" and use RS256, ES256, or other secure algorithms',
|
|
32
|
-
documentationLink: 'https://nvd.nist.gov/vuln/detail/CVE-2022-23540',
|
|
33
|
-
}),
|
|
34
|
-
algorithmNoneInArray: (0, eslint_devkit_1.formatLLMMessage)({
|
|
35
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
36
|
-
issueName: 'JWT Algorithm None in Whitelist',
|
|
37
|
-
cwe: 'CWE-347',
|
|
38
|
-
description: 'Including "none" in algorithms array allows unsigned tokens',
|
|
39
|
-
severity: 'CRITICAL',
|
|
40
|
-
fix: 'Remove "none" from the algorithms array',
|
|
41
|
-
documentationLink: 'https://nvd.nist.gov/vuln/detail/CVE-2022-23540',
|
|
42
|
-
}),
|
|
43
|
-
emptyAlgorithms: (0, eslint_devkit_1.formatLLMMessage)({
|
|
44
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
45
|
-
issueName: 'Empty Algorithms Array',
|
|
46
|
-
cwe: 'CWE-347',
|
|
47
|
-
description: 'Empty algorithms array may default to accepting any algorithm including none',
|
|
48
|
-
severity: 'HIGH',
|
|
49
|
-
fix: 'Specify explicit algorithms: ["RS256"] or ["ES256"]',
|
|
50
|
-
documentationLink: 'https://tools.ietf.org/html/rfc8725',
|
|
51
|
-
}),
|
|
52
|
-
useSecureAlgorithm: (0, eslint_devkit_1.formatLLMMessage)({
|
|
53
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
54
|
-
issueName: 'Use Secure Algorithm',
|
|
55
|
-
description: 'Replace with a secure algorithm',
|
|
56
|
-
severity: 'LOW',
|
|
57
|
-
fix: 'Use algorithms: ["RS256"] or algorithms: ["ES256"]',
|
|
58
|
-
documentationLink: 'https://tools.ietf.org/html/rfc8725',
|
|
59
|
-
}),
|
|
60
|
-
decodeWithoutVerify: (0, eslint_devkit_1.formatLLMMessage)({
|
|
61
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
62
|
-
issueName: 'JWT Decode Without Verify',
|
|
63
|
-
cwe: 'CWE-347',
|
|
64
|
-
description: 'jwt.decode() does NOT verify the signature — using its result as if it were authenticated is functionally equivalent to algorithm:"none". Any token, including forged ones, will decode.',
|
|
65
|
-
severity: 'CRITICAL',
|
|
66
|
-
fix: 'Use jwt.verify(token, secret, { algorithms: ["RS256"] }) instead. Reserve jwt.decode() for non-security inspection only (e.g. logging the issuer).',
|
|
67
|
-
documentationLink: 'https://github.com/auth0/node-jsonwebtoken#jwtdecodetoken--options',
|
|
68
|
-
}),
|
|
69
|
-
},
|
|
70
|
-
schema: [
|
|
71
|
-
{
|
|
72
|
-
type: 'object',
|
|
73
|
-
properties: {
|
|
74
|
-
allowInTests: {
|
|
75
|
-
type: 'boolean',
|
|
76
|
-
default: false,
|
|
77
|
-
description: 'Allow "none" algorithm in test files',
|
|
78
|
-
},
|
|
79
|
-
trustedSanitizers: {
|
|
80
|
-
type: 'array',
|
|
81
|
-
items: { type: 'string' },
|
|
82
|
-
default: [],
|
|
83
|
-
},
|
|
84
|
-
trustedAnnotations: {
|
|
85
|
-
type: 'array',
|
|
86
|
-
items: { type: 'string' },
|
|
87
|
-
default: [],
|
|
88
|
-
},
|
|
89
|
-
strictMode: {
|
|
90
|
-
type: 'boolean',
|
|
91
|
-
default: false,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
additionalProperties: false,
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
defaultOptions: [
|
|
99
|
-
{
|
|
100
|
-
allowInTests: false,
|
|
101
|
-
trustedSanitizers: [],
|
|
102
|
-
trustedAnnotations: [],
|
|
103
|
-
strictMode: false,
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
create(context) {
|
|
107
|
-
const options = context.options[0] ?? {};
|
|
108
|
-
const { allowInTests = false } = options;
|
|
109
|
-
const filename = context.filename;
|
|
110
|
-
// Skip test files if configured
|
|
111
|
-
if (allowInTests && (0, utils_1.isTestFile)(filename)) {
|
|
112
|
-
return {};
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Check if an algorithm value is 'none' (case insensitive)
|
|
116
|
-
*/
|
|
117
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
118
|
-
const isNoneAlgorithm = (value) => {
|
|
119
|
-
return value.toLowerCase() === 'none';
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Check options object for 'none' algorithm
|
|
123
|
-
*/
|
|
124
|
-
const checkOptionsForNone = (optionsNode) => {
|
|
125
|
-
for (const prop of optionsNode.properties) {
|
|
126
|
-
if (prop.type !== 'Property' || prop.key.type !== 'Identifier') {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const keyName = prop.key.name;
|
|
130
|
-
if (keyName !== 'algorithms' &&
|
|
131
|
-
keyName !== 'algorithm' &&
|
|
132
|
-
keyName !== 'alg') {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
// Single algorithm: { algorithm: 'none' }
|
|
136
|
-
if (prop.value.type === 'Literal' &&
|
|
137
|
-
typeof prop.value.value === 'string') {
|
|
138
|
-
if (isNoneAlgorithm(prop.value.value)) {
|
|
139
|
-
context.report({
|
|
140
|
-
node: prop.value,
|
|
141
|
-
messageId: 'algorithmNone',
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
// Array of algorithms: { algorithms: ['none'] } or { algorithms: [] }
|
|
146
|
-
if (prop.value.type === 'ArrayExpression') {
|
|
147
|
-
// Check for empty array
|
|
148
|
-
if (prop.value.elements.length === 0) {
|
|
149
|
-
context.report({
|
|
150
|
-
node: prop.value,
|
|
151
|
-
messageId: 'emptyAlgorithms',
|
|
152
|
-
});
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
// Check each element for 'none'
|
|
156
|
-
for (const elem of prop.value.elements) {
|
|
157
|
-
if (elem &&
|
|
158
|
-
elem.type === 'Literal' &&
|
|
159
|
-
typeof elem.value === 'string' &&
|
|
160
|
-
isNoneAlgorithm(elem.value)) {
|
|
161
|
-
context.report({
|
|
162
|
-
node: elem,
|
|
163
|
-
messageId: 'algorithmNoneInArray',
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Detect `jwt.decode()` calls — closes the audit FN where
|
|
172
|
-
* `jwt.decode(token)` followed by trusting the decoded payload was
|
|
173
|
-
* silent, despite being functionally equivalent to algorithm:"none".
|
|
174
|
-
* See benchmarks/AUDIT_PATTERNS.md §3.8 ("verify-then-trust mismatch").
|
|
175
|
-
*
|
|
176
|
-
* The check is conservative: we flag every `jwt.decode()` call. In
|
|
177
|
-
* the rare case where `decode` is used legitimately (e.g. logging
|
|
178
|
-
* the issuer of an inbound token without authentication semantics),
|
|
179
|
-
* the user can disable the rule on that line. The default-on
|
|
180
|
-
* behaviour is correct — most production uses of `jwt.decode` are
|
|
181
|
-
* authentication mistakes.
|
|
182
|
-
*/
|
|
183
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
184
|
-
function isDecodeCall(node) {
|
|
185
|
-
const callee = node.callee;
|
|
186
|
-
if (callee.type !== 'MemberExpression')
|
|
187
|
-
return false;
|
|
188
|
-
if (callee.property.type !== 'Identifier')
|
|
189
|
-
return false;
|
|
190
|
-
if (callee.property.name !== 'decode')
|
|
191
|
-
return false;
|
|
192
|
-
// Object should be `jwt` (or imported as such). Check both
|
|
193
|
-
// `jwt.decode` and `JWT.decode` patterns.
|
|
194
|
-
if (callee.object.type === 'Identifier') {
|
|
195
|
-
const name = callee.object.name.toLowerCase();
|
|
196
|
-
return name === 'jwt' || name === 'jsonwebtoken';
|
|
197
|
-
}
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
return {
|
|
201
|
-
CallExpression(node) {
|
|
202
|
-
// Detect `jwt.decode(...)` — equivalent to algorithm:"none" if
|
|
203
|
-
// its result is trusted. We always flag (with critical severity)
|
|
204
|
-
// because the FN risk far outweighs the FP risk on real code.
|
|
205
|
-
if (isDecodeCall(node)) {
|
|
206
|
-
context.report({ node, messageId: 'decodeWithoutVerify' });
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
// Check both verify and sign operations
|
|
210
|
-
if (!(0, utils_1.isVerifyOperation)(node) && !(0, utils_1.isSignOperation)(node)) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
// Get options argument (usually 3rd argument)
|
|
214
|
-
const optionsArg = (0, utils_1.getOptionsArgument)(node, 2);
|
|
215
|
-
if (optionsArg) {
|
|
216
|
-
checkOptionsForNone(optionsArg);
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
exports.default = exports.noAlgorithmNone;
|
|
@@ -1,23 +0,0 @@
|
|
|
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-decode-without-verify
|
|
8
|
-
*
|
|
9
|
-
* Detects usage of jwt.decode() or jwt-decode library without corresponding
|
|
10
|
-
* verification. Decoded JWTs can be tampered with by attackers.
|
|
11
|
-
*
|
|
12
|
-
* CWE-345: Insufficient Verification of Data Authenticity
|
|
13
|
-
*
|
|
14
|
-
* @see https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/06-Session_Management_Testing/10-Testing_JSON_Web_Tokens
|
|
15
|
-
*/
|
|
16
|
-
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
17
|
-
import type { NoDecodeWithoutVerifyOptions } from '../../types';
|
|
18
|
-
type MessageIds = 'decodeWithoutVerify' | 'jwtDecodeLibrary' | 'useVerifyInstead';
|
|
19
|
-
type RuleOptions = [NoDecodeWithoutVerifyOptions?];
|
|
20
|
-
export declare const noDecodeWithoutVerify: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
21
|
-
name: string;
|
|
22
|
-
};
|
|
23
|
-
export default noDecodeWithoutVerify;
|
|
@@ -1,131 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.noDecodeWithoutVerify = void 0;
|
|
9
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
exports.noDecodeWithoutVerify = (0, eslint_devkit_1.createRule)({
|
|
12
|
-
name: 'no-decode-without-verify',
|
|
13
|
-
meta: {
|
|
14
|
-
type: 'problem',
|
|
15
|
-
docs: {
|
|
16
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-decode-without-verify.md',
|
|
17
|
-
description: 'Disallow trusting decoded JWT payload without signature verification',
|
|
18
|
-
cwe: 'CWE-345',
|
|
19
|
-
cvss: 7.5,
|
|
20
|
-
},
|
|
21
|
-
fixable: undefined,
|
|
22
|
-
hasSuggestions: false,
|
|
23
|
-
messages: {
|
|
24
|
-
decodeWithoutVerify: (0, eslint_devkit_1.formatLLMMessage)({
|
|
25
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
26
|
-
issueName: 'Decoded JWT Without Verification',
|
|
27
|
-
cwe: 'CWE-345',
|
|
28
|
-
description: 'jwt.decode() returns payload without verifying signature - data can be forged',
|
|
29
|
-
severity: 'HIGH',
|
|
30
|
-
fix: 'Use jwt.verify(token, secret) instead of jwt.decode(token)',
|
|
31
|
-
documentationLink: 'https://owasp.org/API-Security/0xa7-security-misconfiguration/',
|
|
32
|
-
}),
|
|
33
|
-
jwtDecodeLibrary: (0, eslint_devkit_1.formatLLMMessage)({
|
|
34
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
35
|
-
issueName: 'jwt-decode Library Usage',
|
|
36
|
-
cwe: 'CWE-345',
|
|
37
|
-
description: 'jwt-decode library only decodes tokens, never verifies signatures',
|
|
38
|
-
severity: 'HIGH',
|
|
39
|
-
fix: 'Use jsonwebtoken.verify() or jose.jwtVerify() for verification',
|
|
40
|
-
documentationLink: 'https://www.npmjs.com/package/jwt-decode',
|
|
41
|
-
}),
|
|
42
|
-
useVerifyInstead: (0, eslint_devkit_1.formatLLMMessage)({
|
|
43
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
44
|
-
issueName: 'Use Verify Instead',
|
|
45
|
-
description: 'Replace decode with verify to ensure authenticity',
|
|
46
|
-
severity: 'LOW',
|
|
47
|
-
fix: 'jwt.verify(token, secret, { algorithms: ["RS256"] })',
|
|
48
|
-
documentationLink: 'https://www.npmjs.com/package/jsonwebtoken',
|
|
49
|
-
}),
|
|
50
|
-
},
|
|
51
|
-
schema: [
|
|
52
|
-
{
|
|
53
|
-
type: 'object',
|
|
54
|
-
properties: {
|
|
55
|
-
allowHeaderInspection: {
|
|
56
|
-
type: 'boolean',
|
|
57
|
-
default: false,
|
|
58
|
-
description: 'Allow decode() for reading header before verification',
|
|
59
|
-
},
|
|
60
|
-
trustedSanitizers: {
|
|
61
|
-
type: 'array',
|
|
62
|
-
items: { type: 'string' },
|
|
63
|
-
default: [],
|
|
64
|
-
},
|
|
65
|
-
trustedAnnotations: {
|
|
66
|
-
type: 'array',
|
|
67
|
-
items: { type: 'string' },
|
|
68
|
-
default: ['@decoded-header-only', '@verified-separately'],
|
|
69
|
-
},
|
|
70
|
-
strictMode: {
|
|
71
|
-
type: 'boolean',
|
|
72
|
-
default: false,
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
additionalProperties: false,
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
defaultOptions: [
|
|
80
|
-
{
|
|
81
|
-
allowHeaderInspection: false,
|
|
82
|
-
trustedSanitizers: [],
|
|
83
|
-
trustedAnnotations: ['@decoded-header-only', '@verified-separately'],
|
|
84
|
-
strictMode: false,
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
create(context) {
|
|
88
|
-
const options = context.options[0] ?? {};
|
|
89
|
-
const { trustedAnnotations = [] } = options;
|
|
90
|
-
/**
|
|
91
|
-
* Check if this is a jwt-decode import usage
|
|
92
|
-
*/
|
|
93
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
94
|
-
const isJwtDecodeLibrary = (node) => {
|
|
95
|
-
// Direct call: jwtDecode(token)
|
|
96
|
-
if (node.callee.type === 'Identifier' &&
|
|
97
|
-
(node.callee.name === 'jwtDecode' || node.callee.name === 'jwt_decode')) {
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
};
|
|
102
|
-
return {
|
|
103
|
-
CallExpression(node) {
|
|
104
|
-
// Check for jwt.decode() pattern
|
|
105
|
-
if ((0, utils_1.isDecodeOperation)(node)) {
|
|
106
|
-
// Check for safe annotations
|
|
107
|
-
if ((0, eslint_devkit_1.hasSafeAnnotation)(node, context, trustedAnnotations)) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
context.report({
|
|
111
|
-
node,
|
|
112
|
-
messageId: 'decodeWithoutVerify',
|
|
113
|
-
});
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
// Check for jwt-decode library usage
|
|
117
|
-
if (isJwtDecodeLibrary(node)) {
|
|
118
|
-
// Check for safe annotations
|
|
119
|
-
if ((0, eslint_devkit_1.hasSafeAnnotation)(node, context, trustedAnnotations)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
context.report({
|
|
123
|
-
node,
|
|
124
|
-
messageId: 'jwtDecodeLibrary',
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
exports.default = exports.noDecodeWithoutVerify;
|
|
@@ -1,23 +0,0 @@
|
|
|
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-hardcoded-secret
|
|
8
|
-
*
|
|
9
|
-
* Detects hardcoded secrets in JWT sign/verify operations.
|
|
10
|
-
* Hardcoded secrets in source code are a critical security vulnerability.
|
|
11
|
-
*
|
|
12
|
-
* CWE-798: Use of Hard-coded Credentials
|
|
13
|
-
*
|
|
14
|
-
* @see https://cwe.mitre.org/data/definitions/798.html
|
|
15
|
-
*/
|
|
16
|
-
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
17
|
-
import type { NoHardcodedSecretOptions } from '../../types';
|
|
18
|
-
type MessageIds = 'hardcodedSecret' | 'useEnvVariable';
|
|
19
|
-
type RuleOptions = [NoHardcodedSecretOptions?];
|
|
20
|
-
export declare const noHardcodedSecret: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
21
|
-
name: string;
|
|
22
|
-
};
|
|
23
|
-
export default noHardcodedSecret;
|
|
@@ -1,189 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.noHardcodedSecret = void 0;
|
|
9
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
exports.noHardcodedSecret = (0, eslint_devkit_1.createRule)({
|
|
12
|
-
name: 'no-hardcoded-secret',
|
|
13
|
-
meta: {
|
|
14
|
-
type: 'problem',
|
|
15
|
-
docs: {
|
|
16
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-hardcoded-secret.md',
|
|
17
|
-
description: 'Disallow hardcoded secrets in JWT sign/verify operations',
|
|
18
|
-
cwe: 'CWE-798',
|
|
19
|
-
cvss: 9.8,
|
|
20
|
-
},
|
|
21
|
-
fixable: undefined,
|
|
22
|
-
hasSuggestions: false,
|
|
23
|
-
messages: {
|
|
24
|
-
hardcodedSecret: (0, eslint_devkit_1.formatLLMMessage)({
|
|
25
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
26
|
-
issueName: 'Hardcoded JWT Secret',
|
|
27
|
-
cwe: 'CWE-798',
|
|
28
|
-
description: 'Secret key hardcoded in source code can be extracted from repositories',
|
|
29
|
-
severity: 'HIGH',
|
|
30
|
-
fix: 'Use process.env.JWT_SECRET or secure secret management',
|
|
31
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/798.html',
|
|
32
|
-
}),
|
|
33
|
-
useEnvVariable: (0, eslint_devkit_1.formatLLMMessage)({
|
|
34
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
35
|
-
issueName: 'Use Environment Variable',
|
|
36
|
-
description: 'Replace hardcoded secret with environment variable',
|
|
37
|
-
severity: 'LOW',
|
|
38
|
-
fix: 'process.env.JWT_SECRET',
|
|
39
|
-
documentationLink: 'https://12factor.net/config',
|
|
40
|
-
}),
|
|
41
|
-
},
|
|
42
|
-
schema: [
|
|
43
|
-
{
|
|
44
|
-
type: 'object',
|
|
45
|
-
properties: {
|
|
46
|
-
envPatterns: {
|
|
47
|
-
type: 'array',
|
|
48
|
-
items: { type: 'string' },
|
|
49
|
-
default: [],
|
|
50
|
-
description: 'Patterns that indicate safe environment variable usage',
|
|
51
|
-
},
|
|
52
|
-
trustedSanitizers: {
|
|
53
|
-
type: 'array',
|
|
54
|
-
items: { type: 'string' },
|
|
55
|
-
default: [],
|
|
56
|
-
},
|
|
57
|
-
trustedAnnotations: {
|
|
58
|
-
type: 'array',
|
|
59
|
-
items: { type: 'string' },
|
|
60
|
-
default: [],
|
|
61
|
-
},
|
|
62
|
-
strictMode: {
|
|
63
|
-
type: 'boolean',
|
|
64
|
-
default: false,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
additionalProperties: false,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
defaultOptions: [
|
|
72
|
-
{
|
|
73
|
-
envPatterns: [],
|
|
74
|
-
trustedSanitizers: [],
|
|
75
|
-
trustedAnnotations: [],
|
|
76
|
-
strictMode: false,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
create(context) {
|
|
80
|
-
/**
|
|
81
|
-
* Check if a node is a hardcoded string literal
|
|
82
|
-
*/
|
|
83
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
84
|
-
const isHardcodedString = (node) => {
|
|
85
|
-
// String literal
|
|
86
|
-
if (node.type === 'Literal' && typeof node.value === 'string') {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
// Template literal without expressions
|
|
90
|
-
if (node.type === 'TemplateLiteral' &&
|
|
91
|
-
node.expressions.length === 0) {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Resolve an Identifier node to its initializer (one frame of indirection).
|
|
98
|
-
* Closes the audit FN where `const SECRET = 'x'; jwt.sign(p, SECRET)`
|
|
99
|
-
* was treated as safe — the literal-via-const pattern hides the
|
|
100
|
-
* hardcoded secret behind one declaration. See benchmarks/AUDIT_PATTERNS.md
|
|
101
|
-
* §3.2 ("Indirection through one level of variable").
|
|
102
|
-
*/
|
|
103
|
-
const resolveConstLiteralValue = (node) => {
|
|
104
|
-
if (node.type !== 'Identifier')
|
|
105
|
-
return null;
|
|
106
|
-
const scope = context.sourceCode.getScope?.(node) ?? null;
|
|
107
|
-
if (!scope)
|
|
108
|
-
return null;
|
|
109
|
-
const variable = scope.references.find((r) => r.identifier === node)?.resolved;
|
|
110
|
-
const def = variable?.defs[0];
|
|
111
|
-
if (!def || def.type !== 'Variable')
|
|
112
|
-
return null;
|
|
113
|
-
const decl = def.parent;
|
|
114
|
-
if (decl?.type !== 'VariableDeclaration' || decl.kind !== 'const')
|
|
115
|
-
return null;
|
|
116
|
-
return def.node.init ?? null;
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* Check if node is a safe key source
|
|
120
|
-
*/
|
|
121
|
-
const isSafeKeySource = (node) => {
|
|
122
|
-
// Environment variable
|
|
123
|
-
if ((0, utils_1.isEnvVariable)(node)) {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
// Function call (getSecret(), loadKey(), etc.)
|
|
127
|
-
if (node.type === 'CallExpression') {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
// await expression (async key loading)
|
|
131
|
-
if (node.type === 'AwaitExpression') {
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
// Variable reference: resolve `const X = ...` one level. If X is a
|
|
135
|
-
// hardcoded literal, treat as unsafe — fall through to the
|
|
136
|
-
// hardcoded check. Otherwise (env var, call, identifier chain)
|
|
137
|
-
// it's safe.
|
|
138
|
-
if (node.type === 'Identifier') {
|
|
139
|
-
const init = resolveConstLiteralValue(node);
|
|
140
|
-
if (init && isHardcodedString(init)) {
|
|
141
|
-
// Unsafe — let the caller's `isHardcodedString` (with the
|
|
142
|
-
// resolved init) flag it.
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
// Member expression but not literal (config.secret, etc.)
|
|
148
|
-
if (node.type === 'MemberExpression' && !isHardcodedString(node)) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
};
|
|
153
|
-
/**
|
|
154
|
-
* Like isHardcodedString but resolves single-level `const X = '...'`
|
|
155
|
-
* indirection so the caller fires on `const SECRET = 'x'; jwt.sign(p, SECRET)`.
|
|
156
|
-
*/
|
|
157
|
-
const isHardcodedStringOrResolvedConst = (node) => {
|
|
158
|
-
if (isHardcodedString(node))
|
|
159
|
-
return true;
|
|
160
|
-
const init = resolveConstLiteralValue(node);
|
|
161
|
-
return init ? isHardcodedString(init) : false;
|
|
162
|
-
};
|
|
163
|
-
return {
|
|
164
|
-
CallExpression(node) {
|
|
165
|
-
// Check both sign and verify operations
|
|
166
|
-
if (!(0, utils_1.isSignOperation)(node) && !(0, utils_1.isVerifyOperation)(node)) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
// Secret/key is the second argument
|
|
170
|
-
if (node.arguments.length < 2) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const secretArg = node.arguments[1];
|
|
174
|
-
// Skip if safe source
|
|
175
|
-
if (isSafeKeySource(secretArg)) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
// Flag hardcoded strings (also follows single-frame `const X = '...'`).
|
|
179
|
-
if (isHardcodedStringOrResolvedConst(secretArg)) {
|
|
180
|
-
context.report({
|
|
181
|
-
node: secretArg,
|
|
182
|
-
messageId: 'hardcodedSecret',
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
exports.default = exports.noHardcodedSecret;
|
|
@@ -1,20 +0,0 @@
|
|
|
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-sensitive-payload
|
|
8
|
-
*
|
|
9
|
-
* Detects storage of sensitive data in JWT payload.
|
|
10
|
-
* JWT payloads are only base64-encoded, not encrypted.
|
|
11
|
-
*
|
|
12
|
-
* CWE-359: Exposure of Private Personal Information
|
|
13
|
-
*/
|
|
14
|
-
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
15
|
-
import type { NoSensitivePayloadOptions } from '../../types';
|
|
16
|
-
type RuleOptions = [NoSensitivePayloadOptions?];
|
|
17
|
-
export declare const noSensitivePayload: TSESLint.RuleModule<"sensitivePayloadField", RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
18
|
-
name: string;
|
|
19
|
-
};
|
|
20
|
-
export default noSensitivePayload;
|