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.
Files changed (97) hide show
  1. package/README.md +5 -5
  2. package/package.json +16 -24
  3. package/src/index.d.ts +17 -0
  4. package/src/index.js +1 -0
  5. package/src/oxlint.d.ts +17 -0
  6. package/src/oxlint.js +1 -0
  7. package/src/rules/no-algorithm-confusion/index.js +1 -0
  8. package/src/rules/no-algorithm-none/index.js +1 -0
  9. package/src/rules/no-decode-without-verify/index.js +1 -0
  10. package/src/rules/no-hardcoded-secret/index.js +1 -0
  11. package/src/rules/no-sensitive-payload/index.js +1 -0
  12. package/src/rules/no-timestamp-manipulation/index.js +1 -0
  13. package/src/rules/no-weak-secret/index.js +1 -0
  14. package/src/rules/require-algorithm-whitelist/index.js +1 -0
  15. package/src/rules/require-audience-validation/index.js +1 -0
  16. package/src/rules/require-expiration/index.js +1 -0
  17. package/src/rules/require-issued-at/index.js +1 -0
  18. package/src/rules/require-issuer-validation/index.js +1 -0
  19. package/src/rules/require-max-age/index.js +1 -0
  20. package/src/types/index.js +1 -0
  21. package/src/utils/index.js +1 -0
  22. package/AGENTS.md +0 -102
  23. package/CHANGELOG.md +0 -161
  24. package/dist/AGENTS.md +0 -102
  25. package/dist/CHANGELOG.md +0 -161
  26. package/dist/LICENSE +0 -23
  27. package/dist/README.md +0 -158
  28. package/dist/package.json +0 -125
  29. package/dist/src/index.d.ts +0 -101
  30. package/dist/src/index.js +0 -171
  31. package/dist/src/oxlint.d.ts +0 -20
  32. package/dist/src/oxlint.js +0 -21
  33. package/dist/src/rules/no-algorithm-confusion/index.d.ts +0 -24
  34. package/dist/src/rules/no-algorithm-confusion/index.js +0 -165
  35. package/dist/src/rules/no-algorithm-none/index.d.ts +0 -24
  36. package/dist/src/rules/no-algorithm-none/index.js +0 -222
  37. package/dist/src/rules/no-decode-without-verify/index.d.ts +0 -23
  38. package/dist/src/rules/no-decode-without-verify/index.js +0 -131
  39. package/dist/src/rules/no-hardcoded-secret/index.d.ts +0 -23
  40. package/dist/src/rules/no-hardcoded-secret/index.js +0 -189
  41. package/dist/src/rules/no-sensitive-payload/index.d.ts +0 -20
  42. package/dist/src/rules/no-sensitive-payload/index.js +0 -103
  43. package/dist/src/rules/no-timestamp-manipulation/index.d.ts +0 -23
  44. package/dist/src/rules/no-timestamp-manipulation/index.js +0 -97
  45. package/dist/src/rules/no-weak-secret/index.d.ts +0 -23
  46. package/dist/src/rules/no-weak-secret/index.js +0 -165
  47. package/dist/src/rules/require-algorithm-whitelist/index.d.ts +0 -24
  48. package/dist/src/rules/require-algorithm-whitelist/index.js +0 -113
  49. package/dist/src/rules/require-audience-validation/index.d.ts +0 -20
  50. package/dist/src/rules/require-audience-validation/index.js +0 -100
  51. package/dist/src/rules/require-expiration/index.d.ts +0 -23
  52. package/dist/src/rules/require-expiration/index.js +0 -136
  53. package/dist/src/rules/require-issued-at/index.d.ts +0 -23
  54. package/dist/src/rules/require-issued-at/index.js +0 -113
  55. package/dist/src/rules/require-issuer-validation/index.d.ts +0 -20
  56. package/dist/src/rules/require-issuer-validation/index.js +0 -100
  57. package/dist/src/rules/require-max-age/index.d.ts +0 -24
  58. package/dist/src/rules/require-max-age/index.js +0 -93
  59. package/dist/src/types/index.js +0 -7
  60. package/dist/src/utils/index.d.ts +0 -98
  61. package/dist/src/utils/index.js +0 -238
  62. package/src/__compatibility__/jwt-interface.spec.ts +0 -192
  63. package/src/index.test.ts +0 -47
  64. package/src/index.ts +0 -209
  65. package/src/oxlint.test.ts +0 -61
  66. package/src/oxlint.ts +0 -23
  67. package/src/rules/no-algorithm-confusion/index.ts +0 -208
  68. package/src/rules/no-algorithm-confusion/no-algorithm-confusion.test.ts +0 -106
  69. package/src/rules/no-algorithm-none/index.ts +0 -270
  70. package/src/rules/no-algorithm-none/no-algorithm-none.test.ts +0 -146
  71. package/src/rules/no-decode-without-verify/index.ts +0 -162
  72. package/src/rules/no-decode-without-verify/no-decode-without-verify.test.ts +0 -76
  73. package/src/rules/no-hardcoded-secret/index.ts +0 -230
  74. package/src/rules/no-hardcoded-secret/no-hardcoded-secret.test.ts +0 -97
  75. package/src/rules/no-sensitive-payload/index.ts +0 -123
  76. package/src/rules/no-sensitive-payload/no-sensitive-payload.test.ts +0 -157
  77. package/src/rules/no-timestamp-manipulation/index.ts +0 -118
  78. package/src/rules/no-timestamp-manipulation/no-timestamp-manipulation.test.ts +0 -54
  79. package/src/rules/no-weak-secret/index.ts +0 -204
  80. package/src/rules/no-weak-secret/no-weak-secret.test.ts +0 -114
  81. package/src/rules/require-algorithm-whitelist/index.ts +0 -145
  82. package/src/rules/require-algorithm-whitelist/require-algorithm-whitelist.test.ts +0 -72
  83. package/src/rules/require-audience-validation/index.ts +0 -120
  84. package/src/rules/require-audience-validation/require-audience-validation.test.ts +0 -68
  85. package/src/rules/require-expiration/index.ts +0 -170
  86. package/src/rules/require-expiration/require-expiration.test.ts +0 -135
  87. package/src/rules/require-issued-at/index.ts +0 -143
  88. package/src/rules/require-issued-at/require-issued-at.test.ts +0 -64
  89. package/src/rules/require-issuer-validation/index.ts +0 -120
  90. package/src/rules/require-issuer-validation/require-issuer-validation.test.ts +0 -68
  91. package/src/rules/require-max-age/index.ts +0 -117
  92. package/src/rules/require-max-age/require-max-age.test.ts +0 -69
  93. package/src/tests/coverage-dual-layer.test.ts +0 -323
  94. package/src/types/index.ts +0 -107
  95. package/src/utils/index.ts +0 -285
  96. package/src/utils/utils.test.ts +0 -324
  97. /package/{dist/src → src}/types/index.d.ts +0 -0
@@ -1,103 +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.noSensitivePayload = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const utils_1 = require("../../utils");
11
- exports.noSensitivePayload = (0, eslint_devkit_1.createRule)({
12
- name: 'no-sensitive-payload',
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-sensitive-payload.md',
17
- description: 'Prevent storing sensitive data in JWT payload which is only base64-encoded',
18
- cwe: 'CWE-359',
19
- cvss: 5,
20
- },
21
- fixable: undefined,
22
- hasSuggestions: false,
23
- messages: {
24
- sensitivePayloadField: (0, eslint_devkit_1.formatLLMMessage)({
25
- icon: eslint_devkit_1.MessageIcons.SECURITY,
26
- issueName: 'Sensitive Data in JWT Payload',
27
- cwe: 'CWE-359',
28
- description: 'JWT payloads are not encrypted - sensitive data like "{{fieldName}}" can be read by anyone',
29
- severity: 'MEDIUM',
30
- fix: 'Store sensitive data server-side, reference by ID in token',
31
- documentationLink: 'https://tools.ietf.org/html/rfc8725',
32
- }),
33
- },
34
- schema: [
35
- {
36
- type: 'object',
37
- properties: {
38
- additionalSensitiveFields: {
39
- type: 'array',
40
- items: { type: 'string' },
41
- default: [],
42
- description: 'Additional field names to flag as sensitive',
43
- },
44
- trustedSanitizers: {
45
- type: 'array',
46
- items: { type: 'string' },
47
- default: [],
48
- },
49
- trustedAnnotations: {
50
- type: 'array',
51
- items: { type: 'string' },
52
- default: [],
53
- },
54
- strictMode: {
55
- type: 'boolean',
56
- default: false,
57
- },
58
- },
59
- additionalProperties: false,
60
- },
61
- ],
62
- },
63
- defaultOptions: [
64
- {
65
- additionalSensitiveFields: [],
66
- trustedSanitizers: [],
67
- trustedAnnotations: [],
68
- strictMode: false,
69
- },
70
- ],
71
- create(context) {
72
- const options = context.options[0] ?? {};
73
- const additionalFields = options.additionalSensitiveFields ?? [];
74
- const allSensitiveFields = new Set([...utils_1.SENSITIVE_PAYLOAD_FIELDS, ...additionalFields]);
75
- return {
76
- CallExpression(node) {
77
- if (!(0, utils_1.isSignOperation)(node)) {
78
- return;
79
- }
80
- if (node.arguments.length < 1) {
81
- return;
82
- }
83
- const payloadArg = node.arguments[0];
84
- // Check object literal payload
85
- if (payloadArg.type === 'ObjectExpression') {
86
- for (const prop of payloadArg.properties) {
87
- if (prop.type === 'Property' && prop.key.type === 'Identifier') {
88
- const fieldName = prop.key.name.toLowerCase();
89
- if (allSensitiveFields.has(fieldName)) {
90
- context.report({
91
- node: prop,
92
- messageId: 'sensitivePayloadField',
93
- data: { fieldName: prop.key.name },
94
- });
95
- }
96
- }
97
- }
98
- }
99
- },
100
- };
101
- },
102
- });
103
- exports.default = exports.noSensitivePayload;
@@ -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-timestamp-manipulation
8
- *
9
- * Detects patterns that disable automatic timestamp (iat) generation.
10
- * This enables the "Back to the Future" replay attack (LightSEC 2025).
11
- *
12
- * CWE-294: Authentication Bypass by Capture-replay
13
- *
14
- * @see https://securitypattern.com/post/jwt-back-to-the-future
15
- */
16
- import type { TSESLint } from '@interlace/eslint-devkit';
17
- import type { JwtRuleOptions } from '../../types';
18
- type MessageIds = 'timestampDisabled' | 'noTimestampTrue';
19
- type RuleOptions = [JwtRuleOptions?];
20
- export declare const noTimestampManipulation: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
21
- name: string;
22
- };
23
- export default noTimestampManipulation;
@@ -1,97 +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.noTimestampManipulation = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const utils_1 = require("../../utils");
11
- exports.noTimestampManipulation = (0, eslint_devkit_1.createRule)({
12
- name: 'no-timestamp-manipulation',
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-timestamp-manipulation.md',
17
- description: 'Prevent disabling automatic timestamp generation which enables replay attacks',
18
- cwe: 'CWE-294',
19
- cvss: 7.5,
20
- },
21
- fixable: undefined,
22
- hasSuggestions: false,
23
- messages: {
24
- timestampDisabled: (0, eslint_devkit_1.formatLLMMessage)({
25
- icon: eslint_devkit_1.MessageIcons.SECURITY,
26
- issueName: 'Timestamp Generation Disabled',
27
- cwe: 'CWE-294',
28
- description: 'noTimestamp:true disables iat claim, enabling replay attacks',
29
- severity: 'HIGH',
30
- fix: 'Remove noTimestamp option or set to false',
31
- documentationLink: 'https://securitypattern.com/post/jwt-back-to-the-future',
32
- }),
33
- noTimestampTrue: (0, eslint_devkit_1.formatLLMMessage)({
34
- icon: eslint_devkit_1.MessageIcons.SECURITY,
35
- issueName: 'Back to the Future Attack Vector',
36
- cwe: 'CWE-294',
37
- description: 'Disabling timestamps allows attackers to forge tokens valid in the future',
38
- severity: 'HIGH',
39
- fix: 'Always include iat claim for freshness validation',
40
- documentationLink: 'https://securitypattern.com/post/jwt-back-to-the-future',
41
- }),
42
- },
43
- schema: [
44
- {
45
- type: 'object',
46
- properties: {
47
- trustedSanitizers: {
48
- type: 'array',
49
- items: { type: 'string' },
50
- default: [],
51
- },
52
- trustedAnnotations: {
53
- type: 'array',
54
- items: { type: 'string' },
55
- default: [],
56
- },
57
- strictMode: {
58
- type: 'boolean',
59
- default: false,
60
- },
61
- },
62
- additionalProperties: false,
63
- },
64
- ],
65
- },
66
- defaultOptions: [
67
- {
68
- trustedSanitizers: [],
69
- trustedAnnotations: [],
70
- strictMode: false,
71
- },
72
- ],
73
- create(context) {
74
- return {
75
- CallExpression(node) {
76
- if (!(0, utils_1.isSignOperation)(node)) {
77
- return;
78
- }
79
- const optionsArg = (0, utils_1.getOptionsArgument)(node, 2);
80
- if (!optionsArg) {
81
- return;
82
- }
83
- // Check for noTimestamp: true
84
- if ((0, utils_1.hasOption)(optionsArg, 'noTimestamp')) {
85
- const value = (0, utils_1.getOptionValue)(optionsArg, 'noTimestamp');
86
- if (value?.type === 'Literal' && value.value === true) {
87
- context.report({
88
- node: value,
89
- messageId: 'noTimestampTrue',
90
- });
91
- }
92
- }
93
- },
94
- };
95
- },
96
- });
97
- exports.default = exports.noTimestampManipulation;
@@ -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-weak-secret
8
- *
9
- * Detects weak secrets used for HMAC-based JWT signing.
10
- * Weak secrets can be brute-forced, allowing attackers to forge tokens.
11
- *
12
- * CWE-326: Inadequate Encryption Strength
13
- *
14
- * @see https://tools.ietf.org/html/rfc8725
15
- */
16
- import type { TSESLint } from '@interlace/eslint-devkit';
17
- import type { NoWeakSecretOptions } from '../../types';
18
- type MessageIds = 'weakSecret' | 'shortSecret' | 'useStrongSecret';
19
- type RuleOptions = [NoWeakSecretOptions?];
20
- export declare const noWeakSecret: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
21
- name: string;
22
- };
23
- export default noWeakSecret;
@@ -1,165 +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.noWeakSecret = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const utils_1 = require("../../utils");
11
- // Common weak secret patterns
12
- const WEAK_SECRET_PATTERNS = [
13
- /^secret$/i,
14
- /^password$/i,
15
- /^123456/,
16
- /^test/i,
17
- /^demo/i,
18
- /^example/i,
19
- /^changeme/i,
20
- /^default/i,
21
- ];
22
- exports.noWeakSecret = (0, eslint_devkit_1.createRule)({
23
- name: 'no-weak-secret',
24
- meta: {
25
- type: 'problem',
26
- docs: {
27
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/no-weak-secret.md',
28
- description: 'Require strong secrets (256+ bits) for HMAC-based JWT signing',
29
- cwe: 'CWE-326',
30
- cvss: 5.9,
31
- },
32
- fixable: undefined,
33
- hasSuggestions: false,
34
- messages: {
35
- weakSecret: (0, eslint_devkit_1.formatLLMMessage)({
36
- icon: eslint_devkit_1.MessageIcons.SECURITY,
37
- issueName: 'Weak JWT Secret',
38
- cwe: 'CWE-326',
39
- description: 'JWT secret is too weak and can be brute-forced',
40
- severity: 'HIGH',
41
- fix: 'Use crypto.randomBytes(32).toString("hex") for secrets',
42
- documentationLink: 'https://tools.ietf.org/html/rfc8725',
43
- }),
44
- shortSecret: (0, eslint_devkit_1.formatLLMMessage)({
45
- icon: eslint_devkit_1.MessageIcons.SECURITY,
46
- issueName: 'Short JWT Secret',
47
- cwe: 'CWE-326',
48
- description: 'JWT secret must be at least 32 characters (256 bits) for HS256',
49
- severity: 'HIGH',
50
- fix: 'Generate a secret with: crypto.randomBytes(32).toString("hex")',
51
- documentationLink: 'https://tools.ietf.org/html/rfc8725',
52
- }),
53
- useStrongSecret: (0, eslint_devkit_1.formatLLMMessage)({
54
- icon: eslint_devkit_1.MessageIcons.INFO,
55
- issueName: 'Use Strong Secret',
56
- description: 'Replace with cryptographically strong secret',
57
- severity: 'LOW',
58
- fix: 'Use process.env.JWT_SECRET with a 256-bit random value',
59
- documentationLink: 'https://nodejs.org/api/crypto.html',
60
- }),
61
- },
62
- schema: [
63
- {
64
- type: 'object',
65
- properties: {
66
- minSecretLength: {
67
- type: 'integer',
68
- default: 32,
69
- minimum: 16,
70
- description: 'Minimum secret length in characters',
71
- },
72
- trustedSanitizers: {
73
- type: 'array',
74
- items: { type: 'string' },
75
- default: [],
76
- },
77
- trustedAnnotations: {
78
- type: 'array',
79
- items: { type: 'string' },
80
- default: [],
81
- },
82
- strictMode: {
83
- type: 'boolean',
84
- default: false,
85
- },
86
- },
87
- additionalProperties: false,
88
- },
89
- ],
90
- },
91
- defaultOptions: [
92
- {
93
- minSecretLength: 32,
94
- trustedSanitizers: [],
95
- trustedAnnotations: [],
96
- strictMode: false,
97
- },
98
- ],
99
- create(context) {
100
- const options = context.options[0] ?? {};
101
- const { minSecretLength = 32 } = options;
102
- /**
103
- * Check if a value matches known weak patterns
104
- */
105
- const isKnownWeakPattern = (value) => {
106
- return WEAK_SECRET_PATTERNS.some((pattern) => pattern.test(value));
107
- };
108
- /**
109
- * Check the secret argument for weakness
110
- */
111
- const checkSecret = (secretNode) => {
112
- // Environment variables are considered safe (configuration)
113
- if ((0, utils_1.isEnvVariable)(secretNode)) {
114
- return;
115
- }
116
- // Check string literals
117
- if (secretNode.type === 'Literal' &&
118
- typeof secretNode.value === 'string') {
119
- const secretValue = secretNode.value;
120
- // Check for known weak patterns
121
- if (isKnownWeakPattern(secretValue)) {
122
- context.report({
123
- node: secretNode,
124
- messageId: 'weakSecret',
125
- });
126
- return;
127
- }
128
- // Check for short secrets
129
- if (secretValue.length < minSecretLength) {
130
- context.report({
131
- node: secretNode,
132
- messageId: 'shortSecret',
133
- data: {
134
- length: String(secretValue.length),
135
- minLength: String(minSecretLength),
136
- },
137
- });
138
- }
139
- }
140
- // Template literals with obvious weak values
141
- if (secretNode.type === 'TemplateLiteral' && secretNode.quasis.length === 1) {
142
- const rawValue = secretNode.quasis[0].value.raw;
143
- if (isKnownWeakPattern(rawValue) || rawValue.length < minSecretLength) {
144
- context.report({
145
- node: secretNode,
146
- messageId: 'weakSecret',
147
- });
148
- }
149
- }
150
- };
151
- return {
152
- CallExpression(node) {
153
- // Check both sign and verify operations
154
- if (!(0, utils_1.isSignOperation)(node) && !(0, utils_1.isVerifyOperation)(node)) {
155
- return;
156
- }
157
- // Secret is usually the second argument
158
- if (node.arguments.length >= 2) {
159
- checkSecret(node.arguments[1]);
160
- }
161
- },
162
- };
163
- },
164
- });
165
- exports.default = exports.noWeakSecret;
@@ -1,24 +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: require-algorithm-whitelist
8
- *
9
- * Enforces explicit algorithm specification in JWT verify operations.
10
- * Without explicit algorithms, the token's header algorithm is trusted,
11
- * enabling algorithm substitution attacks.
12
- *
13
- * CWE-757: Selection of Less-Secure Algorithm During Negotiation
14
- *
15
- * @see https://tools.ietf.org/html/rfc8725
16
- */
17
- import type { TSESLint } from '@interlace/eslint-devkit';
18
- import type { RequireAlgorithmWhitelistOptions } from '../../types';
19
- type MessageIds = 'missingAlgorithmWhitelist' | 'addAlgorithmWhitelist';
20
- type RuleOptions = [RequireAlgorithmWhitelistOptions?];
21
- export declare const requireAlgorithmWhitelist: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
22
- name: string;
23
- };
24
- export default requireAlgorithmWhitelist;
@@ -1,113 +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.requireAlgorithmWhitelist = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const utils_1 = require("../../utils");
11
- exports.requireAlgorithmWhitelist = (0, eslint_devkit_1.createRule)({
12
- name: 'require-algorithm-whitelist',
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/require-algorithm-whitelist.md',
17
- description: 'Require explicit algorithm specification in JWT verify operations',
18
- cwe: 'CWE-757',
19
- cvss: 7.5,
20
- },
21
- fixable: undefined,
22
- hasSuggestions: false,
23
- messages: {
24
- missingAlgorithmWhitelist: (0, eslint_devkit_1.formatLLMMessage)({
25
- icon: eslint_devkit_1.MessageIcons.SECURITY,
26
- issueName: 'Missing Algorithm Whitelist',
27
- cwe: 'CWE-757',
28
- description: 'JWT verification without explicit algorithms trusts the token header',
29
- severity: 'HIGH',
30
- fix: 'Add algorithms: ["RS256"] or algorithms: ["ES256"] to options',
31
- documentationLink: 'https://tools.ietf.org/html/rfc8725',
32
- }),
33
- addAlgorithmWhitelist: (0, eslint_devkit_1.formatLLMMessage)({
34
- icon: eslint_devkit_1.MessageIcons.INFO,
35
- issueName: 'Add Algorithm Whitelist',
36
- description: 'Specify allowed algorithms explicitly',
37
- severity: 'LOW',
38
- fix: 'jwt.verify(token, key, { algorithms: ["RS256"] })',
39
- documentationLink: 'https://tools.ietf.org/html/rfc8725',
40
- }),
41
- },
42
- schema: [
43
- {
44
- type: 'object',
45
- properties: {
46
- recommendedAlgorithms: {
47
- type: 'array',
48
- items: { type: 'string' },
49
- default: ['RS256', 'ES256'],
50
- description: 'Algorithms to suggest in auto-fix',
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
- recommendedAlgorithms: ['RS256', 'ES256'],
74
- trustedSanitizers: [],
75
- trustedAnnotations: [],
76
- strictMode: false,
77
- },
78
- ],
79
- create(context) {
80
- return {
81
- CallExpression(node) {
82
- // Only check verify operations
83
- if (!(0, utils_1.isVerifyOperation)(node)) {
84
- return;
85
- }
86
- // Need at least token and key arguments
87
- if (node.arguments.length < 2) {
88
- return;
89
- }
90
- const optionsArg = (0, utils_1.getOptionsArgument)(node, 2);
91
- // No options at all - definitely missing algorithms
92
- if (!optionsArg) {
93
- context.report({
94
- node,
95
- messageId: 'missingAlgorithmWhitelist',
96
- });
97
- return;
98
- }
99
- // Options exist but no algorithms property
100
- const hasAlgorithms = (0, utils_1.hasOption)(optionsArg, 'algorithms') ||
101
- (0, utils_1.hasOption)(optionsArg, 'algorithm') ||
102
- (0, utils_1.hasOption)(optionsArg, 'alg');
103
- if (!hasAlgorithms) {
104
- context.report({
105
- node: optionsArg,
106
- messageId: 'missingAlgorithmWhitelist',
107
- });
108
- }
109
- },
110
- };
111
- },
112
- });
113
- exports.default = exports.requireAlgorithmWhitelist;
@@ -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: require-audience-validation
8
- *
9
- * Mandates audience (aud) claim validation in JWT verify operations.
10
- * Without audience validation, tokens intended for other services are accepted.
11
- *
12
- * CWE-287: Improper Authentication
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- import type { RequireAudienceValidationOptions } from '../../types';
16
- type RuleOptions = [RequireAudienceValidationOptions?];
17
- export declare const requireAudienceValidation: TSESLint.RuleModule<"missingAudienceValidation", RuleOptions, unknown, TSESLint.RuleListener> & {
18
- name: string;
19
- };
20
- export default requireAudienceValidation;
@@ -1,100 +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.requireAudienceValidation = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const utils_1 = require("../../utils");
11
- exports.requireAudienceValidation = (0, eslint_devkit_1.createRule)({
12
- name: 'require-audience-validation',
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-jwt-security/docs/rules/require-audience-validation.md',
17
- description: 'Require audience (aud) claim validation in JWT verify operations',
18
- cwe: 'CWE-287',
19
- cvss: 9.8,
20
- },
21
- fixable: undefined,
22
- hasSuggestions: false,
23
- messages: {
24
- missingAudienceValidation: (0, eslint_devkit_1.formatLLMMessage)({
25
- icon: eslint_devkit_1.MessageIcons.SECURITY,
26
- issueName: 'Missing Audience Validation',
27
- cwe: 'CWE-287',
28
- description: 'JWT verification without audience validation accepts tokens intended for other services',
29
- severity: 'MEDIUM',
30
- fix: 'Add audience option: { audience: "https://api.example.com" }',
31
- documentationLink: 'https://tools.ietf.org/html/rfc8725',
32
- }),
33
- },
34
- schema: [
35
- {
36
- type: 'object',
37
- properties: {
38
- knownAudiences: {
39
- type: 'array',
40
- items: { type: 'string' },
41
- default: [],
42
- description: 'Known valid audiences to suggest',
43
- },
44
- trustedSanitizers: {
45
- type: 'array',
46
- items: { type: 'string' },
47
- default: [],
48
- },
49
- trustedAnnotations: {
50
- type: 'array',
51
- items: { type: 'string' },
52
- default: [],
53
- },
54
- strictMode: {
55
- type: 'boolean',
56
- default: false,
57
- },
58
- },
59
- additionalProperties: false,
60
- },
61
- ],
62
- },
63
- defaultOptions: [
64
- {
65
- knownAudiences: [],
66
- trustedSanitizers: [],
67
- trustedAnnotations: [],
68
- strictMode: false,
69
- },
70
- ],
71
- create(context) {
72
- return {
73
- CallExpression(node) {
74
- if (!(0, utils_1.isVerifyOperation)(node)) {
75
- return;
76
- }
77
- if (node.arguments.length < 2) {
78
- return;
79
- }
80
- const optionsArg = (0, utils_1.getOptionsArgument)(node, 2);
81
- // No options at all
82
- if (!optionsArg) {
83
- context.report({
84
- node,
85
- messageId: 'missingAudienceValidation',
86
- });
87
- return;
88
- }
89
- // Check for audience option
90
- if (!(0, utils_1.hasOption)(optionsArg, 'audience') && !(0, utils_1.hasOption)(optionsArg, 'aud')) {
91
- context.report({
92
- node: optionsArg,
93
- messageId: 'missingAudienceValidation',
94
- });
95
- }
96
- },
97
- };
98
- },
99
- });
100
- exports.default = exports.requireAudienceValidation;