eslint-plugin-jwt-security 2.3.1 → 2.3.3
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 +1 -1
- package/package.json +3 -3
- package/src/index.js +1 -118
- package/src/oxlint.js +1 -3
- package/src/rules/no-algorithm-confusion/index.js +1 -145
- package/src/rules/no-algorithm-none/index.js +1 -184
- package/src/rules/no-decode-without-verify/index.js +1 -117
- package/src/rules/no-hardcoded-secret/index.js +1 -150
- package/src/rules/no-sensitive-payload/index.js +1 -97
- package/src/rules/no-timestamp-manipulation/index.js +1 -91
- package/src/rules/no-weak-secret/index.js +1 -146
- package/src/rules/require-algorithm-whitelist/index.js +1 -104
- package/src/rules/require-audience-validation/index.js +1 -93
- package/src/rules/require-expiration/index.js +1 -120
- package/src/rules/require-issued-at/index.js +1 -92
- package/src/rules/require-issuer-validation/index.js +1 -93
- package/src/rules/require-max-age/index.js +1 -86
- package/src/types/index.js +1 -2
- package/src/utils/index.js +1 -165
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ By structuring errors with specific CWE codes, OWASP categories, and direct fix
|
|
|
81
81
|
## 📦 Compatibility
|
|
82
82
|
| Package | Version |
|
|
83
83
|
| :--- | :--- |
|
|
84
|
-
| ESLint | `^8.
|
|
84
|
+
| ESLint | `^8.40.0 \|\| ^9.0.0 \|\| ^10.0.0` |
|
|
85
85
|
| Node.js | `>=18.0.0` |
|
|
86
86
|
|
|
87
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jwt-security",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
4
4
|
"description": "ESLint plugin for JWT security — detects algorithm confusion (CVE-2022-23540), alg:none, weak or hardcoded secrets, and decode-without-verify.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
"node": ">=18.0.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@interlace/eslint-devkit": "^1.
|
|
82
|
+
"@interlace/eslint-devkit": "^1.11.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"eslint": "^8.
|
|
85
|
+
"eslint": "^8.40.0 || ^9.0.0 || ^10.0.0",
|
|
86
86
|
"jsonwebtoken": "^8.0.0 || ^9.0.0",
|
|
87
87
|
"@nestjs/jwt": "^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
88
88
|
"express-jwt": "^7.0.0 || ^8.0.0",
|
package/src/index.js
CHANGED
|
@@ -1,118 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noSensitivePayload = exports.requireMaxAge = exports.noTimestampManipulation = exports.requireAudienceValidation = exports.requireIssuerValidation = exports.requireIssuedAt = exports.noHardcodedSecret = exports.requireExpiration = exports.noWeakSecret = exports.noDecodeWithoutVerify = exports.requireAlgorithmWhitelist = exports.noAlgorithmConfusion = exports.noAlgorithmNone = exports.configs = exports.plugin = exports.rules = void 0;
|
|
4
|
-
const no_algorithm_none_1 = require("./rules/no-algorithm-none");
|
|
5
|
-
Object.defineProperty(exports, "noAlgorithmNone", { enumerable: true, get: function () { return no_algorithm_none_1.noAlgorithmNone; } });
|
|
6
|
-
const no_algorithm_confusion_1 = require("./rules/no-algorithm-confusion");
|
|
7
|
-
Object.defineProperty(exports, "noAlgorithmConfusion", { enumerable: true, get: function () { return no_algorithm_confusion_1.noAlgorithmConfusion; } });
|
|
8
|
-
const require_algorithm_whitelist_1 = require("./rules/require-algorithm-whitelist");
|
|
9
|
-
Object.defineProperty(exports, "requireAlgorithmWhitelist", { enumerable: true, get: function () { return require_algorithm_whitelist_1.requireAlgorithmWhitelist; } });
|
|
10
|
-
const no_decode_without_verify_1 = require("./rules/no-decode-without-verify");
|
|
11
|
-
Object.defineProperty(exports, "noDecodeWithoutVerify", { enumerable: true, get: function () { return no_decode_without_verify_1.noDecodeWithoutVerify; } });
|
|
12
|
-
const no_weak_secret_1 = require("./rules/no-weak-secret");
|
|
13
|
-
Object.defineProperty(exports, "noWeakSecret", { enumerable: true, get: function () { return no_weak_secret_1.noWeakSecret; } });
|
|
14
|
-
const require_expiration_1 = require("./rules/require-expiration");
|
|
15
|
-
Object.defineProperty(exports, "requireExpiration", { enumerable: true, get: function () { return require_expiration_1.requireExpiration; } });
|
|
16
|
-
const no_hardcoded_secret_1 = require("./rules/no-hardcoded-secret");
|
|
17
|
-
Object.defineProperty(exports, "noHardcodedSecret", { enumerable: true, get: function () { return no_hardcoded_secret_1.noHardcodedSecret; } });
|
|
18
|
-
const require_issued_at_1 = require("./rules/require-issued-at");
|
|
19
|
-
Object.defineProperty(exports, "requireIssuedAt", { enumerable: true, get: function () { return require_issued_at_1.requireIssuedAt; } });
|
|
20
|
-
const require_issuer_validation_1 = require("./rules/require-issuer-validation");
|
|
21
|
-
Object.defineProperty(exports, "requireIssuerValidation", { enumerable: true, get: function () { return require_issuer_validation_1.requireIssuerValidation; } });
|
|
22
|
-
const require_audience_validation_1 = require("./rules/require-audience-validation");
|
|
23
|
-
Object.defineProperty(exports, "requireAudienceValidation", { enumerable: true, get: function () { return require_audience_validation_1.requireAudienceValidation; } });
|
|
24
|
-
const no_timestamp_manipulation_1 = require("./rules/no-timestamp-manipulation");
|
|
25
|
-
Object.defineProperty(exports, "noTimestampManipulation", { enumerable: true, get: function () { return no_timestamp_manipulation_1.noTimestampManipulation; } });
|
|
26
|
-
const require_max_age_1 = require("./rules/require-max-age");
|
|
27
|
-
Object.defineProperty(exports, "requireMaxAge", { enumerable: true, get: function () { return require_max_age_1.requireMaxAge; } });
|
|
28
|
-
const no_sensitive_payload_1 = require("./rules/no-sensitive-payload");
|
|
29
|
-
Object.defineProperty(exports, "noSensitivePayload", { enumerable: true, get: function () { return no_sensitive_payload_1.noSensitivePayload; } });
|
|
30
|
-
exports.rules = {
|
|
31
|
-
get 'no-algorithm-none'() { return require("./rules/no-algorithm-none").noAlgorithmNone; },
|
|
32
|
-
get 'no-algorithm-confusion'() { return require("./rules/no-algorithm-confusion").noAlgorithmConfusion; },
|
|
33
|
-
get 'require-algorithm-whitelist'() { return require("./rules/require-algorithm-whitelist").requireAlgorithmWhitelist; },
|
|
34
|
-
get 'no-decode-without-verify'() { return require("./rules/no-decode-without-verify").noDecodeWithoutVerify; },
|
|
35
|
-
get 'no-weak-secret'() { return require("./rules/no-weak-secret").noWeakSecret; },
|
|
36
|
-
get 'require-expiration'() { return require("./rules/require-expiration").requireExpiration; },
|
|
37
|
-
get 'no-hardcoded-secret'() { return require("./rules/no-hardcoded-secret").noHardcodedSecret; },
|
|
38
|
-
get 'require-issued-at'() { return require("./rules/require-issued-at").requireIssuedAt; },
|
|
39
|
-
get 'require-issuer-validation'() { return require("./rules/require-issuer-validation").requireIssuerValidation; },
|
|
40
|
-
get 'require-audience-validation'() { return require("./rules/require-audience-validation").requireAudienceValidation; },
|
|
41
|
-
get 'no-timestamp-manipulation'() { return require("./rules/no-timestamp-manipulation").noTimestampManipulation; },
|
|
42
|
-
get 'require-max-age'() { return require("./rules/require-max-age").requireMaxAge; },
|
|
43
|
-
get 'no-sensitive-payload'() { return require("./rules/no-sensitive-payload").noSensitivePayload; },
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
exports.plugin = {
|
|
47
|
-
meta: {
|
|
48
|
-
name: 'eslint-plugin-jwt-security',
|
|
49
|
-
version: '2.3.1',
|
|
50
|
-
},
|
|
51
|
-
rules: exports.rules,
|
|
52
|
-
};
|
|
53
|
-
const recommendedRules = {
|
|
54
|
-
'jwt/no-algorithm-none': 'error',
|
|
55
|
-
'jwt/no-algorithm-confusion': 'error',
|
|
56
|
-
'jwt/require-algorithm-whitelist': 'error',
|
|
57
|
-
'jwt/no-decode-without-verify': 'error',
|
|
58
|
-
'jwt/no-weak-secret': 'error',
|
|
59
|
-
'jwt/no-hardcoded-secret': 'error',
|
|
60
|
-
'jwt/no-timestamp-manipulation': 'error',
|
|
61
|
-
'jwt/require-expiration': 'error',
|
|
62
|
-
'jwt/no-sensitive-payload': 'warn',
|
|
63
|
-
};
|
|
64
|
-
const strictRules = {
|
|
65
|
-
'jwt/no-algorithm-none': 'error',
|
|
66
|
-
'jwt/no-algorithm-confusion': 'error',
|
|
67
|
-
'jwt/require-algorithm-whitelist': 'error',
|
|
68
|
-
'jwt/no-decode-without-verify': 'error',
|
|
69
|
-
'jwt/no-weak-secret': 'error',
|
|
70
|
-
'jwt/no-hardcoded-secret': 'error',
|
|
71
|
-
'jwt/require-expiration': 'error',
|
|
72
|
-
'jwt/require-issued-at': 'error',
|
|
73
|
-
'jwt/require-issuer-validation': 'error',
|
|
74
|
-
'jwt/require-audience-validation': 'error',
|
|
75
|
-
'jwt/no-timestamp-manipulation': 'error',
|
|
76
|
-
'jwt/require-max-age': 'error',
|
|
77
|
-
'jwt/no-sensitive-payload': 'error',
|
|
78
|
-
};
|
|
79
|
-
const legacyRules = {
|
|
80
|
-
'jwt/no-algorithm-none': 'error',
|
|
81
|
-
'jwt/no-algorithm-confusion': 'error',
|
|
82
|
-
'jwt/no-hardcoded-secret': 'warn',
|
|
83
|
-
};
|
|
84
|
-
exports.configs = {
|
|
85
|
-
flagship: {
|
|
86
|
-
plugins: {
|
|
87
|
-
jwt: exports.plugin,
|
|
88
|
-
},
|
|
89
|
-
rules: {
|
|
90
|
-
'jwt/no-algorithm-none': 'error',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
recommended: {
|
|
94
|
-
plugins: {
|
|
95
|
-
jwt: exports.plugin,
|
|
96
|
-
},
|
|
97
|
-
rules: recommendedRules,
|
|
98
|
-
},
|
|
99
|
-
strict: {
|
|
100
|
-
plugins: {
|
|
101
|
-
jwt: exports.plugin,
|
|
102
|
-
},
|
|
103
|
-
rules: strictRules,
|
|
104
|
-
},
|
|
105
|
-
legacy: {
|
|
106
|
-
plugins: {
|
|
107
|
-
jwt: exports.plugin,
|
|
108
|
-
},
|
|
109
|
-
rules: legacyRules,
|
|
110
|
-
},
|
|
111
|
-
all: {
|
|
112
|
-
plugins: {
|
|
113
|
-
jwt: exports.plugin,
|
|
114
|
-
},
|
|
115
|
-
rules: strictRules,
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
exports.default = exports.plugin;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSensitivePayload=exports.requireMaxAge=exports.noTimestampManipulation=exports.requireAudienceValidation=exports.requireIssuerValidation=exports.requireIssuedAt=exports.noHardcodedSecret=exports.requireExpiration=exports.noWeakSecret=exports.noDecodeWithoutVerify=exports.requireAlgorithmWhitelist=exports.noAlgorithmConfusion=exports.noAlgorithmNone=exports.configs=exports.plugin=exports.rules=void 0;const no_algorithm_none_1=require("./rules/no-algorithm-none");Object.defineProperty(exports,"noAlgorithmNone",{enumerable:true,get:function(){return no_algorithm_none_1.noAlgorithmNone}});const no_algorithm_confusion_1=require("./rules/no-algorithm-confusion");Object.defineProperty(exports,"noAlgorithmConfusion",{enumerable:true,get:function(){return no_algorithm_confusion_1.noAlgorithmConfusion}});const require_algorithm_whitelist_1=require("./rules/require-algorithm-whitelist");Object.defineProperty(exports,"requireAlgorithmWhitelist",{enumerable:true,get:function(){return require_algorithm_whitelist_1.requireAlgorithmWhitelist}});const no_decode_without_verify_1=require("./rules/no-decode-without-verify");Object.defineProperty(exports,"noDecodeWithoutVerify",{enumerable:true,get:function(){return no_decode_without_verify_1.noDecodeWithoutVerify}});const no_weak_secret_1=require("./rules/no-weak-secret");Object.defineProperty(exports,"noWeakSecret",{enumerable:true,get:function(){return no_weak_secret_1.noWeakSecret}});const require_expiration_1=require("./rules/require-expiration");Object.defineProperty(exports,"requireExpiration",{enumerable:true,get:function(){return require_expiration_1.requireExpiration}});const no_hardcoded_secret_1=require("./rules/no-hardcoded-secret");Object.defineProperty(exports,"noHardcodedSecret",{enumerable:true,get:function(){return no_hardcoded_secret_1.noHardcodedSecret}});const require_issued_at_1=require("./rules/require-issued-at");Object.defineProperty(exports,"requireIssuedAt",{enumerable:true,get:function(){return require_issued_at_1.requireIssuedAt}});const require_issuer_validation_1=require("./rules/require-issuer-validation");Object.defineProperty(exports,"requireIssuerValidation",{enumerable:true,get:function(){return require_issuer_validation_1.requireIssuerValidation}});const require_audience_validation_1=require("./rules/require-audience-validation");Object.defineProperty(exports,"requireAudienceValidation",{enumerable:true,get:function(){return require_audience_validation_1.requireAudienceValidation}});const no_timestamp_manipulation_1=require("./rules/no-timestamp-manipulation");Object.defineProperty(exports,"noTimestampManipulation",{enumerable:true,get:function(){return no_timestamp_manipulation_1.noTimestampManipulation}});const require_max_age_1=require("./rules/require-max-age");Object.defineProperty(exports,"requireMaxAge",{enumerable:true,get:function(){return require_max_age_1.requireMaxAge}});const no_sensitive_payload_1=require("./rules/no-sensitive-payload");Object.defineProperty(exports,"noSensitivePayload",{enumerable:true,get:function(){return no_sensitive_payload_1.noSensitivePayload}});exports.rules={get"no-algorithm-none"(){return require("./rules/no-algorithm-none").noAlgorithmNone},get"no-algorithm-confusion"(){return require("./rules/no-algorithm-confusion").noAlgorithmConfusion},get"require-algorithm-whitelist"(){return require("./rules/require-algorithm-whitelist").requireAlgorithmWhitelist},get"no-decode-without-verify"(){return require("./rules/no-decode-without-verify").noDecodeWithoutVerify},get"no-weak-secret"(){return require("./rules/no-weak-secret").noWeakSecret},get"require-expiration"(){return require("./rules/require-expiration").requireExpiration},get"no-hardcoded-secret"(){return require("./rules/no-hardcoded-secret").noHardcodedSecret},get"require-issued-at"(){return require("./rules/require-issued-at").requireIssuedAt},get"require-issuer-validation"(){return require("./rules/require-issuer-validation").requireIssuerValidation},get"require-audience-validation"(){return require("./rules/require-audience-validation").requireAudienceValidation},get"no-timestamp-manipulation"(){return require("./rules/no-timestamp-manipulation").noTimestampManipulation},get"require-max-age"(){return require("./rules/require-max-age").requireMaxAge},get"no-sensitive-payload"(){return require("./rules/no-sensitive-payload").noSensitivePayload}};exports.plugin={meta:{name:"eslint-plugin-jwt-security",version:"2.3.3"},rules:exports.rules};const recommendedRules={"jwt/no-algorithm-none":"error","jwt/no-algorithm-confusion":"error","jwt/require-algorithm-whitelist":"error","jwt/no-decode-without-verify":"error","jwt/no-weak-secret":"error","jwt/no-hardcoded-secret":"error","jwt/no-timestamp-manipulation":"error","jwt/require-expiration":"error","jwt/no-sensitive-payload":"warn"};const strictRules={"jwt/no-algorithm-none":"error","jwt/no-algorithm-confusion":"error","jwt/require-algorithm-whitelist":"error","jwt/no-decode-without-verify":"error","jwt/no-weak-secret":"error","jwt/no-hardcoded-secret":"error","jwt/require-expiration":"error","jwt/require-issued-at":"error","jwt/require-issuer-validation":"error","jwt/require-audience-validation":"error","jwt/no-timestamp-manipulation":"error","jwt/require-max-age":"error","jwt/no-sensitive-payload":"error"};const legacyRules={"jwt/no-algorithm-none":"error","jwt/no-algorithm-confusion":"error","jwt/no-hardcoded-secret":"warn"};exports.configs={flagship:{plugins:{jwt:exports.plugin},rules:{"jwt/no-algorithm-none":"error"}},recommended:{plugins:{jwt:exports.plugin},rules:recommendedRules},strict:{plugins:{jwt:exports.plugin},rules:strictRules},legacy:{plugins:{jwt:exports.plugin},rules:legacyRules},all:{plugins:{jwt:exports.plugin},rules:strictRules}};exports.default=exports.plugin;
|
package/src/oxlint.js
CHANGED
|
@@ -1,145 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noAlgorithmConfusion = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
const PUBLIC_KEY_PATTERNS = [
|
|
7
|
-
/public/i,
|
|
8
|
-
/\.pub$/,
|
|
9
|
-
/\.pem$/,
|
|
10
|
-
/-----BEGIN PUBLIC KEY-----/,
|
|
11
|
-
/-----BEGIN RSA PUBLIC KEY-----/,
|
|
12
|
-
/-----BEGIN EC PUBLIC KEY-----/,
|
|
13
|
-
/getPublicKey/i,
|
|
14
|
-
/publicKey/i,
|
|
15
|
-
/jwks/i,
|
|
16
|
-
];
|
|
17
|
-
exports.noAlgorithmConfusion = (0, eslint_devkit_1.createRule)({
|
|
18
|
-
name: 'no-algorithm-confusion',
|
|
19
|
-
meta: {
|
|
20
|
-
type: 'problem',
|
|
21
|
-
docs: {
|
|
22
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-algorithm-confusion.md',
|
|
23
|
-
description: 'Prevent algorithm confusion attacks using symmetric algorithms with asymmetric keys',
|
|
24
|
-
cwe: 'CWE-347',
|
|
25
|
-
cvss: 9.5,
|
|
26
|
-
},
|
|
27
|
-
fixable: undefined,
|
|
28
|
-
hasSuggestions: false,
|
|
29
|
-
messages: {
|
|
30
|
-
algorithmConfusion: (0, eslint_devkit_1.formatLLMMessage)({
|
|
31
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
32
|
-
issueName: 'JWT Algorithm Confusion Attack',
|
|
33
|
-
cwe: 'CWE-347',
|
|
34
|
-
description: 'Symmetric algorithm (HS*) used with public key allows token forgery',
|
|
35
|
-
severity: 'CRITICAL',
|
|
36
|
-
fix: 'Use asymmetric algorithms (RS256, ES256) with public keys',
|
|
37
|
-
documentationLink: 'https://portswigger.net/web-security/jwt/algorithm-confusion',
|
|
38
|
-
}),
|
|
39
|
-
symmetricWithPublicKey: (0, eslint_devkit_1.formatLLMMessage)({
|
|
40
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
41
|
-
issueName: 'Symmetric Algorithm with Public Key',
|
|
42
|
-
cwe: 'CWE-347',
|
|
43
|
-
description: 'HS256/384/512 should only be used with shared secrets, not public keys',
|
|
44
|
-
severity: 'CRITICAL',
|
|
45
|
-
fix: 'Switch to RS256 or ES256 for asymmetric key verification',
|
|
46
|
-
documentationLink: 'https://portswigger.net/web-security/jwt/algorithm-confusion',
|
|
47
|
-
}),
|
|
48
|
-
useAsymmetricAlgorithm: (0, eslint_devkit_1.formatLLMMessage)({
|
|
49
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
50
|
-
issueName: 'Use Asymmetric Algorithm',
|
|
51
|
-
description: 'Replace HS* with RS* or ES* algorithm',
|
|
52
|
-
severity: 'LOW',
|
|
53
|
-
fix: 'Use RS256 or ES256 with public key verification',
|
|
54
|
-
documentationLink: 'https://tools.ietf.org/html/rfc8725',
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
57
|
-
schema: [
|
|
58
|
-
{
|
|
59
|
-
type: 'object',
|
|
60
|
-
properties: {
|
|
61
|
-
symmetricAlgorithms: {
|
|
62
|
-
type: 'array',
|
|
63
|
-
items: { type: 'string' },
|
|
64
|
-
default: ['HS256', 'HS384', 'HS512'],
|
|
65
|
-
description: 'Algorithms to flag when used with public keys',
|
|
66
|
-
},
|
|
67
|
-
trustedSanitizers: {
|
|
68
|
-
type: 'array',
|
|
69
|
-
items: { type: 'string' },
|
|
70
|
-
default: [],
|
|
71
|
-
},
|
|
72
|
-
trustedAnnotations: {
|
|
73
|
-
type: 'array',
|
|
74
|
-
items: { type: 'string' },
|
|
75
|
-
default: [],
|
|
76
|
-
},
|
|
77
|
-
strictMode: {
|
|
78
|
-
type: 'boolean',
|
|
79
|
-
default: false,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
additionalProperties: false,
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
defaultOptions: [
|
|
87
|
-
{
|
|
88
|
-
symmetricAlgorithms: ['HS256', 'HS384', 'HS512'],
|
|
89
|
-
trustedSanitizers: [],
|
|
90
|
-
trustedAnnotations: [],
|
|
91
|
-
strictMode: false,
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
create(context) {
|
|
95
|
-
const options = context.options[0] ?? {};
|
|
96
|
-
const symmetricAlgSet = new Set(options.symmetricAlgorithms ?? ['HS256', 'HS384', 'HS512']);
|
|
97
|
-
const sourceCode = context.sourceCode;
|
|
98
|
-
const looksLikePublicKey = (node) => {
|
|
99
|
-
const text = sourceCode.getText(node);
|
|
100
|
-
return PUBLIC_KEY_PATTERNS.some((pattern) => pattern.test(text));
|
|
101
|
-
};
|
|
102
|
-
const hasSymmetricAlgorithm = (algorithms) => {
|
|
103
|
-
for (const alg of algorithms) {
|
|
104
|
-
if (symmetricAlgSet.has(alg)) {
|
|
105
|
-
return alg;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
};
|
|
110
|
-
return {
|
|
111
|
-
CallExpression(node) {
|
|
112
|
-
if (!(0, utils_1.isVerifyOperation)(node)) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (node.arguments.length < 2) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const keyArg = node.arguments[1];
|
|
119
|
-
const optionsArg = (0, utils_1.getOptionsArgument)(node, 2);
|
|
120
|
-
if (!looksLikePublicKey(keyArg)) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (optionsArg) {
|
|
124
|
-
const algorithms = (0, utils_1.extractAlgorithms)(optionsArg);
|
|
125
|
-
const symmetricAlg = hasSymmetricAlgorithm(algorithms);
|
|
126
|
-
if (symmetricAlg) {
|
|
127
|
-
for (const prop of optionsArg.properties) {
|
|
128
|
-
if (prop.type === 'Property' &&
|
|
129
|
-
prop.key.type === 'Identifier' &&
|
|
130
|
-
['algorithms', 'algorithm', 'alg'].includes(prop.key.name)) {
|
|
131
|
-
context.report({
|
|
132
|
-
node: prop.value,
|
|
133
|
-
messageId: 'algorithmConfusion',
|
|
134
|
-
data: { algorithm: symmetricAlg },
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
exports.default = exports.noAlgorithmConfusion;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noAlgorithmConfusion=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");const PUBLIC_KEY_PATTERNS=[/public/i,/\.pub$/,/\.pem$/,/-----BEGIN PUBLIC KEY-----/,/-----BEGIN RSA PUBLIC KEY-----/,/-----BEGIN EC PUBLIC KEY-----/,/getPublicKey/i,/publicKey/i,/jwks/i];exports.noAlgorithmConfusion=(0,eslint_devkit_1.createRule)({name:"no-algorithm-confusion",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-algorithm-confusion.md",description:"Prevent algorithm confusion attacks using symmetric algorithms with asymmetric keys",cwe:"CWE-347",cvss:9.5},fixable:void 0,hasSuggestions:false,messages:{algorithmConfusion:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"JWT Algorithm Confusion Attack",cwe:"CWE-347",description:"Symmetric algorithm (HS*) used with public key allows token forgery",severity:"CRITICAL",fix:"Use asymmetric algorithms (RS256, ES256) with public keys",documentationLink:"https://portswigger.net/web-security/jwt/algorithm-confusion"}),symmetricWithPublicKey:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Symmetric Algorithm with Public Key",cwe:"CWE-347",description:"HS256/384/512 should only be used with shared secrets, not public keys",severity:"CRITICAL",fix:"Switch to RS256 or ES256 for asymmetric key verification",documentationLink:"https://portswigger.net/web-security/jwt/algorithm-confusion"}),useAsymmetricAlgorithm:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Asymmetric Algorithm",description:"Replace HS* with RS* or ES* algorithm",severity:"LOW",fix:"Use RS256 or ES256 with public key verification",documentationLink:"https://tools.ietf.org/html/rfc8725"})},schema:[{type:"object",properties:{symmetricAlgorithms:{type:"array",items:{type:"string"},default:["HS256","HS384","HS512"],description:"Algorithms to flag when used with public keys"},trustedSanitizers:{type:"array",items:{type:"string"},default:[]},trustedAnnotations:{type:"array",items:{type:"string"},default:[]},strictMode:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{symmetricAlgorithms:["HS256","HS384","HS512"],trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]??{};const symmetricAlgSet=new Set(options.symmetricAlgorithms??["HS256","HS384","HS512"]);const sourceCode=context.sourceCode;const looksLikePublicKey=node=>{const text=sourceCode.getText(node);return PUBLIC_KEY_PATTERNS.some(pattern=>pattern.test(text))};const hasSymmetricAlgorithm=algorithms=>{for(const alg of algorithms){if(symmetricAlgSet.has(alg)){return alg}}return null};return{CallExpression(node){if(!(0,utils_1.isVerifyOperation)(node)){return}if(node.arguments.length<2){return}const keyArg=node.arguments[1];const optionsArg=(0,utils_1.getOptionsArgument)(node,2);if(!looksLikePublicKey(keyArg)){return}if(optionsArg){const algorithms=(0,utils_1.extractAlgorithms)(optionsArg);const symmetricAlg=hasSymmetricAlgorithm(algorithms);if(symmetricAlg){for(const prop of optionsArg.properties){if(prop.type==="Property"&&prop.key.type==="Identifier"&&["algorithms","algorithm","alg"].includes(prop.key.name)){context.report({node:prop.value,messageId:"algorithmConfusion",data:{algorithm:symmetricAlg}});return}}}}}}}});exports.default=exports.noAlgorithmConfusion;
|
|
@@ -1,184 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noAlgorithmNone = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
exports.noAlgorithmNone = (0, eslint_devkit_1.createRule)({
|
|
7
|
-
name: 'no-algorithm-none',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'problem',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-algorithm-none.md',
|
|
12
|
-
description: 'Disallow JWT "none" algorithm which bypasses signature verification (CVE-2022-23540)',
|
|
13
|
-
cwe: 'CWE-347',
|
|
14
|
-
cvss: 9.5,
|
|
15
|
-
confidence: 'high',
|
|
16
|
-
},
|
|
17
|
-
fixable: undefined,
|
|
18
|
-
hasSuggestions: false,
|
|
19
|
-
messages: {
|
|
20
|
-
algorithmNone: (0, eslint_devkit_1.formatLLMMessage)({
|
|
21
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
22
|
-
issueName: 'JWT Algorithm None Attack',
|
|
23
|
-
cwe: 'CWE-347',
|
|
24
|
-
description: 'Using alg:"none" bypasses signature verification, allowing token forgery',
|
|
25
|
-
severity: 'CRITICAL',
|
|
26
|
-
fix: 'Remove "none" and use RS256, ES256, or other secure algorithms',
|
|
27
|
-
documentationLink: 'https://nvd.nist.gov/vuln/detail/CVE-2022-23540',
|
|
28
|
-
}),
|
|
29
|
-
algorithmNoneInArray: (0, eslint_devkit_1.formatLLMMessage)({
|
|
30
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
31
|
-
issueName: 'JWT Algorithm None in Whitelist',
|
|
32
|
-
cwe: 'CWE-347',
|
|
33
|
-
description: 'Including "none" in algorithms array allows unsigned tokens',
|
|
34
|
-
severity: 'CRITICAL',
|
|
35
|
-
fix: 'Remove "none" from the algorithms array',
|
|
36
|
-
documentationLink: 'https://nvd.nist.gov/vuln/detail/CVE-2022-23540',
|
|
37
|
-
}),
|
|
38
|
-
emptyAlgorithms: (0, eslint_devkit_1.formatLLMMessage)({
|
|
39
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
40
|
-
issueName: 'Empty Algorithms Array',
|
|
41
|
-
cwe: 'CWE-347',
|
|
42
|
-
description: 'Empty algorithms array may default to accepting any algorithm including none',
|
|
43
|
-
severity: 'HIGH',
|
|
44
|
-
fix: 'Specify explicit algorithms: ["RS256"] or ["ES256"]',
|
|
45
|
-
documentationLink: 'https://tools.ietf.org/html/rfc8725',
|
|
46
|
-
}),
|
|
47
|
-
useSecureAlgorithm: (0, eslint_devkit_1.formatLLMMessage)({
|
|
48
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
49
|
-
issueName: 'Use Secure Algorithm',
|
|
50
|
-
description: 'Replace with a secure algorithm',
|
|
51
|
-
severity: 'LOW',
|
|
52
|
-
fix: 'Use algorithms: ["RS256"] or algorithms: ["ES256"]',
|
|
53
|
-
documentationLink: 'https://tools.ietf.org/html/rfc8725',
|
|
54
|
-
}),
|
|
55
|
-
decodeWithoutVerify: (0, eslint_devkit_1.formatLLMMessage)({
|
|
56
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
57
|
-
issueName: 'JWT Decode Without Verify',
|
|
58
|
-
cwe: 'CWE-347',
|
|
59
|
-
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.',
|
|
60
|
-
severity: 'CRITICAL',
|
|
61
|
-
fix: 'Use jwt.verify(token, secret, { algorithms: ["RS256"] }) instead. Reserve jwt.decode() for non-security inspection only (e.g. logging the issuer).',
|
|
62
|
-
documentationLink: 'https://github.com/auth0/node-jsonwebtoken#jwtdecodetoken--options',
|
|
63
|
-
}),
|
|
64
|
-
},
|
|
65
|
-
schema: [
|
|
66
|
-
{
|
|
67
|
-
type: 'object',
|
|
68
|
-
properties: {
|
|
69
|
-
allowInTests: {
|
|
70
|
-
type: 'boolean',
|
|
71
|
-
default: false,
|
|
72
|
-
description: 'Allow "none" algorithm in test files',
|
|
73
|
-
},
|
|
74
|
-
trustedSanitizers: {
|
|
75
|
-
type: 'array',
|
|
76
|
-
items: { type: 'string' },
|
|
77
|
-
default: [],
|
|
78
|
-
},
|
|
79
|
-
trustedAnnotations: {
|
|
80
|
-
type: 'array',
|
|
81
|
-
items: { type: 'string' },
|
|
82
|
-
default: [],
|
|
83
|
-
},
|
|
84
|
-
strictMode: {
|
|
85
|
-
type: 'boolean',
|
|
86
|
-
default: false,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
additionalProperties: false,
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
defaultOptions: [
|
|
94
|
-
{
|
|
95
|
-
allowInTests: false,
|
|
96
|
-
trustedSanitizers: [],
|
|
97
|
-
trustedAnnotations: [],
|
|
98
|
-
strictMode: false,
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
create(context) {
|
|
102
|
-
const options = context.options[0] ?? {};
|
|
103
|
-
const { allowInTests = false } = options;
|
|
104
|
-
const filename = context.filename;
|
|
105
|
-
if (allowInTests && (0, utils_1.isTestFile)(filename)) {
|
|
106
|
-
return {};
|
|
107
|
-
}
|
|
108
|
-
const isNoneAlgorithm = (value) => {
|
|
109
|
-
return value.toLowerCase() === 'none';
|
|
110
|
-
};
|
|
111
|
-
const checkOptionsForNone = (optionsNode) => {
|
|
112
|
-
for (const prop of optionsNode.properties) {
|
|
113
|
-
if (prop.type !== 'Property' || prop.key.type !== 'Identifier') {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
const keyName = prop.key.name;
|
|
117
|
-
if (keyName !== 'algorithms' &&
|
|
118
|
-
keyName !== 'algorithm' &&
|
|
119
|
-
keyName !== 'alg') {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (prop.value.type === 'Literal' &&
|
|
123
|
-
typeof prop.value.value === 'string') {
|
|
124
|
-
if (isNoneAlgorithm(prop.value.value)) {
|
|
125
|
-
context.report({
|
|
126
|
-
node: prop.value,
|
|
127
|
-
messageId: 'algorithmNone',
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (prop.value.type === 'ArrayExpression') {
|
|
132
|
-
if (prop.value.elements.length === 0) {
|
|
133
|
-
context.report({
|
|
134
|
-
node: prop.value,
|
|
135
|
-
messageId: 'emptyAlgorithms',
|
|
136
|
-
});
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
for (const elem of prop.value.elements) {
|
|
140
|
-
if (elem &&
|
|
141
|
-
elem.type === 'Literal' &&
|
|
142
|
-
typeof elem.value === 'string' &&
|
|
143
|
-
isNoneAlgorithm(elem.value)) {
|
|
144
|
-
context.report({
|
|
145
|
-
node: elem,
|
|
146
|
-
messageId: 'algorithmNoneInArray',
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
function isDecodeCall(node) {
|
|
154
|
-
const callee = node.callee;
|
|
155
|
-
if (callee.type !== 'MemberExpression')
|
|
156
|
-
return false;
|
|
157
|
-
if (callee.property.type !== 'Identifier')
|
|
158
|
-
return false;
|
|
159
|
-
if (callee.property.name !== 'decode')
|
|
160
|
-
return false;
|
|
161
|
-
if (callee.object.type === 'Identifier') {
|
|
162
|
-
const name = callee.object.name.toLowerCase();
|
|
163
|
-
return name === 'jwt' || name === 'jsonwebtoken';
|
|
164
|
-
}
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
CallExpression(node) {
|
|
169
|
-
if (isDecodeCall(node)) {
|
|
170
|
-
context.report({ node, messageId: 'decodeWithoutVerify' });
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (!(0, utils_1.isVerifyOperation)(node) && !(0, utils_1.isSignOperation)(node)) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
const optionsArg = (0, utils_1.getOptionsArgument)(node, 2);
|
|
177
|
-
if (optionsArg) {
|
|
178
|
-
checkOptionsForNone(optionsArg);
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
exports.default = exports.noAlgorithmNone;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noAlgorithmNone=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");exports.noAlgorithmNone=(0,eslint_devkit_1.createRule)({name:"no-algorithm-none",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-algorithm-none.md",description:'Disallow JWT "none" algorithm which bypasses signature verification (CVE-2022-23540)',cwe:"CWE-347",cvss:9.5,confidence:"high"},fixable:void 0,hasSuggestions:false,messages:{algorithmNone:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"JWT Algorithm None Attack",cwe:"CWE-347",description:'Using alg:"none" bypasses signature verification, allowing token forgery',severity:"CRITICAL",fix:'Remove "none" and use RS256, ES256, or other secure algorithms',documentationLink:"https://nvd.nist.gov/vuln/detail/CVE-2022-23540"}),algorithmNoneInArray:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"JWT Algorithm None in Whitelist",cwe:"CWE-347",description:'Including "none" in algorithms array allows unsigned tokens',severity:"CRITICAL",fix:'Remove "none" from the algorithms array',documentationLink:"https://nvd.nist.gov/vuln/detail/CVE-2022-23540"}),emptyAlgorithms:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Empty Algorithms Array",cwe:"CWE-347",description:"Empty algorithms array may default to accepting any algorithm including none",severity:"HIGH",fix:'Specify explicit algorithms: ["RS256"] or ["ES256"]',documentationLink:"https://tools.ietf.org/html/rfc8725"}),useSecureAlgorithm:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Secure Algorithm",description:"Replace with a secure algorithm",severity:"LOW",fix:'Use algorithms: ["RS256"] or algorithms: ["ES256"]',documentationLink:"https://tools.ietf.org/html/rfc8725"}),decodeWithoutVerify:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"JWT Decode Without Verify",cwe:"CWE-347",description:'jwt.decode() does NOT verify the signature \u2014 using its result as if it were authenticated is functionally equivalent to algorithm:"none". Any token, including forged ones, will decode.',severity:"CRITICAL",fix:'Use jwt.verify(token, secret, { algorithms: ["RS256"] }) instead. Reserve jwt.decode() for non-security inspection only (e.g. logging the issuer).',documentationLink:"https://github.com/auth0/node-jsonwebtoken#jwtdecodetoken--options"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:'Allow "none" algorithm in test files'},trustedSanitizers:{type:"array",items:{type:"string"},default:[]},trustedAnnotations:{type:"array",items:{type:"string"},default:[]},strictMode:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]??{};const{allowInTests=false}=options;const filename=context.filename;if(allowInTests&&(0,utils_1.isTestFile)(filename)){return{}}const isNoneAlgorithm=value=>{return value.toLowerCase()==="none"};const checkOptionsForNone=optionsNode=>{for(const prop of optionsNode.properties){if(prop.type!=="Property"||prop.key.type!=="Identifier"){continue}const keyName=prop.key.name;if(keyName!=="algorithms"&&keyName!=="algorithm"&&keyName!=="alg"){continue}if(prop.value.type==="Literal"&&typeof prop.value.value==="string"){if(isNoneAlgorithm(prop.value.value)){context.report({node:prop.value,messageId:"algorithmNone"})}}if(prop.value.type==="ArrayExpression"){if(prop.value.elements.length===0){context.report({node:prop.value,messageId:"emptyAlgorithms"});continue}for(const elem of prop.value.elements){if(elem&&elem.type==="Literal"&&typeof elem.value==="string"&&isNoneAlgorithm(elem.value)){context.report({node:elem,messageId:"algorithmNoneInArray"})}}}}};function isDecodeCall(node){const callee=node.callee;if(callee.type!=="MemberExpression")return false;if(callee.property.type!=="Identifier")return false;if(callee.property.name!=="decode")return false;if(callee.object.type==="Identifier"){const name=callee.object.name.toLowerCase();return name==="jwt"||name==="jsonwebtoken"}return false}return{CallExpression(node){if(isDecodeCall(node)){context.report({node,messageId:"decodeWithoutVerify"});return}if(!(0,utils_1.isVerifyOperation)(node)&&!(0,utils_1.isSignOperation)(node)){return}const optionsArg=(0,utils_1.getOptionsArgument)(node,2);if(optionsArg){checkOptionsForNone(optionsArg)}}}}});exports.default=exports.noAlgorithmNone;
|
|
@@ -1,117 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noDecodeWithoutVerify = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
exports.noDecodeWithoutVerify = (0, eslint_devkit_1.createRule)({
|
|
7
|
-
name: 'no-decode-without-verify',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'problem',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-decode-without-verify.md',
|
|
12
|
-
description: 'Disallow trusting decoded JWT payload without signature verification',
|
|
13
|
-
cwe: 'CWE-345',
|
|
14
|
-
cvss: 7.5,
|
|
15
|
-
},
|
|
16
|
-
fixable: undefined,
|
|
17
|
-
hasSuggestions: false,
|
|
18
|
-
messages: {
|
|
19
|
-
decodeWithoutVerify: (0, eslint_devkit_1.formatLLMMessage)({
|
|
20
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
21
|
-
issueName: 'Decoded JWT Without Verification',
|
|
22
|
-
cwe: 'CWE-345',
|
|
23
|
-
description: 'jwt.decode() returns payload without verifying signature - data can be forged',
|
|
24
|
-
severity: 'HIGH',
|
|
25
|
-
fix: 'Use jwt.verify(token, secret) instead of jwt.decode(token)',
|
|
26
|
-
documentationLink: 'https://owasp.org/API-Security/0xa7-security-misconfiguration/',
|
|
27
|
-
}),
|
|
28
|
-
jwtDecodeLibrary: (0, eslint_devkit_1.formatLLMMessage)({
|
|
29
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
30
|
-
issueName: 'jwt-decode Library Usage',
|
|
31
|
-
cwe: 'CWE-345',
|
|
32
|
-
description: 'jwt-decode library only decodes tokens, never verifies signatures',
|
|
33
|
-
severity: 'HIGH',
|
|
34
|
-
fix: 'Use jsonwebtoken.verify() or jose.jwtVerify() for verification',
|
|
35
|
-
documentationLink: 'https://www.npmjs.com/package/jwt-decode',
|
|
36
|
-
}),
|
|
37
|
-
useVerifyInstead: (0, eslint_devkit_1.formatLLMMessage)({
|
|
38
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
39
|
-
issueName: 'Use Verify Instead',
|
|
40
|
-
description: 'Replace decode with verify to ensure authenticity',
|
|
41
|
-
severity: 'LOW',
|
|
42
|
-
fix: 'jwt.verify(token, secret, { algorithms: ["RS256"] })',
|
|
43
|
-
documentationLink: 'https://www.npmjs.com/package/jsonwebtoken',
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
schema: [
|
|
47
|
-
{
|
|
48
|
-
type: 'object',
|
|
49
|
-
properties: {
|
|
50
|
-
allowHeaderInspection: {
|
|
51
|
-
type: 'boolean',
|
|
52
|
-
default: false,
|
|
53
|
-
description: 'Allow decode() for reading header before verification',
|
|
54
|
-
},
|
|
55
|
-
trustedSanitizers: {
|
|
56
|
-
type: 'array',
|
|
57
|
-
items: { type: 'string' },
|
|
58
|
-
default: [],
|
|
59
|
-
},
|
|
60
|
-
trustedAnnotations: {
|
|
61
|
-
type: 'array',
|
|
62
|
-
items: { type: 'string' },
|
|
63
|
-
default: ['@decoded-header-only', '@verified-separately'],
|
|
64
|
-
},
|
|
65
|
-
strictMode: {
|
|
66
|
-
type: 'boolean',
|
|
67
|
-
default: false,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
additionalProperties: false,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
defaultOptions: [
|
|
75
|
-
{
|
|
76
|
-
allowHeaderInspection: false,
|
|
77
|
-
trustedSanitizers: [],
|
|
78
|
-
trustedAnnotations: ['@decoded-header-only', '@verified-separately'],
|
|
79
|
-
strictMode: false,
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
create(context) {
|
|
83
|
-
const options = context.options[0] ?? {};
|
|
84
|
-
const { trustedAnnotations = [] } = options;
|
|
85
|
-
const isJwtDecodeLibrary = (node) => {
|
|
86
|
-
if (node.callee.type === 'Identifier' &&
|
|
87
|
-
(node.callee.name === 'jwtDecode' || node.callee.name === 'jwt_decode')) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
CallExpression(node) {
|
|
94
|
-
if ((0, utils_1.isDecodeOperation)(node)) {
|
|
95
|
-
if ((0, eslint_devkit_1.hasSafeAnnotation)(node, context, trustedAnnotations)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
context.report({
|
|
99
|
-
node,
|
|
100
|
-
messageId: 'decodeWithoutVerify',
|
|
101
|
-
});
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (isJwtDecodeLibrary(node)) {
|
|
105
|
-
if ((0, eslint_devkit_1.hasSafeAnnotation)(node, context, trustedAnnotations)) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
context.report({
|
|
109
|
-
node,
|
|
110
|
-
messageId: 'jwtDecodeLibrary',
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
exports.default = exports.noDecodeWithoutVerify;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDecodeWithoutVerify=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");exports.noDecodeWithoutVerify=(0,eslint_devkit_1.createRule)({name:"no-decode-without-verify",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-decode-without-verify.md",description:"Disallow trusting decoded JWT payload without signature verification",cwe:"CWE-345",cvss:7.5},fixable:void 0,hasSuggestions:false,messages:{decodeWithoutVerify:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Decoded JWT Without Verification",cwe:"CWE-345",description:"jwt.decode() returns payload without verifying signature - data can be forged",severity:"HIGH",fix:"Use jwt.verify(token, secret) instead of jwt.decode(token)",documentationLink:"https://owasp.org/API-Security/0xa7-security-misconfiguration/"}),jwtDecodeLibrary:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"jwt-decode Library Usage",cwe:"CWE-345",description:"jwt-decode library only decodes tokens, never verifies signatures",severity:"HIGH",fix:"Use jsonwebtoken.verify() or jose.jwtVerify() for verification",documentationLink:"https://www.npmjs.com/package/jwt-decode"}),useVerifyInstead:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Verify Instead",description:"Replace decode with verify to ensure authenticity",severity:"LOW",fix:'jwt.verify(token, secret, { algorithms: ["RS256"] })',documentationLink:"https://www.npmjs.com/package/jsonwebtoken"})},schema:[{type:"object",properties:{allowHeaderInspection:{type:"boolean",default:false,description:"Allow decode() for reading header before verification"},trustedSanitizers:{type:"array",items:{type:"string"},default:[]},trustedAnnotations:{type:"array",items:{type:"string"},default:["@decoded-header-only","@verified-separately"]},strictMode:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{allowHeaderInspection:false,trustedSanitizers:[],trustedAnnotations:["@decoded-header-only","@verified-separately"],strictMode:false}],create(context){const options=context.options[0]??{};const{trustedAnnotations=[]}=options;const isJwtDecodeLibrary=node=>{if(node.callee.type==="Identifier"&&(node.callee.name==="jwtDecode"||node.callee.name==="jwt_decode")){return true}return false};return{CallExpression(node){if((0,utils_1.isDecodeOperation)(node)){if((0,eslint_devkit_1.hasSafeAnnotation)(node,context,trustedAnnotations)){return}context.report({node,messageId:"decodeWithoutVerify"});return}if(isJwtDecodeLibrary(node)){if((0,eslint_devkit_1.hasSafeAnnotation)(node,context,trustedAnnotations)){return}context.report({node,messageId:"jwtDecodeLibrary"})}}}}});exports.default=exports.noDecodeWithoutVerify;
|