@interlace/eslint-devkit 1.7.0 → 1.8.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.
- package/README.md +8 -0
- package/package.json +1 -2
- package/src/ast/index.js +15 -2
- package/src/index.js +22 -9
- package/src/messaging/index.js +19 -6
- package/src/node/fs.js +34 -2
- package/src/node/index.js +17 -4
- package/src/node/os.js +34 -2
- package/src/node/path.js +34 -2
- package/src/resolver/index.js +18 -5
- package/src/resolver.js +15 -2
- package/src/rule-creation/index.d.ts +1 -0
- package/src/rule-creation/index.js +19 -5
- package/src/rule-creation/require-tls-rule.d.ts +113 -0
- package/src/rule-creation/require-tls-rule.js +190 -0
- package/src/rule-creation/sql-injection-rule.d.ts +4 -3
- package/src/rule-creation/sql-injection-rule.js +96 -5
- package/src/security/index.js +15 -2
- package/src/types/index.js +15 -2
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-devkit" target="blank"><img src="https://eslint.interlace.tools/logos/interlace.svg" alt="Interlace" height="90" /></a>
|
|
3
|
+
|
|
4
|
+
<a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/logos/oxlint.svg" alt="oxlint" height="90" /></a>
|
|
5
|
+
|
|
6
|
+
<a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/logos/eslint.svg" alt="ESLint" height="90" /></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
1
9
|
# @interlace/eslint-devkit
|
|
2
10
|
|
|
3
11
|
**Build ESLint plugins that write themselves** - TypeScript utilities for creating rules that AI assistants can understand and auto-fix.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interlace/eslint-devkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -68,7 +68,6 @@
|
|
|
68
68
|
"@typescript-eslint/utils": "^7.0.0 || ^8.0.0",
|
|
69
69
|
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
70
70
|
"oxc-resolver": "^11.24.2",
|
|
71
|
-
"tslib": "^2.3.0",
|
|
72
71
|
"typescript": ">=4.8.4"
|
|
73
72
|
},
|
|
74
73
|
"peerDependenciesMeta": {
|
package/src/ast/index.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("../ast/ast-utils"), exports);
|
|
17
|
+
__exportStar(require("../ast/ast-utils"), exports);
|
package/src/index.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.ESLintUtils = exports.AST_NODE_TYPES = exports.toSARIF = exports.severityToCVSS = exports.getSecurityBenchmarks = exports.MessageIcons = exports.OWASP_2021_TO_2025 = exports.OWASP_SERVERLESS_DETAILS = exports.OWASP_2021_DETAILS = exports.OWASP_2025_DETAILS = exports.OWASP_DETAILS = exports.CWE_COMPLIANCE_MAPPING = exports.CWE_MAPPING = exports.CVSS_RANGES = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
18
|
require("./types/meta-augmentation");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
__exportStar(require("./rule-creation"), exports);
|
|
20
|
+
__exportStar(require("./ast/ast-utils"), exports);
|
|
21
|
+
__exportStar(require("./types/type-utils"), exports);
|
|
22
|
+
__exportStar(require("./messaging"), exports);
|
|
23
|
+
__exportStar(require("./security"), exports);
|
|
24
|
+
__exportStar(require("./node"), exports);
|
|
25
|
+
__exportStar(require("./resolver"), exports);
|
|
26
|
+
__exportStar(require("./aria-definitions"), exports);
|
|
14
27
|
var messaging_1 = require("./messaging");
|
|
15
28
|
Object.defineProperty(exports, "CVSS_RANGES", { enumerable: true, get: function () { return messaging_1.CVSS_RANGES; } });
|
|
16
29
|
Object.defineProperty(exports, "CWE_MAPPING", { enumerable: true, get: function () { return messaging_1.CWE_MAPPING; } });
|
package/src/messaging/index.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tslib_1.__exportStar(require("./formatters-ai"), exports);
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./formatters"), exports);
|
|
20
|
+
__exportStar(require("./config"), exports);
|
|
21
|
+
__exportStar(require("./formatters-ai"), exports);
|
package/src/node/fs.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.fileExistsSync = fileExistsSync;
|
|
4
37
|
exports.readFileSync = readFileSync;
|
|
@@ -7,8 +40,7 @@ exports.statSync = statSync;
|
|
|
7
40
|
exports.mkdirSync = mkdirSync;
|
|
8
41
|
exports.writeFileSync = writeFileSync;
|
|
9
42
|
exports.findFileUpward = findFileUpward;
|
|
10
|
-
const
|
|
11
|
-
const fs = tslib_1.__importStar(require("node:fs"));
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
12
44
|
const path_1 = require("./path");
|
|
13
45
|
function fileExistsSync(filePath) {
|
|
14
46
|
return fs.existsSync(filePath);
|
package/src/node/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
tslib_1.__exportStar(require("./path"), exports);
|
|
17
|
+
__exportStar(require("./fs"), exports);
|
|
18
|
+
__exportStar(require("./os"), exports);
|
|
19
|
+
__exportStar(require("./path"), exports);
|
package/src/node/os.js
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.getEOL = getEOL;
|
|
4
37
|
exports.getPlatform = getPlatform;
|
|
5
38
|
exports.getArch = getArch;
|
|
6
39
|
exports.getTmpDir = getTmpDir;
|
|
7
|
-
const
|
|
8
|
-
const os = tslib_1.__importStar(require("node:os"));
|
|
40
|
+
const os = __importStar(require("node:os"));
|
|
9
41
|
function getEOL() {
|
|
10
42
|
return os.EOL;
|
|
11
43
|
}
|
package/src/node/path.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.createPatternCache = createPatternCache;
|
|
4
37
|
exports.patternToRegex = patternToRegex;
|
|
@@ -14,8 +47,7 @@ exports.normalizePath = normalizePath;
|
|
|
14
47
|
exports.joinPath = joinPath;
|
|
15
48
|
exports.resolvePath = resolvePath;
|
|
16
49
|
exports.getExtname = getExtname;
|
|
17
|
-
const
|
|
18
|
-
const path = tslib_1.__importStar(require("node:path"));
|
|
50
|
+
const path = __importStar(require("node:path"));
|
|
19
51
|
function createPatternCache() {
|
|
20
52
|
return new Map();
|
|
21
53
|
}
|
package/src/resolver/index.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
tslib_1.__exportStar(require("./resolver-detection"), exports);
|
|
17
|
+
__exportStar(require("./resolver"), exports);
|
|
18
|
+
__exportStar(require("./resolver-adapter"), exports);
|
|
19
|
+
__exportStar(require("./dependency-analysis"), exports);
|
|
20
|
+
__exportStar(require("./resolver-detection"), exports);
|
package/src/resolver.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./resolver/index"), exports);
|
|
17
|
+
__exportStar(require("./resolver/index"), exports);
|
|
@@ -1,7 +1,21 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
17
|
+
__exportStar(require("./rule-creator"), exports);
|
|
18
|
+
__exportStar(require("./mock-context"), exports);
|
|
19
|
+
__exportStar(require("./sql-injection-rule"), exports);
|
|
20
|
+
__exportStar(require("./unscoped-mutation-rule"), exports);
|
|
21
|
+
__exportStar(require("./require-tls-rule"), exports);
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
7
|
+
/** Message ids every rule built by this factory reports. */
|
|
8
|
+
export type RequireTlsMessageIds = 'tlsDisabled' | 'certificateValidationDisabled';
|
|
9
|
+
export interface RequireTlsRuleConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The rule's own `meta.type` + `meta.docs`, spelled out by the caller.
|
|
12
|
+
* Same reasoning as `createUnscopedMutationRule`: the metadata auditor
|
|
13
|
+
* statically parses each rule's source file, so metadata hidden inside a
|
|
14
|
+
* factory is invisible to it.
|
|
15
|
+
*/
|
|
16
|
+
readonly meta: {
|
|
17
|
+
readonly type: 'problem';
|
|
18
|
+
readonly docs: {
|
|
19
|
+
readonly description: string;
|
|
20
|
+
readonly url: string;
|
|
21
|
+
readonly cwe: string;
|
|
22
|
+
/**
|
|
23
|
+
* Secondary-mapping note. `cwe` holds one identifier, but this rule
|
|
24
|
+
* reports two weaknesses — `tlsDisabled` is CWE-319 and
|
|
25
|
+
* `certificateValidationDisabled` is CWE-295 — so the second one is
|
|
26
|
+
* recorded here, where `scripts/docs-cwe-coverage.ts` reads it.
|
|
27
|
+
*/
|
|
28
|
+
readonly cweJustification?: string;
|
|
29
|
+
readonly cvss: number;
|
|
30
|
+
readonly confidence: 'high' | 'medium' | 'low';
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Modules whose import means this file talks to the driver, e.g.
|
|
35
|
+
* `['mysql2', 'mysql']`. A file importing none of them is skipped entirely,
|
|
36
|
+
* which is what keeps this rule out of `node-security`'s territory.
|
|
37
|
+
*/
|
|
38
|
+
readonly modules: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* Extra keys, on top of the shared defaults, that identify an object as a
|
|
41
|
+
* connection config for this driver — Sequelize's `dialectOptions`,
|
|
42
|
+
* TypeORM's `synchronize`, and so on.
|
|
43
|
+
*/
|
|
44
|
+
readonly connectionKeys?: readonly string[];
|
|
45
|
+
/**
|
|
46
|
+
* URL schemes this driver accepts in a connection string, e.g.
|
|
47
|
+
* `['mysql']`. A string literal starting with one of them is scanned for
|
|
48
|
+
* `sslmode=disable` / `ssl=false`. Omit for drivers that take no URL.
|
|
49
|
+
*/
|
|
50
|
+
readonly urlSchemes?: readonly string[];
|
|
51
|
+
/** Remediation line in the emitted message. */
|
|
52
|
+
readonly fix: string;
|
|
53
|
+
/** Reference link in the emitted message. */
|
|
54
|
+
readonly documentationLink: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Is this property value the literal `false` (or another falsy literal)?
|
|
58
|
+
*
|
|
59
|
+
* Only a *readable* literal counts. `ssl: enableSsl` is a variable this rule
|
|
60
|
+
* cannot resolve, and guessing there is how a security rule earns a
|
|
61
|
+
* false-positive reputation — it stays silent instead.
|
|
62
|
+
*
|
|
63
|
+
* `trustServerCertificate` inverts the sense: it is dangerous when TRUE. Callers
|
|
64
|
+
* pass `expect` to say which polarity they mean.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isLiteralBoolean(value: TSESTree.Node, expect: boolean): boolean;
|
|
67
|
+
/** Does this object literal carry at least one connection-identifying key? */
|
|
68
|
+
export declare function looksLikeConnectionConfig(obj: TSESTree.ObjectExpression, connectionKeys: readonly string[]): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* A connection string that explicitly turns TLS off.
|
|
71
|
+
*
|
|
72
|
+
* Anchored on the scheme so a random sentence containing `sslmode=disable`
|
|
73
|
+
* (a doc comment, an error message) is not a finding, and matched with a word
|
|
74
|
+
* boundary so `sslmode=disabled-for-now` — not a real libpq value — does not
|
|
75
|
+
* silently pass either.
|
|
76
|
+
*
|
|
77
|
+
* The fragment is cut off before the scan, because a URL fragment ends the
|
|
78
|
+
* query string. It has to be cut on both sides of the finding:
|
|
79
|
+
*
|
|
80
|
+
* - `?sslmode=disable#frag` — the fragment ends a real parameter, so this is
|
|
81
|
+
* a finding. Terminating on `&` alone made it a silent false negative.
|
|
82
|
+
* - `#?sslmode=disable` — the text sits *inside* the fragment, which no
|
|
83
|
+
* driver parses as a connection option, so this is not a finding.
|
|
84
|
+
*/
|
|
85
|
+
export declare function urlDisablesTls(value: string, schemes: readonly string[]): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Is this string literal actually being used as a connection string?
|
|
88
|
+
*
|
|
89
|
+
* The object path earns its low false-positive rate by requiring a
|
|
90
|
+
* connection-shaped neighbour before a TLS key counts. The URL path needs the
|
|
91
|
+
* same discipline: a `mysql://…?sslmode=disable` string is only a finding where
|
|
92
|
+
* a driver would read it. Two positions qualify —
|
|
93
|
+
*
|
|
94
|
+
* - a connection-named property: `{ connection: 'postgres://…' }`,
|
|
95
|
+
* `{ url: '…' }`, `{ uri: '…' }`
|
|
96
|
+
* - an argument to a call on a driver binding:
|
|
97
|
+
* `mysql.createConnection('mysql://…')`, `new Sequelize('postgres://…')`
|
|
98
|
+
*
|
|
99
|
+
* Deliberately NOT qualifying: a bare `const dsn = 'mysql://…'`. It is
|
|
100
|
+
* indistinguishable from a fixture, a doc example, or an error-message
|
|
101
|
+
* template, and reporting it is the exact false positive that makes a security
|
|
102
|
+
* plugin the one users switch off. The cost is a false negative when the DSN is
|
|
103
|
+
* built in one statement and passed in another.
|
|
104
|
+
*/
|
|
105
|
+
export declare function inConnectionPosition(node: TSESTree.Literal, connectionKeys: readonly string[], bindings: ReadonlySet<string>): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Build a CWE-319 rule for the given driver.
|
|
108
|
+
*
|
|
109
|
+
* Reports a config object only when a TLS key is explicitly disabled with a
|
|
110
|
+
* readable literal AND the object reads as a connection config. An unreadable
|
|
111
|
+
* value is a deliberate false negative.
|
|
112
|
+
*/
|
|
113
|
+
export declare function createRequireTlsRule(config: RequireTlsRuleConfig): TSESLint.RuleModule<RequireTlsMessageIds, []>;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLiteralBoolean = isLiteralBoolean;
|
|
4
|
+
exports.looksLikeConnectionConfig = looksLikeConnectionConfig;
|
|
5
|
+
exports.urlDisablesTls = urlDisablesTls;
|
|
6
|
+
exports.inConnectionPosition = inConnectionPosition;
|
|
7
|
+
exports.createRequireTlsRule = createRequireTlsRule;
|
|
8
|
+
const ast_node_types_1 = require("../ast-node-types");
|
|
9
|
+
const messaging_1 = require("../messaging");
|
|
10
|
+
const unscoped_mutation_rule_1 = require("./unscoped-mutation-rule");
|
|
11
|
+
const DEFAULT_CONNECTION_KEYS = [
|
|
12
|
+
'host',
|
|
13
|
+
'hostname',
|
|
14
|
+
'port',
|
|
15
|
+
'user',
|
|
16
|
+
'username',
|
|
17
|
+
'password',
|
|
18
|
+
'database',
|
|
19
|
+
'connectionString',
|
|
20
|
+
'socketPath',
|
|
21
|
+
'uri',
|
|
22
|
+
'url',
|
|
23
|
+
'connection',
|
|
24
|
+
'pool',
|
|
25
|
+
'schema',
|
|
26
|
+
];
|
|
27
|
+
const TLS_OFF_KEYS = ['ssl', 'secure', 'tls', 'encrypt', 'useSSL', 'requireSSL'];
|
|
28
|
+
const VERIFY_OFF_KEYS = [
|
|
29
|
+
'rejectUnauthorized',
|
|
30
|
+
'verifyServerCertificate',
|
|
31
|
+
'checkServerIdentity',
|
|
32
|
+
'trustServerCertificate',
|
|
33
|
+
];
|
|
34
|
+
function isLiteralBoolean(value, expect) {
|
|
35
|
+
if (value.type !== ast_node_types_1.AST_NODE_TYPES.Literal)
|
|
36
|
+
return false;
|
|
37
|
+
if (typeof value.value !== 'boolean') {
|
|
38
|
+
return expect === false && !value.value;
|
|
39
|
+
}
|
|
40
|
+
return value.value === expect;
|
|
41
|
+
}
|
|
42
|
+
function looksLikeConnectionConfig(obj, connectionKeys) {
|
|
43
|
+
return obj.properties.some((prop) => {
|
|
44
|
+
const name = (0, unscoped_mutation_rule_1.propertyKeyName)(prop);
|
|
45
|
+
return name !== undefined && connectionKeys.includes(name);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function urlDisablesTls(value, schemes) {
|
|
49
|
+
if (!schemes.some((scheme) => value.startsWith(`${scheme}://`)))
|
|
50
|
+
return false;
|
|
51
|
+
const query = value.split('#')[0];
|
|
52
|
+
return /[?&](?:sslmode=disable|ssl=(?:false|0))(?:&|$)/i.test(query);
|
|
53
|
+
}
|
|
54
|
+
function inConnectionPosition(node, connectionKeys, bindings) {
|
|
55
|
+
const parent = node.parent;
|
|
56
|
+
if (!parent)
|
|
57
|
+
return false;
|
|
58
|
+
if (parent.type === ast_node_types_1.AST_NODE_TYPES.Property && parent.value === node) {
|
|
59
|
+
const name = (0, unscoped_mutation_rule_1.propertyKeyName)(parent);
|
|
60
|
+
return name !== undefined && connectionKeys.includes(name);
|
|
61
|
+
}
|
|
62
|
+
if (parent.type === ast_node_types_1.AST_NODE_TYPES.CallExpression ||
|
|
63
|
+
parent.type === ast_node_types_1.AST_NODE_TYPES.NewExpression) {
|
|
64
|
+
if (!parent.arguments.includes(node))
|
|
65
|
+
return false;
|
|
66
|
+
return calleeBaseIsDriver(parent.callee, bindings);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
function calleeBaseIsDriver(callee, bindings) {
|
|
71
|
+
let cursor = callee;
|
|
72
|
+
for (;;) {
|
|
73
|
+
if (cursor.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression) {
|
|
74
|
+
cursor = cursor.object;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (cursor.type === ast_node_types_1.AST_NODE_TYPES.CallExpression) {
|
|
78
|
+
cursor = cursor.callee;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
return cursor.type === ast_node_types_1.AST_NODE_TYPES.Identifier && bindings.has(cursor.name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function createRequireTlsRule(config) {
|
|
85
|
+
const connectionKeys = [...DEFAULT_CONNECTION_KEYS, ...(config.connectionKeys ?? [])];
|
|
86
|
+
const urlSchemes = config.urlSchemes ?? [];
|
|
87
|
+
return {
|
|
88
|
+
meta: {
|
|
89
|
+
type: config.meta.type,
|
|
90
|
+
docs: { ...config.meta.docs },
|
|
91
|
+
messages: {
|
|
92
|
+
tlsDisabled: (0, messaging_1.formatLLMMessage)({
|
|
93
|
+
icon: messaging_1.MessageIcons.SECURITY,
|
|
94
|
+
issueName: 'Cleartext Database Connection',
|
|
95
|
+
description: 'TLS is explicitly disabled on this database connection. Queries, result rows and the credentials that open the session all cross the network in cleartext.',
|
|
96
|
+
severity: 'HIGH',
|
|
97
|
+
cwe: config.meta.docs.cwe,
|
|
98
|
+
owasp: 'A02:2021',
|
|
99
|
+
compliance: ['SOC2', 'PCI-DSS', 'HIPAA', 'NIST-CSF'],
|
|
100
|
+
effort: 'low',
|
|
101
|
+
fix: config.fix,
|
|
102
|
+
documentationLink: config.documentationLink,
|
|
103
|
+
}),
|
|
104
|
+
certificateValidationDisabled: (0, messaging_1.formatLLMMessage)({
|
|
105
|
+
icon: messaging_1.MessageIcons.SECURITY,
|
|
106
|
+
issueName: 'Unverified Database TLS Peer',
|
|
107
|
+
description: 'Certificate validation is disabled on this database connection. The traffic is encrypted but the server is never authenticated, so it encrypts just as willingly to whoever answered in its place.',
|
|
108
|
+
severity: 'HIGH',
|
|
109
|
+
cwe: config.meta.docs.cwe,
|
|
110
|
+
owasp: 'A02:2021',
|
|
111
|
+
compliance: ['SOC2', 'PCI-DSS', 'HIPAA', 'NIST-CSF'],
|
|
112
|
+
effort: 'medium',
|
|
113
|
+
fix: 'Supply the server CA instead of switching verification off — `ssl: { ca: fs.readFileSync(caPath) }`. If the certificate is self-signed, add that CA to the trust store rather than trusting everything.',
|
|
114
|
+
documentationLink: config.documentationLink,
|
|
115
|
+
}),
|
|
116
|
+
},
|
|
117
|
+
schema: [],
|
|
118
|
+
},
|
|
119
|
+
defaultOptions: [],
|
|
120
|
+
create(context) {
|
|
121
|
+
let bindings = new Set();
|
|
122
|
+
let reported = new WeakSet();
|
|
123
|
+
const report = (prop, messageId) => {
|
|
124
|
+
if (reported.has(prop))
|
|
125
|
+
return;
|
|
126
|
+
reported.add(prop);
|
|
127
|
+
context.report({ node: prop, messageId });
|
|
128
|
+
};
|
|
129
|
+
const reportVerifyOffProperty = (prop, name) => {
|
|
130
|
+
if (!VERIFY_OFF_KEYS.includes(name))
|
|
131
|
+
return;
|
|
132
|
+
const inverted = name === 'trustServerCertificate';
|
|
133
|
+
if (!isLiteralBoolean(prop.value, inverted))
|
|
134
|
+
return;
|
|
135
|
+
report(prop, 'certificateValidationDisabled');
|
|
136
|
+
};
|
|
137
|
+
const scanTlsKeys = (obj) => {
|
|
138
|
+
for (const prop of obj.properties) {
|
|
139
|
+
if (prop.type !== ast_node_types_1.AST_NODE_TYPES.Property)
|
|
140
|
+
continue;
|
|
141
|
+
const name = (0, unscoped_mutation_rule_1.propertyKeyName)(prop);
|
|
142
|
+
if (name === undefined)
|
|
143
|
+
continue;
|
|
144
|
+
if (TLS_OFF_KEYS.includes(name)) {
|
|
145
|
+
if (isLiteralBoolean(prop.value, false)) {
|
|
146
|
+
report(prop, 'tlsDisabled');
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (prop.value.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression) {
|
|
150
|
+
scanTlsKeys(prop.value);
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
reportVerifyOffProperty(prop, name);
|
|
155
|
+
if (prop.value.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression &&
|
|
156
|
+
connectionKeys.includes(name)) {
|
|
157
|
+
scanTlsKeys(prop.value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const checkObject = (obj) => {
|
|
162
|
+
if (!looksLikeConnectionConfig(obj, connectionKeys))
|
|
163
|
+
return;
|
|
164
|
+
scanTlsKeys(obj);
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
Program(program) {
|
|
168
|
+
bindings = (0, unscoped_mutation_rule_1.driverBindings)(program, config.modules);
|
|
169
|
+
reported = new WeakSet();
|
|
170
|
+
},
|
|
171
|
+
ObjectExpression(node) {
|
|
172
|
+
if (bindings.size === 0)
|
|
173
|
+
return;
|
|
174
|
+
checkObject(node);
|
|
175
|
+
},
|
|
176
|
+
Literal(node) {
|
|
177
|
+
if (bindings.size === 0)
|
|
178
|
+
return;
|
|
179
|
+
if (typeof node.value !== 'string')
|
|
180
|
+
return;
|
|
181
|
+
if (!urlDisablesTls(node.value, urlSchemes))
|
|
182
|
+
return;
|
|
183
|
+
if (!inConnectionPosition(node, connectionKeys, bindings))
|
|
184
|
+
return;
|
|
185
|
+
context.report({ node, messageId: 'tlsDisabled' });
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -43,8 +43,9 @@ export interface SqlInjectionRuleConfig {
|
|
|
43
43
|
/**
|
|
44
44
|
* Build a CWE-89 rule for the given sinks and remediation copy.
|
|
45
45
|
*
|
|
46
|
-
* Detects
|
|
47
|
-
* interpolation into a sink,
|
|
48
|
-
* `+=`) that is later passed to a sink
|
|
46
|
+
* Detects four shapes: direct concatenation into a sink, direct
|
|
47
|
+
* interpolation into a sink, a variable tainted by either (including via
|
|
48
|
+
* `+=`) that is later passed to a sink, and either of those passed to a
|
|
49
|
+
* same-file helper that forwards the argument into a sink.
|
|
49
50
|
*/
|
|
50
51
|
export declare function createSqlInjectionRule(config: SqlInjectionRuleConfig): TSESLint.RuleModule<SqlInjectionMessageIds, []>;
|
|
@@ -4,6 +4,34 @@ exports.createSqlInjectionRule = createSqlInjectionRule;
|
|
|
4
4
|
const ast_node_types_1 = require("../ast-node-types");
|
|
5
5
|
const messaging_1 = require("../messaging");
|
|
6
6
|
const SQL_KEYWORDS = /\b(?:select|insert|update|delete|drop|alter|truncate|union|from|where|values|set)\b/i;
|
|
7
|
+
const FUNCTION_TYPES = new Set([
|
|
8
|
+
ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration,
|
|
9
|
+
ast_node_types_1.AST_NODE_TYPES.FunctionExpression,
|
|
10
|
+
ast_node_types_1.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
11
|
+
]);
|
|
12
|
+
function enclosingFunction(node) {
|
|
13
|
+
for (let n = node.parent; n; n = n.parent) {
|
|
14
|
+
if (FUNCTION_TYPES.has(n.type))
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
function callableName(fn) {
|
|
20
|
+
if (fn.type === ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration && fn.id)
|
|
21
|
+
return fn.id.name;
|
|
22
|
+
const parent = fn.parent;
|
|
23
|
+
if (parent.type === ast_node_types_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
24
|
+
parent.id.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
|
|
25
|
+
return parent.id.name;
|
|
26
|
+
}
|
|
27
|
+
if ((parent.type === ast_node_types_1.AST_NODE_TYPES.MethodDefinition ||
|
|
28
|
+
parent.type === ast_node_types_1.AST_NODE_TYPES.PropertyDefinition ||
|
|
29
|
+
parent.type === ast_node_types_1.AST_NODE_TYPES.Property) &&
|
|
30
|
+
parent.key.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
|
|
31
|
+
return parent.key.name;
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
7
35
|
function staticText(node) {
|
|
8
36
|
if (node.type === ast_node_types_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
9
37
|
return node.quasis.map((q) => q.value.raw).join(' ');
|
|
@@ -21,7 +49,8 @@ function classify(node, requireSqlKeywords) {
|
|
|
21
49
|
if (node.type === ast_node_types_1.AST_NODE_TYPES.BinaryExpression && node.operator === '+') {
|
|
22
50
|
kind = 'concat';
|
|
23
51
|
}
|
|
24
|
-
if (node.type === ast_node_types_1.AST_NODE_TYPES.TemplateLiteral &&
|
|
52
|
+
if (node.type === ast_node_types_1.AST_NODE_TYPES.TemplateLiteral &&
|
|
53
|
+
node.expressions.length > 0) {
|
|
25
54
|
kind = 'template';
|
|
26
55
|
}
|
|
27
56
|
if (kind === false)
|
|
@@ -56,6 +85,10 @@ function createSqlInjectionRule(config) {
|
|
|
56
85
|
issueName: 'SQL Injection Risk',
|
|
57
86
|
description: 'Unsafe SQL query construction detected (template literal).',
|
|
58
87
|
severity: 'CRITICAL',
|
|
88
|
+
cwe: config.meta.docs.cwe,
|
|
89
|
+
owasp: 'A03:2021',
|
|
90
|
+
compliance: ['SOC2', 'PCI-DSS', 'NIST-CSF'],
|
|
91
|
+
effort: 'high',
|
|
59
92
|
fix: config.fix,
|
|
60
93
|
documentationLink: config.documentationLink,
|
|
61
94
|
}),
|
|
@@ -66,6 +99,10 @@ function createSqlInjectionRule(config) {
|
|
|
66
99
|
create(context) {
|
|
67
100
|
const tainted = new Map();
|
|
68
101
|
const sqlish = new Set();
|
|
102
|
+
const wrappers = new Map();
|
|
103
|
+
const definitions = new Map();
|
|
104
|
+
const wrapperFns = new Map();
|
|
105
|
+
const pending = [];
|
|
69
106
|
const report = (node, kind) => {
|
|
70
107
|
context.report({
|
|
71
108
|
node,
|
|
@@ -73,6 +110,11 @@ function createSqlInjectionRule(config) {
|
|
|
73
110
|
});
|
|
74
111
|
};
|
|
75
112
|
return {
|
|
113
|
+
'FunctionDeclaration, FunctionExpression, ArrowFunctionExpression'(node) {
|
|
114
|
+
const name = callableName(node);
|
|
115
|
+
if (name !== undefined)
|
|
116
|
+
definitions.set(name, (definitions.get(name) ?? 0) + 1);
|
|
117
|
+
},
|
|
76
118
|
VariableDeclarator(node) {
|
|
77
119
|
if (node.id.type === ast_node_types_1.AST_NODE_TYPES.Identifier && node.init) {
|
|
78
120
|
const kind = classify(node.init, config.requireSqlKeywords);
|
|
@@ -83,22 +125,52 @@ function createSqlInjectionRule(config) {
|
|
|
83
125
|
}
|
|
84
126
|
},
|
|
85
127
|
AssignmentExpression(node) {
|
|
86
|
-
if (node.operator === '+=' &&
|
|
128
|
+
if (node.operator === '+=' &&
|
|
129
|
+
node.left.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
|
|
87
130
|
const gate = config.requireSqlKeywords && !sqlish.has(node.left.name);
|
|
88
131
|
const kind = classify(node.right, gate);
|
|
89
132
|
if (kind)
|
|
90
133
|
tainted.set(node.left.name, kind);
|
|
134
|
+
if (SQL_KEYWORDS.test(staticText(node.right)))
|
|
135
|
+
sqlish.add(node.left.name);
|
|
91
136
|
}
|
|
92
137
|
},
|
|
93
138
|
CallExpression(node) {
|
|
94
|
-
|
|
95
|
-
node.callee.property.type
|
|
96
|
-
|
|
139
|
+
const isMember = node.callee.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression &&
|
|
140
|
+
node.callee.property.type === ast_node_types_1.AST_NODE_TYPES.Identifier;
|
|
141
|
+
const calleeName = isMember
|
|
142
|
+
? node.callee
|
|
143
|
+
.property.name
|
|
144
|
+
: node.callee.type === ast_node_types_1.AST_NODE_TYPES.Identifier
|
|
145
|
+
? node.callee.name
|
|
146
|
+
: undefined;
|
|
147
|
+
if (calleeName === undefined)
|
|
148
|
+
return;
|
|
149
|
+
if (!isMember || !sinks.has(calleeName)) {
|
|
150
|
+
for (const [index, arg] of node.arguments.entries()) {
|
|
151
|
+
if (arg.type === ast_node_types_1.AST_NODE_TYPES.SpreadElement)
|
|
152
|
+
continue;
|
|
153
|
+
const kind = classify(arg, true);
|
|
154
|
+
if (kind)
|
|
155
|
+
pending.push({ name: calleeName, index, arg, kind });
|
|
156
|
+
else if (arg.type === ast_node_types_1.AST_NODE_TYPES.Identifier)
|
|
157
|
+
pending.push({ name: calleeName, index, arg, kind: undefined });
|
|
158
|
+
}
|
|
97
159
|
return;
|
|
98
160
|
}
|
|
99
161
|
const queryArg = node.arguments[0];
|
|
100
162
|
if (!queryArg)
|
|
101
163
|
return;
|
|
164
|
+
if (queryArg.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
|
|
165
|
+
const fn = enclosingFunction(node);
|
|
166
|
+
const index = fn?.params.findIndex((p) => p.type === ast_node_types_1.AST_NODE_TYPES.Identifier &&
|
|
167
|
+
p.name === queryArg.name) ?? -1;
|
|
168
|
+
const name = fn && index >= 0 ? callableName(fn) : undefined;
|
|
169
|
+
if (name !== undefined && fn) {
|
|
170
|
+
wrappers.set(name, index);
|
|
171
|
+
wrapperFns.set(fn, name);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
102
174
|
const direct = classify(queryArg, config.requireSqlKeywords);
|
|
103
175
|
if (direct) {
|
|
104
176
|
report(queryArg, direct);
|
|
@@ -110,6 +182,25 @@ function createSqlInjectionRule(config) {
|
|
|
110
182
|
report(queryArg, taint);
|
|
111
183
|
}
|
|
112
184
|
},
|
|
185
|
+
'Program:exit'() {
|
|
186
|
+
const proven = new Map();
|
|
187
|
+
for (const name of wrapperFns.values())
|
|
188
|
+
proven.set(name, (proven.get(name) ?? 0) + 1);
|
|
189
|
+
for (const { name, index, arg, kind } of pending) {
|
|
190
|
+
if (wrappers.get(name) !== index)
|
|
191
|
+
continue;
|
|
192
|
+
if (definitions.get(name) !== proven.get(name))
|
|
193
|
+
continue;
|
|
194
|
+
if (kind) {
|
|
195
|
+
report(arg, kind);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const varName = arg.name;
|
|
199
|
+
const taint = tainted.get(varName);
|
|
200
|
+
if (taint && sqlish.has(varName))
|
|
201
|
+
report(arg, taint);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
113
204
|
};
|
|
114
205
|
},
|
|
115
206
|
};
|
package/src/security/index.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./security-utils"), exports);
|
|
17
|
+
__exportStar(require("./security-utils"), exports);
|
package/src/types/index.js
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./type-utils"), exports);
|
|
17
|
+
__exportStar(require("./type-utils"), exports);
|
|
5
18
|
require("./meta-augmentation");
|