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.
Files changed (79) hide show
  1. package/AGENTS.md +102 -0
  2. package/CHANGELOG.md +161 -0
  3. package/LICENSE +23 -0
  4. package/README.md +158 -0
  5. package/dist/AGENTS.md +102 -0
  6. package/dist/CHANGELOG.md +161 -0
  7. package/dist/LICENSE +23 -0
  8. package/dist/README.md +158 -0
  9. package/dist/package.json +125 -0
  10. package/dist/src/index.d.ts +101 -0
  11. package/dist/src/index.js +171 -0
  12. package/dist/src/oxlint.d.ts +20 -0
  13. package/dist/src/oxlint.js +21 -0
  14. package/dist/src/rules/no-algorithm-confusion/index.d.ts +24 -0
  15. package/dist/src/rules/no-algorithm-confusion/index.js +165 -0
  16. package/dist/src/rules/no-algorithm-none/index.d.ts +24 -0
  17. package/dist/src/rules/no-algorithm-none/index.js +222 -0
  18. package/dist/src/rules/no-decode-without-verify/index.d.ts +23 -0
  19. package/dist/src/rules/no-decode-without-verify/index.js +131 -0
  20. package/dist/src/rules/no-hardcoded-secret/index.d.ts +23 -0
  21. package/dist/src/rules/no-hardcoded-secret/index.js +189 -0
  22. package/dist/src/rules/no-sensitive-payload/index.d.ts +20 -0
  23. package/dist/src/rules/no-sensitive-payload/index.js +103 -0
  24. package/dist/src/rules/no-timestamp-manipulation/index.d.ts +23 -0
  25. package/dist/src/rules/no-timestamp-manipulation/index.js +97 -0
  26. package/dist/src/rules/no-weak-secret/index.d.ts +23 -0
  27. package/dist/src/rules/no-weak-secret/index.js +165 -0
  28. package/dist/src/rules/require-algorithm-whitelist/index.d.ts +24 -0
  29. package/dist/src/rules/require-algorithm-whitelist/index.js +113 -0
  30. package/dist/src/rules/require-audience-validation/index.d.ts +20 -0
  31. package/dist/src/rules/require-audience-validation/index.js +100 -0
  32. package/dist/src/rules/require-expiration/index.d.ts +23 -0
  33. package/dist/src/rules/require-expiration/index.js +136 -0
  34. package/dist/src/rules/require-issued-at/index.d.ts +23 -0
  35. package/dist/src/rules/require-issued-at/index.js +113 -0
  36. package/dist/src/rules/require-issuer-validation/index.d.ts +20 -0
  37. package/dist/src/rules/require-issuer-validation/index.js +100 -0
  38. package/dist/src/rules/require-max-age/index.d.ts +24 -0
  39. package/dist/src/rules/require-max-age/index.js +93 -0
  40. package/dist/src/types/index.d.ts +82 -0
  41. package/dist/src/types/index.js +7 -0
  42. package/dist/src/utils/index.d.ts +98 -0
  43. package/dist/src/utils/index.js +238 -0
  44. package/package.json +125 -0
  45. package/src/__compatibility__/jwt-interface.spec.ts +192 -0
  46. package/src/index.test.ts +47 -0
  47. package/src/index.ts +209 -0
  48. package/src/oxlint.test.ts +61 -0
  49. package/src/oxlint.ts +23 -0
  50. package/src/rules/no-algorithm-confusion/index.ts +208 -0
  51. package/src/rules/no-algorithm-confusion/no-algorithm-confusion.test.ts +106 -0
  52. package/src/rules/no-algorithm-none/index.ts +270 -0
  53. package/src/rules/no-algorithm-none/no-algorithm-none.test.ts +146 -0
  54. package/src/rules/no-decode-without-verify/index.ts +162 -0
  55. package/src/rules/no-decode-without-verify/no-decode-without-verify.test.ts +76 -0
  56. package/src/rules/no-hardcoded-secret/index.ts +230 -0
  57. package/src/rules/no-hardcoded-secret/no-hardcoded-secret.test.ts +97 -0
  58. package/src/rules/no-sensitive-payload/index.ts +123 -0
  59. package/src/rules/no-sensitive-payload/no-sensitive-payload.test.ts +157 -0
  60. package/src/rules/no-timestamp-manipulation/index.ts +118 -0
  61. package/src/rules/no-timestamp-manipulation/no-timestamp-manipulation.test.ts +54 -0
  62. package/src/rules/no-weak-secret/index.ts +204 -0
  63. package/src/rules/no-weak-secret/no-weak-secret.test.ts +114 -0
  64. package/src/rules/require-algorithm-whitelist/index.ts +145 -0
  65. package/src/rules/require-algorithm-whitelist/require-algorithm-whitelist.test.ts +72 -0
  66. package/src/rules/require-audience-validation/index.ts +120 -0
  67. package/src/rules/require-audience-validation/require-audience-validation.test.ts +68 -0
  68. package/src/rules/require-expiration/index.ts +170 -0
  69. package/src/rules/require-expiration/require-expiration.test.ts +135 -0
  70. package/src/rules/require-issued-at/index.ts +143 -0
  71. package/src/rules/require-issued-at/require-issued-at.test.ts +64 -0
  72. package/src/rules/require-issuer-validation/index.ts +120 -0
  73. package/src/rules/require-issuer-validation/require-issuer-validation.test.ts +68 -0
  74. package/src/rules/require-max-age/index.ts +117 -0
  75. package/src/rules/require-max-age/require-max-age.test.ts +69 -0
  76. package/src/tests/coverage-dual-layer.test.ts +323 -0
  77. package/src/types/index.ts +107 -0
  78. package/src/utils/index.ts +285 -0
  79. package/src/utils/utils.test.ts +324 -0
@@ -0,0 +1,171 @@
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.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;
9
+ // Import rules - Core Security
10
+ const no_algorithm_none_1 = require("./rules/no-algorithm-none");
11
+ Object.defineProperty(exports, "noAlgorithmNone", { enumerable: true, get: function () { return no_algorithm_none_1.noAlgorithmNone; } });
12
+ const no_algorithm_confusion_1 = require("./rules/no-algorithm-confusion");
13
+ Object.defineProperty(exports, "noAlgorithmConfusion", { enumerable: true, get: function () { return no_algorithm_confusion_1.noAlgorithmConfusion; } });
14
+ const require_algorithm_whitelist_1 = require("./rules/require-algorithm-whitelist");
15
+ Object.defineProperty(exports, "requireAlgorithmWhitelist", { enumerable: true, get: function () { return require_algorithm_whitelist_1.requireAlgorithmWhitelist; } });
16
+ const no_decode_without_verify_1 = require("./rules/no-decode-without-verify");
17
+ Object.defineProperty(exports, "noDecodeWithoutVerify", { enumerable: true, get: function () { return no_decode_without_verify_1.noDecodeWithoutVerify; } });
18
+ const no_weak_secret_1 = require("./rules/no-weak-secret");
19
+ Object.defineProperty(exports, "noWeakSecret", { enumerable: true, get: function () { return no_weak_secret_1.noWeakSecret; } });
20
+ const require_expiration_1 = require("./rules/require-expiration");
21
+ Object.defineProperty(exports, "requireExpiration", { enumerable: true, get: function () { return require_expiration_1.requireExpiration; } });
22
+ const no_hardcoded_secret_1 = require("./rules/no-hardcoded-secret");
23
+ Object.defineProperty(exports, "noHardcodedSecret", { enumerable: true, get: function () { return no_hardcoded_secret_1.noHardcodedSecret; } });
24
+ // Import rules - 2025 Vulnerability Research
25
+ const require_issued_at_1 = require("./rules/require-issued-at");
26
+ Object.defineProperty(exports, "requireIssuedAt", { enumerable: true, get: function () { return require_issued_at_1.requireIssuedAt; } });
27
+ const require_issuer_validation_1 = require("./rules/require-issuer-validation");
28
+ Object.defineProperty(exports, "requireIssuerValidation", { enumerable: true, get: function () { return require_issuer_validation_1.requireIssuerValidation; } });
29
+ const require_audience_validation_1 = require("./rules/require-audience-validation");
30
+ Object.defineProperty(exports, "requireAudienceValidation", { enumerable: true, get: function () { return require_audience_validation_1.requireAudienceValidation; } });
31
+ const no_timestamp_manipulation_1 = require("./rules/no-timestamp-manipulation");
32
+ Object.defineProperty(exports, "noTimestampManipulation", { enumerable: true, get: function () { return no_timestamp_manipulation_1.noTimestampManipulation; } });
33
+ const require_max_age_1 = require("./rules/require-max-age");
34
+ Object.defineProperty(exports, "requireMaxAge", { enumerable: true, get: function () { return require_max_age_1.requireMaxAge; } });
35
+ const no_sensitive_payload_1 = require("./rules/no-sensitive-payload");
36
+ Object.defineProperty(exports, "noSensitivePayload", { enumerable: true, get: function () { return no_sensitive_payload_1.noSensitivePayload; } });
37
+ /**
38
+ * Collection of all JWT security ESLint rules (13 rules)
39
+ */
40
+ exports.rules = {
41
+ // Core Security Rules
42
+ 'no-algorithm-none': no_algorithm_none_1.noAlgorithmNone,
43
+ 'no-algorithm-confusion': no_algorithm_confusion_1.noAlgorithmConfusion,
44
+ 'require-algorithm-whitelist': require_algorithm_whitelist_1.requireAlgorithmWhitelist,
45
+ 'no-decode-without-verify': no_decode_without_verify_1.noDecodeWithoutVerify,
46
+ 'no-weak-secret': no_weak_secret_1.noWeakSecret,
47
+ 'require-expiration': require_expiration_1.requireExpiration,
48
+ 'no-hardcoded-secret': no_hardcoded_secret_1.noHardcodedSecret,
49
+ // 2025 Vulnerability Research - "Back to the Future" & Replay Prevention
50
+ 'require-issued-at': require_issued_at_1.requireIssuedAt,
51
+ 'require-issuer-validation': require_issuer_validation_1.requireIssuerValidation,
52
+ 'require-audience-validation': require_audience_validation_1.requireAudienceValidation,
53
+ 'no-timestamp-manipulation': no_timestamp_manipulation_1.noTimestampManipulation,
54
+ 'require-max-age': require_max_age_1.requireMaxAge,
55
+ 'no-sensitive-payload': no_sensitive_payload_1.noSensitivePayload,
56
+ };
57
+ /**
58
+ * ESLint Plugin object
59
+ */
60
+ exports.plugin = {
61
+ meta: {
62
+ name: 'eslint-plugin-jwt-security',
63
+ version: '2.2.9',
64
+ },
65
+ rules: exports.rules,
66
+ };
67
+ /**
68
+ * Recommended configuration - baseline security
69
+ * Critical rules as errors, high as warnings
70
+ */
71
+ const recommendedRules = {
72
+ // CRITICAL - Algorithm attacks
73
+ 'jwt/no-algorithm-none': 'error',
74
+ 'jwt/no-algorithm-confusion': 'error',
75
+ // HIGH - Verification and secrets
76
+ 'jwt/require-algorithm-whitelist': 'error',
77
+ 'jwt/no-decode-without-verify': 'error',
78
+ 'jwt/no-weak-secret': 'error',
79
+ 'jwt/no-hardcoded-secret': 'error',
80
+ 'jwt/no-timestamp-manipulation': 'error', // LightSEC 2025
81
+ // MEDIUM - Best practices
82
+ 'jwt/require-expiration': 'error',
83
+ 'jwt/no-sensitive-payload': 'warn',
84
+ };
85
+ /**
86
+ * Strict configuration - maximum security (2025 research)
87
+ * All rules as errors - includes replay attack prevention
88
+ */
89
+ const strictRules = {
90
+ // All core rules as errors
91
+ 'jwt/no-algorithm-none': 'error',
92
+ 'jwt/no-algorithm-confusion': 'error',
93
+ 'jwt/require-algorithm-whitelist': 'error',
94
+ 'jwt/no-decode-without-verify': 'error',
95
+ 'jwt/no-weak-secret': 'error',
96
+ 'jwt/no-hardcoded-secret': 'error',
97
+ 'jwt/require-expiration': 'error',
98
+ // 2025 Research - Full replay attack prevention
99
+ 'jwt/require-issued-at': 'error',
100
+ 'jwt/require-issuer-validation': 'error',
101
+ 'jwt/require-audience-validation': 'error',
102
+ 'jwt/no-timestamp-manipulation': 'error',
103
+ 'jwt/require-max-age': 'error',
104
+ 'jwt/no-sensitive-payload': 'error',
105
+ };
106
+ /**
107
+ * Legacy configuration - migration mode
108
+ * Only critical rules enabled
109
+ */
110
+ const legacyRules = {
111
+ // Only most critical rules
112
+ 'jwt/no-algorithm-none': 'error',
113
+ 'jwt/no-algorithm-confusion': 'error',
114
+ 'jwt/no-hardcoded-secret': 'warn',
115
+ };
116
+ /**
117
+ * Configuration presets for flat config
118
+ */
119
+ exports.configs = {
120
+ /**
121
+ * Flagship preset — the rule from this plugin in the ecosystem-wide
122
+ * flagship list (`.agent/flagship-rules.md`). Use this when you want
123
+ * the highest-signal JWT subset shippable in CI gates.
124
+ */
125
+ flagship: {
126
+ plugins: {
127
+ jwt: exports.plugin,
128
+ },
129
+ rules: {
130
+ 'jwt/no-algorithm-none': 'error',
131
+ },
132
+ },
133
+ /**
134
+ * Recommended preset - balanced security
135
+ */
136
+ recommended: {
137
+ plugins: {
138
+ jwt: exports.plugin,
139
+ },
140
+ rules: recommendedRules,
141
+ },
142
+ /**
143
+ * Strict preset - maximum security (includes 2025 research)
144
+ */
145
+ strict: {
146
+ plugins: {
147
+ jwt: exports.plugin,
148
+ },
149
+ rules: strictRules,
150
+ },
151
+ /**
152
+ * Legacy preset - migration mode
153
+ */
154
+ legacy: {
155
+ plugins: {
156
+ jwt: exports.plugin,
157
+ },
158
+ rules: legacyRules,
159
+ },
160
+ /**
161
+ * All rules preset
162
+ */
163
+ all: {
164
+ plugins: {
165
+ jwt: exports.plugin,
166
+ },
167
+ rules: strictRules,
168
+ },
169
+ };
170
+ // Default export for flat config usage
171
+ exports.default = exports.plugin;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * oxlint sub-export.
8
+ *
9
+ * Consumers wire oxlint to this entry via:
10
+ * { "jsPlugins": ["eslint-plugin-jwt-security/oxlint"] }
11
+ *
12
+ * oxlint's JS plugin loader does `require('eslint-plugin-jwt-security/oxlint')` and reads
13
+ * `.rules` off the result. The compiled output of `export = plugin` is
14
+ * `module.exports = plugin`, which gives oxlint the plugin object directly
15
+ * (`{ meta, rules }`) — no wrapper, no `.default` indirection.
16
+ *
17
+ * Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
18
+ */
19
+ import { plugin } from './index';
20
+ export = plugin;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
7
+ /**
8
+ * oxlint sub-export.
9
+ *
10
+ * Consumers wire oxlint to this entry via:
11
+ * { "jsPlugins": ["eslint-plugin-jwt-security/oxlint"] }
12
+ *
13
+ * oxlint's JS plugin loader does `require('eslint-plugin-jwt-security/oxlint')` and reads
14
+ * `.rules` off the result. The compiled output of `export = plugin` is
15
+ * `module.exports = plugin`, which gives oxlint the plugin object directly
16
+ * (`{ meta, rules }`) — no wrapper, no `.default` indirection.
17
+ *
18
+ * Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
19
+ */
20
+ const index_1 = require("./index");
21
+ module.exports = index_1.plugin;
@@ -0,0 +1,24 @@
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-algorithm-confusion
8
+ *
9
+ * Detects algorithm confusion attacks where symmetric algorithms (HS256/384/512)
10
+ * are used with asymmetric keys (public keys). This allows attackers to sign
11
+ * tokens using the public key as an HMAC secret.
12
+ *
13
+ * CWE-347: Improper Verification of Cryptographic Signature
14
+ *
15
+ * @see https://portswigger.net/web-security/jwt/algorithm-confusion
16
+ */
17
+ import type { TSESLint } from '@interlace/eslint-devkit';
18
+ import type { NoAlgorithmConfusionOptions } from '../../types';
19
+ type MessageIds = 'algorithmConfusion' | 'symmetricWithPublicKey' | 'useAsymmetricAlgorithm';
20
+ type RuleOptions = [NoAlgorithmConfusionOptions?];
21
+ export declare const noAlgorithmConfusion: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
22
+ name: string;
23
+ };
24
+ export default noAlgorithmConfusion;
@@ -0,0 +1,165 @@
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.noAlgorithmConfusion = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const utils_1 = require("../../utils");
11
+ // Patterns that indicate a public key
12
+ const PUBLIC_KEY_PATTERNS = [
13
+ /public/i,
14
+ /\.pub$/,
15
+ /\.pem$/,
16
+ /-----BEGIN PUBLIC KEY-----/,
17
+ /-----BEGIN RSA PUBLIC KEY-----/,
18
+ /-----BEGIN EC PUBLIC KEY-----/,
19
+ /getPublicKey/i,
20
+ /publicKey/i,
21
+ /jwks/i,
22
+ ];
23
+ exports.noAlgorithmConfusion = (0, eslint_devkit_1.createRule)({
24
+ name: 'no-algorithm-confusion',
25
+ meta: {
26
+ type: 'problem',
27
+ docs: {
28
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-algorithm-confusion.md',
29
+ description: 'Prevent algorithm confusion attacks using symmetric algorithms with asymmetric keys',
30
+ cwe: 'CWE-347',
31
+ cvss: 9.5,
32
+ },
33
+ fixable: undefined,
34
+ hasSuggestions: false,
35
+ messages: {
36
+ algorithmConfusion: (0, eslint_devkit_1.formatLLMMessage)({
37
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
38
+ issueName: 'JWT Algorithm Confusion Attack',
39
+ cwe: 'CWE-347',
40
+ description: 'Symmetric algorithm (HS*) used with public key allows token forgery',
41
+ severity: 'CRITICAL',
42
+ fix: 'Use asymmetric algorithms (RS256, ES256) with public keys',
43
+ documentationLink: 'https://portswigger.net/web-security/jwt/algorithm-confusion',
44
+ }),
45
+ symmetricWithPublicKey: (0, eslint_devkit_1.formatLLMMessage)({
46
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
47
+ issueName: 'Symmetric Algorithm with Public Key',
48
+ cwe: 'CWE-347',
49
+ description: 'HS256/384/512 should only be used with shared secrets, not public keys',
50
+ severity: 'CRITICAL',
51
+ fix: 'Switch to RS256 or ES256 for asymmetric key verification',
52
+ documentationLink: 'https://portswigger.net/web-security/jwt/algorithm-confusion',
53
+ }),
54
+ useAsymmetricAlgorithm: (0, eslint_devkit_1.formatLLMMessage)({
55
+ icon: eslint_devkit_1.MessageIcons.INFO,
56
+ issueName: 'Use Asymmetric Algorithm',
57
+ description: 'Replace HS* with RS* or ES* algorithm',
58
+ severity: 'LOW',
59
+ fix: 'Use RS256 or ES256 with public key verification',
60
+ documentationLink: 'https://tools.ietf.org/html/rfc8725',
61
+ }),
62
+ },
63
+ schema: [
64
+ {
65
+ type: 'object',
66
+ properties: {
67
+ symmetricAlgorithms: {
68
+ type: 'array',
69
+ items: { type: 'string' },
70
+ default: ['HS256', 'HS384', 'HS512'],
71
+ description: 'Algorithms to flag when used with public keys',
72
+ },
73
+ trustedSanitizers: {
74
+ type: 'array',
75
+ items: { type: 'string' },
76
+ default: [],
77
+ },
78
+ trustedAnnotations: {
79
+ type: 'array',
80
+ items: { type: 'string' },
81
+ default: [],
82
+ },
83
+ strictMode: {
84
+ type: 'boolean',
85
+ default: false,
86
+ },
87
+ },
88
+ additionalProperties: false,
89
+ },
90
+ ],
91
+ },
92
+ defaultOptions: [
93
+ {
94
+ symmetricAlgorithms: ['HS256', 'HS384', 'HS512'],
95
+ trustedSanitizers: [],
96
+ trustedAnnotations: [],
97
+ strictMode: false,
98
+ },
99
+ ],
100
+ create(context) {
101
+ const options = context.options[0] ?? {};
102
+ const symmetricAlgSet = new Set(options.symmetricAlgorithms ?? ['HS256', 'HS384', 'HS512']);
103
+ const sourceCode = context.sourceCode;
104
+ /**
105
+ * Check if a node looks like a public key reference
106
+ */
107
+ const looksLikePublicKey = (node) => {
108
+ const text = sourceCode.getText(node);
109
+ return PUBLIC_KEY_PATTERNS.some((pattern) => pattern.test(text));
110
+ };
111
+ /**
112
+ * Check if algorithms include symmetric algorithms
113
+ */
114
+ const hasSymmetricAlgorithm = (algorithms) => {
115
+ for (const alg of algorithms) {
116
+ if (symmetricAlgSet.has(alg)) {
117
+ return alg;
118
+ }
119
+ }
120
+ return null;
121
+ };
122
+ return {
123
+ CallExpression(node) {
124
+ // Only check verify operations
125
+ if (!(0, utils_1.isVerifyOperation)(node)) {
126
+ return;
127
+ }
128
+ // Need at least 2 arguments: token, key
129
+ if (node.arguments.length < 2) {
130
+ return;
131
+ }
132
+ const keyArg = node.arguments[1];
133
+ const optionsArg = (0, utils_1.getOptionsArgument)(node, 2);
134
+ // Check if key looks like a public key
135
+ if (!looksLikePublicKey(keyArg)) {
136
+ return;
137
+ }
138
+ // If there are options, check the algorithms
139
+ if (optionsArg) {
140
+ const algorithms = (0, utils_1.extractAlgorithms)(optionsArg);
141
+ const symmetricAlg = hasSymmetricAlgorithm(algorithms);
142
+ if (symmetricAlg) {
143
+ // Find the algorithm node for precise error location
144
+ for (const prop of optionsArg.properties) {
145
+ if (prop.type === 'Property' &&
146
+ prop.key.type === 'Identifier' &&
147
+ ['algorithms', 'algorithm', 'alg'].includes(prop.key.name)) {
148
+ context.report({
149
+ node: prop.value,
150
+ messageId: 'algorithmConfusion',
151
+ data: { algorithm: symmetricAlg },
152
+ });
153
+ return;
154
+ }
155
+ }
156
+ }
157
+ }
158
+ // If no options specified but key looks like public key,
159
+ // and we're in verify, flag as potential issue
160
+ // (verification without explicit algorithm with public key is risky)
161
+ },
162
+ };
163
+ },
164
+ });
165
+ exports.default = exports.noAlgorithmConfusion;
@@ -0,0 +1,24 @@
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-algorithm-none
8
+ *
9
+ * Detects attempts to use the 'none' algorithm which bypasses JWT signature verification.
10
+ * This is a critical vulnerability (CVE-2022-23540) that allows attackers to forge JWT tokens.
11
+ *
12
+ * CWE-347: Improper Verification of Cryptographic Signature
13
+ *
14
+ * @see https://nvd.nist.gov/vuln/detail/CVE-2022-23540
15
+ * @see https://tools.ietf.org/html/rfc8725
16
+ */
17
+ import type { TSESLint } from '@interlace/eslint-devkit';
18
+ import type { NoAlgorithmNoneOptions } from '../../types';
19
+ type MessageIds = 'algorithmNone' | 'algorithmNoneInArray' | 'emptyAlgorithms' | 'useSecureAlgorithm' | 'decodeWithoutVerify';
20
+ type RuleOptions = [NoAlgorithmNoneOptions?];
21
+ export declare const noAlgorithmNone: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
22
+ name: string;
23
+ };
24
+ export default noAlgorithmNone;
@@ -0,0 +1,222 @@
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;
@@ -0,0 +1,23 @@
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;