eslint-plugin-jwt-security 2.3.1 → 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.
@@ -1,165 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JWT_METHODS = exports.SENSITIVE_PAYLOAD_FIELDS = exports.SECURE_ALGORITHMS = exports.SYMMETRIC_ALGORITHMS = exports.INSECURE_ALGORITHMS = exports.JWT_LIBRARIES = void 0;
4
- exports.isJwtLibraryCall = isJwtLibraryCall;
5
- exports.isStringLiteral = isStringLiteral;
6
- exports.extractAlgorithms = extractAlgorithms;
7
- exports.hasOption = hasOption;
8
- exports.getOptionValue = getOptionValue;
9
- exports.isWeakSecret = isWeakSecret;
10
- exports.isEnvVariable = isEnvVariable;
11
- exports.isSignOperation = isSignOperation;
12
- exports.isVerifyOperation = isVerifyOperation;
13
- exports.isDecodeOperation = isDecodeOperation;
14
- exports.getOptionsArgument = getOptionsArgument;
15
- exports.isTestFile = isTestFile;
16
- exports.JWT_LIBRARIES = {
17
- JSONWEBTOKEN: 'jsonwebtoken',
18
- JOSE: 'jose',
19
- EXPRESS_JWT: 'express-jwt',
20
- NESTJS_JWT: '@nestjs/jwt',
21
- JWKS_RSA: 'jwks-rsa',
22
- JWT_DECODE: 'jwt-decode',
23
- };
24
- exports.INSECURE_ALGORITHMS = new Set([
25
- 'none',
26
- 'None',
27
- 'NONE',
28
- 'HS256',
29
- 'HS384',
30
- 'HS512',
31
- ]);
32
- exports.SYMMETRIC_ALGORITHMS = new Set(['HS256', 'HS384', 'HS512']);
33
- exports.SECURE_ALGORITHMS = new Set([
34
- 'RS256',
35
- 'RS384',
36
- 'RS512',
37
- 'ES256',
38
- 'ES384',
39
- 'ES512',
40
- 'PS256',
41
- 'PS384',
42
- 'PS512',
43
- 'EdDSA',
44
- ]);
45
- exports.SENSITIVE_PAYLOAD_FIELDS = new Set([
46
- 'password', 'passwd', 'pwd', 'pass', 'secret',
47
- 'apikey', 'api_key', 'api-key',
48
- 'apisecret', 'api_secret', 'api-secret',
49
- 'accesstoken', 'access_token', 'access-token',
50
- 'refreshtoken', 'refresh_token', 'refresh-token',
51
- 'bearertoken', 'bearer_token', 'bearer-token',
52
- 'privatekey', 'private_key', 'private-key',
53
- 'secretkey', 'secret_key', 'secret-key',
54
- 'email', 'emailaddress', 'email_address', 'email-address',
55
- 'phone', 'phonenumber', 'phone_number', 'phone-number',
56
- 'ssn', 'socialsecuritynumber', 'social_security_number',
57
- 'dob', 'dateofbirth', 'date_of_birth', 'birthdate',
58
- 'address', 'streetaddress', 'street_address',
59
- 'creditcard', 'credit_card', 'credit-card',
60
- 'cardnumber', 'card_number', 'card-number',
61
- 'cvv', 'cvc', 'securitycode', 'security_code',
62
- 'pin', 'pincode', 'pin_code',
63
- 'bankaccount', 'bank_account', 'bank-account',
64
- 'accountnumber', 'account_number', 'account-number',
65
- 'routingnumber', 'routing_number', 'routing-number',
66
- ]);
67
- exports.JWT_METHODS = {
68
- SIGN: new Set(['sign', 'signJWT', 'SignJWT']),
69
- VERIFY: new Set(['verify', 'verifyJWT', 'jwtVerify']),
70
- DECODE: new Set(['decode', 'jwtDecode', 'decodeJWT']),
71
- };
72
- function isJwtLibraryCall(node, targetMethods) {
73
- if (node.callee.type === 'MemberExpression') {
74
- const property = node.callee.property;
75
- if (property.type === 'Identifier') {
76
- return targetMethods.has(property.name);
77
- }
78
- }
79
- if (node.callee.type === 'Identifier') {
80
- return targetMethods.has(node.callee.name);
81
- }
82
- return false;
83
- }
84
- function isStringLiteral(node, value) {
85
- if (node.type !== 'Literal' || typeof node.value !== 'string') {
86
- return false;
87
- }
88
- return value === undefined || node.value === value;
89
- }
90
- function extractAlgorithms(optionsNode) {
91
- const algorithms = [];
92
- for (const prop of optionsNode.properties) {
93
- if (prop.type !== 'Property' || prop.key.type !== 'Identifier') {
94
- continue;
95
- }
96
- const keyName = prop.key.name;
97
- if (keyName !== 'algorithms' && keyName !== 'algorithm' && keyName !== 'alg') {
98
- continue;
99
- }
100
- if (prop.value.type === 'Literal' && typeof prop.value.value === 'string') {
101
- algorithms.push(prop.value.value);
102
- }
103
- if (prop.value.type === 'ArrayExpression') {
104
- for (const elem of prop.value.elements) {
105
- if (elem && elem.type === 'Literal' && typeof elem.value === 'string') {
106
- algorithms.push(elem.value);
107
- }
108
- }
109
- }
110
- }
111
- return algorithms;
112
- }
113
- function hasOption(optionsNode, optionName) {
114
- return optionsNode.properties.some((prop) => prop.type === 'Property' &&
115
- prop.key.type === 'Identifier' &&
116
- prop.key.name === optionName);
117
- }
118
- function getOptionValue(optionsNode, optionName) {
119
- for (const prop of optionsNode.properties) {
120
- if (prop.type === 'Property' &&
121
- prop.key.type === 'Identifier' &&
122
- prop.key.name === optionName) {
123
- return prop.value;
124
- }
125
- }
126
- return undefined;
127
- }
128
- function isWeakSecret(node, minLength = 32) {
129
- if (node.type === 'Literal' && typeof node.value === 'string') {
130
- return node.value.length < minLength;
131
- }
132
- return false;
133
- }
134
- function isEnvVariable(node) {
135
- if (node.type === 'MemberExpression' &&
136
- node.object.type === 'MemberExpression' &&
137
- node.object.object.type === 'Identifier' &&
138
- node.object.object.name === 'process' &&
139
- node.object.property.type === 'Identifier' &&
140
- node.object.property.name === 'env') {
141
- return true;
142
- }
143
- return false;
144
- }
145
- function isSignOperation(node) {
146
- return isJwtLibraryCall(node, exports.JWT_METHODS.SIGN);
147
- }
148
- function isVerifyOperation(node) {
149
- return isJwtLibraryCall(node, exports.JWT_METHODS.VERIFY);
150
- }
151
- function isDecodeOperation(node) {
152
- return isJwtLibraryCall(node, exports.JWT_METHODS.DECODE);
153
- }
154
- function getOptionsArgument(node, optionsIndex = 2) {
155
- const arg = node.arguments[optionsIndex];
156
- if (arg && arg.type === 'ObjectExpression') {
157
- return arg;
158
- }
159
- return undefined;
160
- }
161
- function isTestFile(filename) {
162
- return /\.(test|spec)\.[jt]sx?$/.test(filename) ||
163
- /__(tests?|mocks?)__/.test(filename) ||
164
- /\/(tests?|specs?|__tests__)\//.test(filename);
165
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.JWT_METHODS=exports.SENSITIVE_PAYLOAD_FIELDS=exports.SECURE_ALGORITHMS=exports.SYMMETRIC_ALGORITHMS=exports.INSECURE_ALGORITHMS=exports.JWT_LIBRARIES=void 0;exports.isJwtLibraryCall=isJwtLibraryCall;exports.isStringLiteral=isStringLiteral;exports.extractAlgorithms=extractAlgorithms;exports.hasOption=hasOption;exports.getOptionValue=getOptionValue;exports.isWeakSecret=isWeakSecret;exports.isEnvVariable=isEnvVariable;exports.isSignOperation=isSignOperation;exports.isVerifyOperation=isVerifyOperation;exports.isDecodeOperation=isDecodeOperation;exports.getOptionsArgument=getOptionsArgument;exports.isTestFile=isTestFile;exports.JWT_LIBRARIES={JSONWEBTOKEN:"jsonwebtoken",JOSE:"jose",EXPRESS_JWT:"express-jwt",NESTJS_JWT:"@nestjs/jwt",JWKS_RSA:"jwks-rsa",JWT_DECODE:"jwt-decode"};exports.INSECURE_ALGORITHMS=new Set(["none","None","NONE","HS256","HS384","HS512"]);exports.SYMMETRIC_ALGORITHMS=new Set(["HS256","HS384","HS512"]);exports.SECURE_ALGORITHMS=new Set(["RS256","RS384","RS512","ES256","ES384","ES512","PS256","PS384","PS512","EdDSA"]);exports.SENSITIVE_PAYLOAD_FIELDS=new Set(["password","passwd","pwd","pass","secret","apikey","api_key","api-key","apisecret","api_secret","api-secret","accesstoken","access_token","access-token","refreshtoken","refresh_token","refresh-token","bearertoken","bearer_token","bearer-token","privatekey","private_key","private-key","secretkey","secret_key","secret-key","email","emailaddress","email_address","email-address","phone","phonenumber","phone_number","phone-number","ssn","socialsecuritynumber","social_security_number","dob","dateofbirth","date_of_birth","birthdate","address","streetaddress","street_address","creditcard","credit_card","credit-card","cardnumber","card_number","card-number","cvv","cvc","securitycode","security_code","pin","pincode","pin_code","bankaccount","bank_account","bank-account","accountnumber","account_number","account-number","routingnumber","routing_number","routing-number"]);exports.JWT_METHODS={SIGN:new Set(["sign","signJWT","SignJWT"]),VERIFY:new Set(["verify","verifyJWT","jwtVerify"]),DECODE:new Set(["decode","jwtDecode","decodeJWT"])};function isJwtLibraryCall(node,targetMethods){if(node.callee.type==="MemberExpression"){const property=node.callee.property;if(property.type==="Identifier"){return targetMethods.has(property.name)}}if(node.callee.type==="Identifier"){return targetMethods.has(node.callee.name)}return false}function isStringLiteral(node,value){if(node.type!=="Literal"||typeof node.value!=="string"){return false}return value===void 0||node.value===value}function extractAlgorithms(optionsNode){const algorithms=[];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"){algorithms.push(prop.value.value)}if(prop.value.type==="ArrayExpression"){for(const elem of prop.value.elements){if(elem&&elem.type==="Literal"&&typeof elem.value==="string"){algorithms.push(elem.value)}}}}return algorithms}function hasOption(optionsNode,optionName){return optionsNode.properties.some(prop=>prop.type==="Property"&&prop.key.type==="Identifier"&&prop.key.name===optionName)}function getOptionValue(optionsNode,optionName){for(const prop of optionsNode.properties){if(prop.type==="Property"&&prop.key.type==="Identifier"&&prop.key.name===optionName){return prop.value}}return void 0}function isWeakSecret(node,minLength=32){if(node.type==="Literal"&&typeof node.value==="string"){return node.value.length<minLength}return false}function isEnvVariable(node){if(node.type==="MemberExpression"&&node.object.type==="MemberExpression"&&node.object.object.type==="Identifier"&&node.object.object.name==="process"&&node.object.property.type==="Identifier"&&node.object.property.name==="env"){return true}return false}function isSignOperation(node){return isJwtLibraryCall(node,exports.JWT_METHODS.SIGN)}function isVerifyOperation(node){return isJwtLibraryCall(node,exports.JWT_METHODS.VERIFY)}function isDecodeOperation(node){return isJwtLibraryCall(node,exports.JWT_METHODS.DECODE)}function getOptionsArgument(node,optionsIndex=2){const arg=node.arguments[optionsIndex];if(arg&&arg.type==="ObjectExpression"){return arg}return void 0}function isTestFile(filename){return/\.(test|spec)\.[jt]sx?$/.test(filename)||/__(tests?|mocks?)__/.test(filename)||/\/(tests?|specs?|__tests__)\//.test(filename)}