eslint-plugin-sonarjs 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cjs/S100/rule.js +7 -5
- package/cjs/S101/rule.js +2 -2
- package/cjs/S104/rule.js +2 -2
- package/cjs/S105/rule.js +2 -2
- package/cjs/S1066/rule.js +5 -4
- package/cjs/S1067/rule.js +8 -6
- package/cjs/S1110/rule.js +7 -5
- package/cjs/S1119/rule.js +2 -2
- package/cjs/S1121/rule.js +4 -3
- package/cjs/S1125/rule.js +9 -8
- package/cjs/S1126/rule.js +2 -2
- package/cjs/S1128/rule.js +8 -5
- package/cjs/S1134/rule.js +2 -2
- package/cjs/S1135/rule.js +2 -2
- package/cjs/S1154/rule.js +6 -4
- package/cjs/S117/rule.js +6 -5
- package/cjs/S1172/rule.js +2 -2
- package/cjs/S1192/rule.js +5 -4
- package/cjs/S1219/rule.js +4 -3
- package/cjs/S1226/rule.js +6 -4
- package/cjs/S124/rule.js +2 -2
- package/cjs/S125/rule.js +9 -7
- package/cjs/S126/rule.js +2 -2
- package/cjs/S1264/rule.js +2 -2
- package/cjs/S128/rule.js +4 -3
- package/cjs/S1291/rule.js +2 -2
- package/cjs/S1301/rule.js +2 -2
- package/cjs/S1313/rule.js +2 -2
- package/cjs/S134/rule.js +7 -5
- package/cjs/S135/rule.js +5 -4
- package/cjs/S138/rule.js +9 -6
- package/cjs/S1439/rule.js +2 -2
- package/cjs/S1444/rule.js +2 -2
- package/cjs/S1451/rule.js +2 -2
- package/cjs/S1472/rule.js +2 -2
- package/cjs/S1479/rule.js +2 -2
- package/cjs/S1481/rule.js +2 -2
- package/cjs/S1488/rule.js +11 -7
- package/cjs/S1515/rule.js +10 -8
- package/cjs/S1523/rule.js +5 -5
- package/cjs/S1526/rule.js +5 -4
- package/cjs/S1527/rule.js +2 -2
- package/cjs/S1528/rule.js +2 -2
- package/cjs/S1529/rule.js +4 -3
- package/cjs/S1530/rule.js +5 -3
- package/cjs/S1533/rule.js +2 -2
- package/cjs/S1535/rule.js +2 -2
- package/cjs/S1541/rule.js +10 -7
- package/cjs/S1607/rule.js +22 -20
- package/cjs/S1764/rule.js +10 -7
- package/cjs/S1821/rule.js +2 -2
- package/cjs/S1848/rule.js +10 -7
- package/cjs/S1854/rule.js +18 -14
- package/cjs/S1862/rule.js +10 -8
- package/cjs/S1871/rule.js +21 -16
- package/cjs/S1874/rule.js +4 -3
- package/cjs/S1940/rule.js +2 -2
- package/cjs/S1994/rule.js +10 -7
- package/cjs/S2004/rule.js +9 -7
- package/cjs/S2068/rule.js +75 -12
- package/cjs/S2077/rule.js +10 -6
- package/cjs/S2092/rule.js +2 -2
- package/cjs/S2123/rule.js +2 -2
- package/cjs/S2137/rule.js +2 -2
- package/cjs/S2138/rule.js +4 -3
- package/cjs/S2187/rule.js +2 -2
- package/cjs/S2201/rule.js +8 -5
- package/cjs/S2208/rule.js +2 -2
- package/cjs/S2234/rule.js +15 -11
- package/cjs/S2245/rule.js +4 -3
- package/cjs/S2251/rule.js +5 -4
- package/cjs/S2255/rule.js +6 -5
- package/cjs/S2259/rule.js +14 -9
- package/cjs/S2301/rule.js +14 -9
- package/cjs/S2310/rule.js +14 -11
- package/cjs/S2392/rule.js +7 -5
- package/cjs/S2424/rule.js +2 -2
- package/cjs/S2428/rule.js +8 -6
- package/cjs/S2486/rule.js +4 -3
- package/cjs/S2589/rule.js +12 -10
- package/cjs/S2598/rule.js +17 -14
- package/cjs/S2612/generated-meta.js +1 -1
- package/cjs/S2612/rule.js +8 -6
- package/cjs/S2639/rule.js +2 -2
- package/cjs/S2681/rule.js +2 -2
- package/cjs/S2692/rule.js +6 -4
- package/cjs/S2699/rule.js +40 -31
- package/cjs/S2703/rule.js +2 -2
- package/cjs/S2737/rule.js +6 -4
- package/cjs/S2755/rule.js +9 -6
- package/cjs/S2757/rule.js +2 -2
- package/cjs/S2817/rule.js +10 -7
- package/cjs/S2819/rule.js +16 -12
- package/cjs/S2870/rule.js +8 -5
- package/cjs/S2871/rule.js +12 -9
- package/cjs/S2970/rule.js +9 -8
- package/cjs/S2990/rule.js +2 -2
- package/cjs/S2999/rule.js +10 -7
- package/cjs/S3001/rule.js +2 -2
- package/cjs/S3003/rule.js +10 -7
- package/cjs/S3317/rule.js +4 -3
- package/cjs/S3330/rule.js +2 -2
- package/cjs/S3358/rule.js +2 -2
- package/cjs/S3402/rule.js +14 -10
- package/cjs/S3403/rule.js +10 -7
- package/cjs/S3415/rule.js +16 -13
- package/cjs/S3499/rule.js +5 -4
- package/cjs/S3500/rule.js +5 -4
- package/cjs/S3513/rule.js +5 -4
- package/cjs/S3514/rule.js +10 -7
- package/cjs/S3516/rule.js +10 -7
- package/cjs/S3524/rule.js +2 -2
- package/cjs/S3525/rule.js +6 -4
- package/cjs/S3531/rule.js +5 -3
- package/cjs/S3533/rule.js +8 -7
- package/cjs/S3579/rule.js +6 -4
- package/cjs/S3616/rule.js +6 -4
- package/cjs/S3626/rule.js +4 -3
- package/cjs/S3686/rule.js +7 -5
- package/cjs/S3699/rule.js +4 -3
- package/cjs/S3735/rule.js +8 -5
- package/cjs/S3757/rule.js +8 -6
- package/cjs/S3758/rule.js +9 -7
- package/cjs/S3760/rule.js +24 -21
- package/cjs/S3776/rule.js +26 -22
- package/cjs/S3782/rule.js +6 -4
- package/cjs/S3785/rule.js +9 -6
- package/cjs/S3796/rule.js +12 -8
- package/cjs/S3798/rule.js +4 -3
- package/cjs/S3800/rule.js +16 -11
- package/cjs/S3801/rule.js +15 -11
- package/cjs/S3827/rule.js +9 -6
- package/cjs/S3923/rule.js +9 -6
- package/cjs/S3972/rule.js +5 -4
- package/cjs/S3973/rule.js +7 -5
- package/cjs/S3981/rule.js +4 -3
- package/cjs/S3984/rule.js +4 -3
- package/cjs/S4030/rule.js +10 -7
- package/cjs/S4036/rule.js +7 -5
- package/cjs/S4043/rule.js +12 -8
- package/cjs/S4139/rule.js +7 -5
- package/cjs/S4143/rule.js +12 -9
- package/cjs/S4144/rule.js +12 -9
- package/cjs/S4158/rule.js +11 -8
- package/cjs/S4165/rule.js +14 -12
- package/cjs/S4322/rule.js +8 -5
- package/cjs/S4323/rule.js +4 -3
- package/cjs/S4324/rule.js +7 -5
- package/cjs/S4328/rule.js +2 -2
- package/cjs/S4335/rule.js +6 -4
- package/cjs/S4423/rule.js +4 -3
- package/cjs/S4423/rule.lib.js +8 -7
- package/cjs/S4426/rule.js +11 -10
- package/cjs/S4502/rule.js +16 -13
- package/cjs/S4507/rule.js +8 -6
- package/cjs/S4524/rule.js +2 -2
- package/cjs/S4619/rule.js +6 -4
- package/cjs/S4621/rule.js +5 -4
- package/cjs/S4622/rule.js +5 -3
- package/cjs/S4623/rule.js +8 -5
- package/cjs/S4624/rule.js +6 -4
- package/cjs/S4634/rule.js +4 -3
- package/cjs/S4721/rule.js +7 -5
- package/cjs/S4782/rule.js +7 -5
- package/cjs/S4784/rule.js +5 -4
- package/cjs/S4787/rule.js +9 -7
- package/cjs/S4790/rule.js +7 -5
- package/cjs/S4798/rule.js +2 -2
- package/cjs/S4817/rule.js +10 -8
- package/cjs/S4818/rule.js +4 -3
- package/cjs/S4822/rule.js +13 -9
- package/cjs/S4823/rule.js +4 -3
- package/cjs/S4829/rule.js +4 -3
- package/cjs/S4830/rule.js +11 -8
- package/cjs/S5042/rule.js +9 -7
- package/cjs/S5122/rule.js +40 -36
- package/cjs/S5148/rule.js +9 -8
- package/cjs/S5247/rule.js +22 -18
- package/cjs/S5256/rule.js +5 -4
- package/cjs/S5257/rule.js +4 -3
- package/cjs/S5260/rule.js +4 -3
- package/cjs/S5264/rule.js +4 -3
- package/cjs/S5332/rule.js +4 -3
- package/cjs/S5332/rule.lib.js +19 -17
- package/cjs/S5443/rule.js +2 -2
- package/cjs/S5527/rule.js +18 -14
- package/cjs/S5542/rule.js +6 -4
- package/cjs/S5547/rule.js +6 -4
- package/cjs/S5604/rule.js +15 -14
- package/cjs/S5659/rule.js +15 -12
- package/cjs/S5689/rule.js +11 -8
- package/cjs/S5691/rule.js +7 -5
- package/cjs/S5693/rule.js +14 -12
- package/cjs/S5725/rule.js +9 -6
- package/cjs/S5728/rule.js +7 -4
- package/cjs/S5730/rule.js +9 -6
- package/cjs/S5732/rule.js +8 -5
- package/cjs/S5734/rule.js +7 -4
- package/cjs/S5736/rule.js +8 -5
- package/cjs/S5739/rule.js +11 -8
- package/cjs/S5742/rule.js +7 -4
- package/cjs/S5743/rule.js +8 -6
- package/cjs/S5757/rule.js +13 -10
- package/cjs/S5759/rule.js +10 -7
- package/cjs/S5842/rule.js +2 -2
- package/cjs/S5843/rule.js +22 -19
- package/cjs/S5850/rule.js +4 -3
- package/cjs/S5852/rule.js +2 -2
- package/cjs/S5856/rule.js +10 -7
- package/cjs/S5860/rule.js +30 -26
- package/cjs/S5863/rule.js +15 -11
- package/cjs/S5867/rule.js +8 -7
- package/cjs/S5868/rule.js +7 -5
- package/cjs/S5869/rule.js +6 -5
- package/cjs/S5876/rule.js +12 -8
- package/cjs/S5958/rule.js +12 -9
- package/cjs/S5973/rule.js +10 -7
- package/cjs/S6019/rule.js +4 -3
- package/cjs/S6035/rule.js +2 -2
- package/cjs/S6079/rule.js +9 -6
- package/cjs/S6080/rule.js +13 -10
- package/cjs/S6092/rule.js +9 -7
- package/cjs/S6245/rule.js +14 -9
- package/cjs/S6249/rule.js +7 -5
- package/cjs/S6252/rule.js +12 -8
- package/cjs/S6265/rule.js +27 -20
- package/cjs/S6268/rule.js +5 -4
- package/cjs/S6270/rule.js +12 -9
- package/cjs/S6275/rule.js +2 -2
- package/cjs/S6281/rule.js +22 -17
- package/cjs/S6299/rule.js +2 -2
- package/cjs/S6302/rule.js +6 -5
- package/cjs/S6303/rule.js +12 -10
- package/cjs/S6304/rule.js +6 -5
- package/cjs/S6308/rule.js +7 -5
- package/cjs/S6317/rule.js +5 -4
- package/cjs/S6319/rule.js +2 -2
- package/cjs/S6321/rule.js +25 -23
- package/cjs/S6323/rule.js +4 -3
- package/cjs/S6324/rule.js +2 -2
- package/cjs/S6326/rule.js +2 -2
- package/cjs/S6327/rule.js +2 -2
- package/cjs/S6328/rule.js +4 -3
- package/cjs/S6329/rule.js +7 -5
- package/cjs/S6330/rule.js +2 -2
- package/cjs/S6332/rule.js +2 -2
- package/cjs/S6333/rule.js +8 -6
- package/cjs/S6351/rule.js +22 -19
- package/cjs/S6353/rule.js +2 -2
- package/cjs/S6397/rule.js +2 -2
- package/cjs/S6418/rule.js +9 -24
- package/cjs/S6426/rule.js +5 -4
- package/cjs/S6437/rule.js +10 -7
- package/cjs/S6439/rule.js +9 -7
- package/cjs/S6442/rule.js +11 -8
- package/cjs/S6443/rule.js +9 -7
- package/cjs/S6486/rule.js +5 -4
- package/cjs/S6564/rule.js +4 -3
- package/cjs/S6594/rule.js +12 -8
- package/cjs/S6627/rule.js +6 -4
- package/cjs/S6759/rule.js +10 -6
- package/cjs/S6958/rule.js +2 -2
- package/cjs/S6959/rule.js +9 -6
- package/cjs/S7059/rule.js +8 -5
- package/cjs/S7639/rule.js +5 -4
- package/cjs/S7790/rule.js +7 -5
- package/cjs/S8441/rule.js +13 -9
- package/cjs/S881/rule.js +2 -2
- package/cjs/S888/rule.js +4 -3
- package/cjs/S930/rule.js +14 -12
- package/cjs/helpers/ast.js +11 -8
- package/cjs/helpers/aws/s3.js +9 -6
- package/cjs/helpers/chai.js +41 -43
- package/cjs/helpers/cookie-flag-check.js +19 -17
- package/cjs/helpers/{decorators/index.js → entropy.js} +16 -17
- package/cjs/helpers/express.js +127 -128
- package/cjs/helpers/mocha.js +50 -54
- package/cjs/helpers/regex/ast.js +7 -6
- package/cjs/helpers/regex/extract.js +11 -11
- package/cjs/helpers/regex/group.js +2 -2
- package/cjs/helpers/regex/location.js +2 -2
- package/cjs/helpers/regex/range.js +5 -4
- package/cjs/helpers/regex/rule-template.js +4 -3
- package/cjs/helpers/sinon.js +33 -36
- package/cjs/helpers/supertest.js +34 -37
- package/cjs/helpers/vitest.js +29 -32
- package/docs/file-permissions.md +1 -1
- package/package.json +39 -1
- package/types/helpers/ancestor.d.ts +1 -1
- package/types/helpers/aws/s3.d.ts +1 -1
- package/types/helpers/chai.d.ts +3 -5
- package/types/helpers/entropy.d.ts +1 -0
- package/types/helpers/express.d.ts +38 -43
- package/types/helpers/mocha.d.ts +19 -21
- package/types/helpers/regex/ast.d.ts +1 -1
- package/types/helpers/regex/rule-template.d.ts +1 -1
- package/types/helpers/sinon.d.ts +3 -5
- package/types/helpers/supertest.d.ts +3 -5
- package/types/helpers/type.d.ts +1 -1
- package/types/helpers/vitest.d.ts +3 -5
- package/cjs/helpers/aws/index.js +0 -35
- package/cjs/helpers/decorators/interceptor.js +0 -88
- package/cjs/helpers/index.js +0 -60
- package/cjs/helpers/recognizers/index.js +0 -37
- package/cjs/helpers/rule-detect-react.js +0 -29
- package/cjs/helpers/validate-version.js +0 -94
- package/types/helpers/aws/index.d.ts +0 -3
- package/types/helpers/decorators/index.d.ts +0 -2
- package/types/helpers/decorators/interceptor.d.ts +0 -16
- package/types/helpers/index.d.ts +0 -28
- package/types/helpers/recognizers/index.d.ts +0 -2
- package/types/helpers/rule-detect-react.d.ts +0 -2
- package/types/helpers/validate-version.d.ts +0 -13
package/cjs/helpers/aws/s3.js
CHANGED
|
@@ -5,7 +5,10 @@ exports.isS3BucketConstructor = isS3BucketConstructor;
|
|
|
5
5
|
exports.isS3BucketDeploymentConstructor = isS3BucketDeploymentConstructor;
|
|
6
6
|
exports.getBucketProperty = getBucketProperty;
|
|
7
7
|
exports.findPropagatedSetting = findPropagatedSetting;
|
|
8
|
-
const
|
|
8
|
+
const location_js_1 = require("../location.js");
|
|
9
|
+
const module_js_1 = require("../module.js");
|
|
10
|
+
const ancestor_js_1 = require("../ancestor.js");
|
|
11
|
+
const ast_js_1 = require("../ast.js");
|
|
9
12
|
const cdk_js_1 = require("./cdk.js");
|
|
10
13
|
/**
|
|
11
14
|
* A rule template for AWS S3 Buckets
|
|
@@ -40,7 +43,7 @@ function S3BucketTemplate(callback, meta = {}) {
|
|
|
40
43
|
* new s3.Bucket();
|
|
41
44
|
*/
|
|
42
45
|
function isS3BucketConstructor(context, node) {
|
|
43
|
-
return (0, cdk_js_1.normalizeFQN)((0,
|
|
46
|
+
return (0, cdk_js_1.normalizeFQN)((0, module_js_1.getFullyQualifiedName)(context, node)) === 'aws_cdk_lib.aws_s3.Bucket';
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
49
|
* Detects S3 BucketDeployment's constructor invocation from 'aws-cdk-lib/aws-s3-deployment':
|
|
@@ -49,7 +52,7 @@ function isS3BucketConstructor(context, node) {
|
|
|
49
52
|
* new s3.BucketDeployment();
|
|
50
53
|
*/
|
|
51
54
|
function isS3BucketDeploymentConstructor(context, node) {
|
|
52
|
-
return ((0, cdk_js_1.normalizeFQN)((0,
|
|
55
|
+
return ((0, cdk_js_1.normalizeFQN)((0, module_js_1.getFullyQualifiedName)(context, node)) ===
|
|
53
56
|
'aws_cdk_lib.aws_s3_deployment.BucketDeployment');
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
@@ -71,11 +74,11 @@ function isS3BucketDeploymentConstructor(context, node) {
|
|
|
71
74
|
function getBucketProperty(context, bucket, key) {
|
|
72
75
|
const args = bucket.arguments;
|
|
73
76
|
const optionsArg = args[2];
|
|
74
|
-
const options = (0,
|
|
77
|
+
const options = (0, ast_js_1.getValueOfExpression)(context, optionsArg, 'ObjectExpression');
|
|
75
78
|
if (options == null) {
|
|
76
79
|
return null;
|
|
77
80
|
}
|
|
78
|
-
return options.properties.find(property => (0,
|
|
81
|
+
return options.properties.find(property => (0, ast_js_1.isProperty)(property) && (0, ast_js_1.isIdentifier)(property.key, key));
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
81
84
|
* Finds the propagated setting of a sensitive property
|
|
@@ -83,7 +86,7 @@ function getBucketProperty(context, bucket, key) {
|
|
|
83
86
|
function findPropagatedSetting(sensitiveProperty, propagatedValue) {
|
|
84
87
|
const isPropagatedProperty = sensitiveProperty.value !== propagatedValue;
|
|
85
88
|
if (isPropagatedProperty) {
|
|
86
|
-
return (0,
|
|
89
|
+
return (0, location_js_1.toSecondaryLocation)((0, ancestor_js_1.getNodeParent)(propagatedValue), 'Propagated setting.');
|
|
87
90
|
}
|
|
88
91
|
return undefined;
|
|
89
92
|
}
|
package/cjs/helpers/chai.js
CHANGED
|
@@ -3,51 +3,49 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.isImported = isImported;
|
|
7
|
+
exports.isTSAssertion = isTSAssertion;
|
|
8
|
+
exports.isAssertion = isAssertion;
|
|
9
|
+
const module_js_1 = require("./module.js");
|
|
10
|
+
const module_ts_js_1 = require("./module-ts.js");
|
|
11
|
+
const ast_js_1 = require("./ast.js");
|
|
8
12
|
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
function isImported(context) {
|
|
14
|
+
return ((0, module_js_1.getRequireCalls)(context).some(r => r.arguments[0].type === 'Literal' && r.arguments[0].value === 'chai') || (0, module_js_1.getImportDeclarations)(context).some(i => i.source.value === 'chai'));
|
|
15
|
+
}
|
|
16
|
+
function isTSAssertion(services, node) {
|
|
17
|
+
if (node.kind !== typescript_1.default.SyntaxKind.CallExpression) {
|
|
18
|
+
return false;
|
|
13
19
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
const fqn = (0, index_js_1.getFullyQualifiedNameTS)(services, node);
|
|
20
|
-
if (!fqn) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return fqn.startsWith('chai.assert') || fqn.startsWith('chai.expect') || fqn.includes('should');
|
|
20
|
+
const fqn = (0, module_ts_js_1.getFullyQualifiedNameTS)(services, node);
|
|
21
|
+
if (!fqn) {
|
|
22
|
+
return false;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
return fqn.startsWith('chai.assert') || fqn.startsWith('chai.expect') || fqn.includes('should');
|
|
25
|
+
}
|
|
26
|
+
function isAssertion(context, node) {
|
|
27
|
+
return isAssertUsage(context, node) || isExpectUsage(context, node) || isShouldUsage(node);
|
|
28
|
+
}
|
|
29
|
+
function isAssertUsage(context, node) {
|
|
30
|
+
// assert(), assert.<expr>(), chai.assert(), chai.assert.<expr>()
|
|
31
|
+
const fqn = extractFQNforCallExpression(context, node);
|
|
32
|
+
if (!fqn) {
|
|
33
|
+
return false;
|
|
28
34
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const names = fqn.split('.');
|
|
36
|
+
return names[0] === 'chai' && names[1] === 'assert';
|
|
37
|
+
}
|
|
38
|
+
function isExpectUsage(context, node) {
|
|
39
|
+
// expect(), chai.expect()
|
|
40
|
+
return extractFQNforCallExpression(context, node) === 'chai.expect';
|
|
41
|
+
}
|
|
42
|
+
function isShouldUsage(node) {
|
|
43
|
+
// <expr>.should.<expr>
|
|
44
|
+
return node.type === 'MemberExpression' && (0, ast_js_1.isIdentifier)(node.property, 'should');
|
|
45
|
+
}
|
|
46
|
+
function extractFQNforCallExpression(context, node) {
|
|
47
|
+
if (node.type !== 'CallExpression') {
|
|
48
|
+
return undefined;
|
|
38
49
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return extractFQNforCallExpression(context, node) === 'chai.expect';
|
|
42
|
-
}
|
|
43
|
-
function isShouldUsage(node) {
|
|
44
|
-
// <expr>.should.<expr>
|
|
45
|
-
return node.type === 'MemberExpression' && (0, index_js_1.isIdentifier)(node.property, 'should');
|
|
46
|
-
}
|
|
47
|
-
function extractFQNforCallExpression(context, node) {
|
|
48
|
-
if (node.type !== 'CallExpression') {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
return (0, index_js_1.getFullyQualifiedName)(context, node);
|
|
52
|
-
}
|
|
53
|
-
})(Chai || (exports.Chai = Chai = {}));
|
|
50
|
+
return (0, module_js_1.getFullyQualifiedName)(context, node);
|
|
51
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CookieFlagCheck = void 0;
|
|
4
|
-
const
|
|
4
|
+
const location_js_1 = require("./location.js");
|
|
5
|
+
const ast_js_1 = require("./ast.js");
|
|
6
|
+
const module_js_1 = require("./module.js");
|
|
5
7
|
class CookieFlagCheck {
|
|
6
8
|
constructor(context, flag) {
|
|
7
9
|
this.context = context;
|
|
@@ -13,7 +15,7 @@ class CookieFlagCheck {
|
|
|
13
15
|
this.checkSensitiveCookieArgument(callExpression, 0);
|
|
14
16
|
}
|
|
15
17
|
checkCookiesMethodCall(callExpression) {
|
|
16
|
-
if (!(0,
|
|
18
|
+
if (!(0, ast_js_1.isIdentifier)(callExpression.callee.property, 'set')) {
|
|
17
19
|
return;
|
|
18
20
|
}
|
|
19
21
|
// Sensitive argument is third argument for "cookies.set" calls
|
|
@@ -25,12 +27,12 @@ class CookieFlagCheck {
|
|
|
25
27
|
if (cookieProperty) {
|
|
26
28
|
// csurf cookie property can be passed as a boolean literal,
|
|
27
29
|
// in which case neither "secure" nor "httponly" are enabled by default
|
|
28
|
-
const cookiePropertyLiteral = (0,
|
|
30
|
+
const cookiePropertyLiteral = (0, ast_js_1.getValueOfExpression)(this.context, cookieProperty.value, 'Literal');
|
|
29
31
|
if (cookiePropertyLiteral?.value === true) {
|
|
30
|
-
(0,
|
|
32
|
+
(0, location_js_1.report)(this.context, {
|
|
31
33
|
node: callExpression.callee,
|
|
32
34
|
message: this.issueMessage,
|
|
33
|
-
}, [(0,
|
|
35
|
+
}, [(0, location_js_1.toSecondaryLocation)(cookiePropertyLiteral)]);
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -43,7 +45,7 @@ class CookieFlagCheck {
|
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
47
|
const sensitiveArgument = callExpression.arguments[sensitiveArgumentIndex];
|
|
46
|
-
const cookieObjectExpression = (0,
|
|
48
|
+
const cookieObjectExpression = (0, ast_js_1.getValueOfExpression)(this.context, sensitiveArgument, 'ObjectExpression');
|
|
47
49
|
if (!cookieObjectExpression) {
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
@@ -54,15 +56,15 @@ class CookieFlagCheck {
|
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
58
|
const firstArgument = callExpression.arguments[argumentIndex];
|
|
57
|
-
const objectExpression = (0,
|
|
59
|
+
const objectExpression = (0, ast_js_1.getValueOfExpression)(this.context, firstArgument, 'ObjectExpression');
|
|
58
60
|
if (!objectExpression) {
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
|
-
const cookieProperty = (0,
|
|
63
|
+
const cookieProperty = (0, ast_js_1.getProperty)(objectExpression, 'cookie', this.context);
|
|
62
64
|
if (!cookieProperty) {
|
|
63
65
|
return;
|
|
64
66
|
}
|
|
65
|
-
const cookiePropertyValue = (0,
|
|
67
|
+
const cookiePropertyValue = (0, ast_js_1.getValueOfExpression)(this.context, cookieProperty.value, 'ObjectExpression');
|
|
66
68
|
if (cookiePropertyValue) {
|
|
67
69
|
this.checkFlagOnCookieExpression(cookiePropertyValue, firstArgument, objectExpression, callExpression);
|
|
68
70
|
return;
|
|
@@ -70,15 +72,15 @@ class CookieFlagCheck {
|
|
|
70
72
|
return cookieProperty;
|
|
71
73
|
}
|
|
72
74
|
checkFlagOnCookieExpression(cookiePropertyValue, firstArgument, objectExpression, callExpression) {
|
|
73
|
-
const flagProperty = (0,
|
|
75
|
+
const flagProperty = (0, ast_js_1.getProperty)(cookiePropertyValue, this.flag, this.context);
|
|
74
76
|
if (flagProperty) {
|
|
75
|
-
const flagPropertyValue = (0,
|
|
77
|
+
const flagPropertyValue = (0, ast_js_1.getValueOfExpression)(this.context, flagProperty.value, 'Literal');
|
|
76
78
|
if (flagPropertyValue?.value === false) {
|
|
77
|
-
const secondaryLocations = [(0,
|
|
79
|
+
const secondaryLocations = [(0, location_js_1.toSecondaryLocation)(flagPropertyValue)];
|
|
78
80
|
if (firstArgument !== objectExpression) {
|
|
79
|
-
secondaryLocations.push((0,
|
|
81
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)(objectExpression));
|
|
80
82
|
}
|
|
81
|
-
(0,
|
|
83
|
+
(0, location_js_1.report)(this.context, {
|
|
82
84
|
node: callExpression.callee,
|
|
83
85
|
message: this.issueMessage,
|
|
84
86
|
}, secondaryLocations);
|
|
@@ -88,7 +90,7 @@ class CookieFlagCheck {
|
|
|
88
90
|
checkCookiesFromCallExpression(node) {
|
|
89
91
|
const callExpression = node;
|
|
90
92
|
const { callee } = callExpression;
|
|
91
|
-
const fqn = (0,
|
|
93
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(this.context, callee);
|
|
92
94
|
if (fqn === 'cookie-session') {
|
|
93
95
|
this.checkCookieSession(callExpression);
|
|
94
96
|
return;
|
|
@@ -102,8 +104,8 @@ class CookieFlagCheck {
|
|
|
102
104
|
return;
|
|
103
105
|
}
|
|
104
106
|
if (callee.type === 'MemberExpression') {
|
|
105
|
-
const objectValue = (0,
|
|
106
|
-
if (objectValue && (0,
|
|
107
|
+
const objectValue = (0, ast_js_1.getValueOfExpression)(this.context, callee.object, 'NewExpression');
|
|
108
|
+
if (objectValue && (0, module_js_1.getFullyQualifiedName)(this.context, objectValue.callee) === 'cookies') {
|
|
107
109
|
this.checkCookiesMethodCall(callExpression);
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
2
|
/*
|
|
18
3
|
* SonarQube JavaScript Plugin
|
|
19
4
|
* Copyright (C) 2011-2025 SonarSource Sàrl
|
|
@@ -30,5 +15,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
15
|
* You should have received a copy of the Sonar Source-Available License
|
|
31
16
|
* along with this program; if not, see https://sonarsource.com/license/ssal/
|
|
32
17
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.shannonEntropy = shannonEntropy;
|
|
20
|
+
function shannonEntropy(str) {
|
|
21
|
+
if (!str) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
const len = str.length;
|
|
25
|
+
const occurrences = {};
|
|
26
|
+
for (const ch of str) {
|
|
27
|
+
occurrences[ch] = (occurrences[ch] ?? 0) + 1;
|
|
28
|
+
}
|
|
29
|
+
return (Object.values(occurrences)
|
|
30
|
+
.map(count => count / len)
|
|
31
|
+
.map(freq => -freq * Math.log(freq))
|
|
32
|
+
.reduce((acc, e) => acc + e, 0) / Math.log(2));
|
|
33
|
+
}
|
package/cjs/helpers/express.js
CHANGED
|
@@ -1,144 +1,143 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.attemptFindAppInstantiation = attemptFindAppInstantiation;
|
|
4
|
+
exports.attemptFindAppInjection = attemptFindAppInjection;
|
|
5
|
+
exports.isUsingMiddleware = isUsingMiddleware;
|
|
6
|
+
exports.isMiddlewareInstance = isMiddlewareInstance;
|
|
7
|
+
exports.SensitiveMiddlewarePropertyRule = SensitiveMiddlewarePropertyRule;
|
|
8
|
+
const module_js_1 = require("./module.js");
|
|
9
|
+
const ast_js_1 = require("./ast.js");
|
|
10
|
+
const ancestor_js_1 = require("./ancestor.js");
|
|
11
|
+
const location_js_1 = require("./location.js");
|
|
5
12
|
/**
|
|
6
13
|
* This modules provides utilities for writing rules about Express.js.
|
|
7
14
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const pattern = varDecl.id;
|
|
19
|
-
return pattern.type === 'Identifier' ? pattern : undefined;
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
15
|
+
const EXPRESS = 'express';
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether the declaration looks somewhat like `<id> = express()`
|
|
18
|
+
* and returns `<id>` if it matches.
|
|
19
|
+
*/
|
|
20
|
+
function attemptFindAppInstantiation(varDecl, context) {
|
|
21
|
+
const rhs = varDecl.init;
|
|
22
|
+
if (rhs?.type === 'CallExpression' && (0, module_js_1.getFullyQualifiedName)(context, rhs) === EXPRESS) {
|
|
23
|
+
const pattern = varDecl.id;
|
|
24
|
+
return pattern.type === 'Identifier' ? pattern : undefined;
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether the function injects an instantiated app and is exported like `module.exports = function(app) {}`
|
|
30
|
+
* or `module.exports.property = function(app) {}`, and returns app if it matches.
|
|
31
|
+
*/
|
|
32
|
+
function attemptFindAppInjection(functionDef, context, node) {
|
|
33
|
+
const app = functionDef.params.find(param => param.type === 'Identifier' && param.name === 'app');
|
|
34
|
+
if (app) {
|
|
35
|
+
const parent = (0, ancestor_js_1.getParent)(context, node);
|
|
36
|
+
if (parent?.type === 'AssignmentExpression') {
|
|
37
|
+
const { left } = parent;
|
|
38
|
+
if (left.type === 'MemberExpression' &&
|
|
39
|
+
((0, ast_js_1.isModuleExports)(left) || (0, ast_js_1.isModuleExports)(left.object))) {
|
|
40
|
+
return app;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
return undefined;
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return false;
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Checks whether the expression looks somewhat like `app.use(m1, [m2, m3], ..., mN)`,
|
|
48
|
+
* where one of `mK`-nodes satisfies the given predicate.
|
|
49
|
+
*/
|
|
50
|
+
function isUsingMiddleware(context, callExpression, app, middlewareNodePredicate) {
|
|
51
|
+
if ((0, ast_js_1.isMethodInvocation)(callExpression, app.name, 'use', 1)) {
|
|
52
|
+
const flattenedArgs = (0, ast_js_1.flattenArgs)(context, callExpression.arguments);
|
|
53
|
+
return flattenedArgs.some(middlewareNodePredicate);
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return false;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks whether a node looks somewhat like `require('m')()` for
|
|
59
|
+
* some middleware `m` from the list of middlewares.
|
|
60
|
+
*/
|
|
61
|
+
function isMiddlewareInstance(context, middlewares, n) {
|
|
62
|
+
if (n.type === 'CallExpression') {
|
|
63
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, n);
|
|
64
|
+
return fqn !== null && middlewares.includes(fqn);
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return [];
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Rule factory for detecting sensitive settings that are passed to
|
|
70
|
+
* middlewares eventually used by Express.js applications:
|
|
71
|
+
*
|
|
72
|
+
* app.use(
|
|
73
|
+
* middleware(settings)
|
|
74
|
+
* )
|
|
75
|
+
*
|
|
76
|
+
* or
|
|
77
|
+
*
|
|
78
|
+
* app.use(
|
|
79
|
+
* middleware.method(settings)
|
|
80
|
+
* )
|
|
81
|
+
*
|
|
82
|
+
* @param sensitivePropertyFinder - a function looking for a sensitive setting on a middleware call
|
|
83
|
+
* @param message - the reported message when an issue is raised
|
|
84
|
+
* @param meta - the rule metadata
|
|
85
|
+
* @returns a rule module that raises issues when a sensitive property is found
|
|
86
|
+
*/
|
|
87
|
+
function SensitiveMiddlewarePropertyRule(sensitivePropertyFinder, message, meta = {}) {
|
|
88
|
+
return {
|
|
89
|
+
meta,
|
|
90
|
+
create(context) {
|
|
91
|
+
let app;
|
|
92
|
+
let sensitiveProperties;
|
|
93
|
+
function isExposing(middlewareNode) {
|
|
94
|
+
return Boolean(sensitiveProperties.push(...findSensitiveProperty(middlewareNode)));
|
|
95
|
+
}
|
|
96
|
+
function findSensitiveProperty(middlewareNode) {
|
|
97
|
+
if (middlewareNode.type === 'CallExpression') {
|
|
98
|
+
return sensitivePropertyFinder(context, middlewareNode);
|
|
100
99
|
}
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
Program: () => {
|
|
104
|
+
app = null;
|
|
105
|
+
sensitiveProperties = [];
|
|
106
|
+
},
|
|
107
|
+
CallExpression: (node) => {
|
|
108
|
+
if (app) {
|
|
109
|
+
const callExpr = node;
|
|
110
|
+
const isSafe = !isUsingMiddleware(context, callExpr, app, isExposing);
|
|
111
|
+
if (!isSafe) {
|
|
112
|
+
for (const sensitive of sensitiveProperties) {
|
|
113
|
+
(0, location_js_1.report)(context, {
|
|
114
|
+
node: callExpr,
|
|
115
|
+
message,
|
|
116
|
+
}, [(0, location_js_1.toSecondaryLocation)(sensitive)]);
|
|
118
117
|
}
|
|
118
|
+
sensitiveProperties = [];
|
|
119
119
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
VariableDeclarator: (node) => {
|
|
123
|
+
if (!app) {
|
|
124
|
+
const varDecl = node;
|
|
125
|
+
const instantiatedApp = attemptFindAppInstantiation(varDecl, context);
|
|
126
|
+
if (instantiatedApp) {
|
|
127
|
+
app = instantiatedApp;
|
|
128
128
|
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
':function': (node) => {
|
|
132
|
+
if (!app) {
|
|
133
|
+
const functionDef = node;
|
|
134
|
+
const injectedApp = attemptFindAppInjection(functionDef, context, node);
|
|
135
|
+
if (injectedApp) {
|
|
136
|
+
app = injectedApp;
|
|
137
137
|
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
})(Express || (exports.Express = Express = {}));
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|