@interlace/eslint-devkit 1.6.2 → 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 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
+ &nbsp;&nbsp;
4
+ <a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/logos/oxlint.svg" alt="oxlint" height="90" /></a>
5
+ &nbsp;&nbsp;
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.6.2",
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
- const tslib_1 = require("tslib");
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
- tslib_1.__exportStar(require("./rule-creation"), exports);
7
- tslib_1.__exportStar(require("./ast/ast-utils"), exports);
8
- tslib_1.__exportStar(require("./types/type-utils"), exports);
9
- tslib_1.__exportStar(require("./messaging"), exports);
10
- tslib_1.__exportStar(require("./security"), exports);
11
- tslib_1.__exportStar(require("./node"), exports);
12
- tslib_1.__exportStar(require("./resolver"), exports);
13
- tslib_1.__exportStar(require("./aria-definitions"), exports);
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; } });
@@ -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
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./types"), exports);
5
- tslib_1.__exportStar(require("./constants"), exports);
6
- tslib_1.__exportStar(require("./formatters"), exports);
7
- tslib_1.__exportStar(require("./config"), exports);
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 tslib_1 = require("tslib");
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
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./fs"), exports);
5
- tslib_1.__exportStar(require("./os"), exports);
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 tslib_1 = require("tslib");
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 tslib_1 = require("tslib");
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
  }
@@ -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
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./resolver"), exports);
5
- tslib_1.__exportStar(require("./resolver-adapter"), exports);
6
- tslib_1.__exportStar(require("./dependency-analysis"), exports);
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
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./resolver/index"), exports);
17
+ __exportStar(require("./resolver/index"), exports);
@@ -6,3 +6,5 @@
6
6
  export * from './rule-creator';
7
7
  export * from './mock-context';
8
8
  export * from './sql-injection-rule';
9
+ export * from './unscoped-mutation-rule';
10
+ export * from './require-tls-rule';
@@ -1,6 +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
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./rule-creator"), exports);
5
- tslib_1.__exportStar(require("./mock-context"), exports);
6
- tslib_1.__exportStar(require("./sql-injection-rule"), exports);
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 three shapes: direct concatenation into a sink, direct
47
- * interpolation into a sink, and a variable tainted by either (including via
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 && node.expressions.length > 0) {
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 === '+=' && node.left.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
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
- if (node.callee.type !== ast_node_types_1.AST_NODE_TYPES.MemberExpression ||
95
- node.callee.property.type !== ast_node_types_1.AST_NODE_TYPES.Identifier ||
96
- !sinks.has(node.callee.property.name)) {
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
  };
@@ -0,0 +1,158 @@
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 UnscopedMutationMessageIds = 'unscopedMutation' | 'explicitTruncate';
9
+ export interface UnscopedMutationRuleConfig {
10
+ /**
11
+ * The rule's own `meta.type` + `meta.docs`, spelled out by the caller.
12
+ *
13
+ * Deliberately NOT derived inside this factory: `scripts/audit-rule-meta-completeness.ts`
14
+ * reads rule metadata by *statically parsing the rule's source file*, so
15
+ * metadata hidden in here is invisible to it — a factory-built rule scores
16
+ * 0% and fails the strict gate. Keeping it at the call site also puts each
17
+ * driver's CWE/CVSS where a reader expects to find it.
18
+ */
19
+ readonly meta: {
20
+ readonly type: 'problem';
21
+ readonly docs: {
22
+ readonly description: string;
23
+ readonly url: string;
24
+ readonly cwe: string;
25
+ readonly cvss: number;
26
+ readonly confidence: 'high' | 'medium' | 'low';
27
+ };
28
+ };
29
+ /** Bulk-mutation sink methods, e.g. `['deleteMany', 'updateMany']`. */
30
+ readonly methods: readonly string[];
31
+ /**
32
+ * Modules whose exports are this driver's handles, e.g. `['drizzle-orm']`.
33
+ * A file that imports none of them is skipped entirely.
34
+ *
35
+ * Method names alone are hopeless discriminators — `delete` and `update` are
36
+ * also `Map.prototype.delete`, `Set.prototype.delete`, and the vocabulary of
37
+ * every store wrapper ever written. Without this gate the Drizzle and Knex
38
+ * instantiations report `map.delete(key)`. Same reasoning as
39
+ * `eslint-plugin-mongodb-security`'s `receiver.ts`.
40
+ */
41
+ readonly modules: readonly string[];
42
+ /**
43
+ * Identifiers that read as a handle for this driver, matched against the
44
+ * base of the receiver chain (`db` in `db.delete(users)`, `prisma` in
45
+ * `prisma.user.deleteMany()`).
46
+ *
47
+ * Checked in addition to the import gate, because importing `knex` in a file
48
+ * does not make every `.delete()` in it a query. A handle assigned from an
49
+ * imported binding is accepted regardless of its name.
50
+ */
51
+ readonly receiverPattern: RegExp;
52
+ /**
53
+ * What the sink's arguments mean for this driver. The same AST — a lone
54
+ * identifier argument — means opposite things per driver, so it cannot be
55
+ * inferred:
56
+ *
57
+ * - `'options'` (default) — the arguments may carry the filter
58
+ * (`deleteMany(opts)`, `destroy({ where })`). An argument that cannot be
59
+ * read is therefore treated as possible scope, and nothing is reported.
60
+ * - `'table'` — the argument names the table (`db.delete(users)`,
61
+ * `knex('users').update(values)`) and never carries a filter, so only
62
+ * chain scope counts.
63
+ *
64
+ * Reading `db.delete(users)` as `'options'` would suppress the headline
65
+ * Drizzle finding; reading `deleteMany(opts)` as `'table'` would invent a
66
+ * false positive on every dynamic filter.
67
+ */
68
+ readonly argumentRole?: 'options' | 'table';
69
+ /**
70
+ * Only report when an options object is actually present but carries no
71
+ * filter — never on a bare `sink()` with no arguments. Defaults to `false`.
72
+ *
73
+ * Required by ORMs whose instance and static methods share a name.
74
+ * Sequelize's `instance.destroy()` deletes exactly one row and takes no
75
+ * arguments, while `Model.destroy({})` empties the table. Without this,
76
+ * every single-row `instance.destroy()` becomes a false positive — and a
77
+ * plugin that fires on correct code is the one users disable.
78
+ *
79
+ * The cost is a deliberate false negative on `Model.destroy()` written with
80
+ * no arguments, which Sequelize rejects at runtime anyway.
81
+ */
82
+ readonly requireOptionsObject?: boolean;
83
+ /**
84
+ * Top-level option keys that scope a mutation. Defaults to `['where']`.
85
+ * Only DIRECT properties count — a nested `{ data: { where } }` is data,
86
+ * not a filter.
87
+ */
88
+ readonly scopeKeys?: readonly string[];
89
+ /**
90
+ * Chain methods that scope a mutation. Defaults to `['where']`; Knex-style
91
+ * drivers pass their variants (`whereIn`, `whereRaw`, ...).
92
+ */
93
+ readonly scopeMethods?: readonly string[];
94
+ /**
95
+ * Option keys that mean "wipe the table" even though an options object was
96
+ * passed, e.g. Sequelize's `destroy({ truncate: true })`. Reported under
97
+ * `explicitTruncate` because the remediation differs: there is no clause to
98
+ * add, the call itself is the decision.
99
+ */
100
+ readonly truncateKeys?: readonly string[];
101
+ /** Remediation line in the emitted message. */
102
+ readonly fix: string;
103
+ /** Reference link in the emitted message. */
104
+ readonly documentationLink: string;
105
+ }
106
+ /** Property-key name of an object member, or `undefined` for one we cannot read. */
107
+ export declare function propertyKeyName(prop: TSESTree.ObjectLiteralElement): string | undefined;
108
+ /**
109
+ * Does this object literal carry a truthy value under any of `keys`?
110
+ *
111
+ * `truncate: false` is not a truncate, so the value is checked rather than
112
+ * the key's presence.
113
+ */
114
+ export declare function hasTruthyKey(obj: TSESTree.ObjectExpression, keys: readonly string[]): boolean;
115
+ /**
116
+ * Scope evidence inside the call's arguments, for `argumentRole: 'options'`.
117
+ *
118
+ * Returns `true` when scope is present OR cannot be ruled out. An argument we
119
+ * cannot see into — an identifier, a call, a conditional — is treated as
120
+ * scoped: this rule's value is that a finding is always real, so an
121
+ * unreadable filter is a deliberate false negative rather than a guess.
122
+ *
123
+ * A bare literal (`destroy(1)`) is readable and carries no filter, so it does
124
+ * not suppress.
125
+ */
126
+ export declare function hasArgumentScope(args: readonly TSESTree.CallExpressionArgument[], scopeKeys: readonly string[]): boolean;
127
+ /**
128
+ * Every method name called anywhere in the member chain containing `node`.
129
+ *
130
+ * Ascends to the chain root first, so scope written after the sink
131
+ * (`db.delete(users).where(...)`) counts as much as scope written before it
132
+ * (`qb.where(...).delete()`).
133
+ */
134
+ export declare function chainMethodNames(node: TSESTree.CallExpression): Set<string>;
135
+ /**
136
+ * Build a CWE-284 rule for the given bulk-mutation sinks.
137
+ *
138
+ * Reports a sink call only when BOTH scope channels come up empty: no
139
+ * readable filter in the arguments, and no scoping method anywhere in its
140
+ * chain.
141
+ */
142
+ /**
143
+ * Local binding names introduced by importing any of `modules`.
144
+ *
145
+ * Covers both `import { drizzle } from 'drizzle-orm'` and
146
+ * `const knex = require('knex')`, including the destructured and namespace
147
+ * forms. An empty set means the file does not touch the driver at all.
148
+ */
149
+ export declare function driverBindings(program: TSESTree.Program, modules: readonly string[]): Set<string>;
150
+ /**
151
+ * Name at the base of a receiver chain, or `undefined` when it is not an
152
+ * identifier.
153
+ *
154
+ * `db.delete(users)` → `db`; `prisma.user.deleteMany()` → `prisma`;
155
+ * `this.db.delete(t)` → `db`, since `this` carries no name of its own.
156
+ */
157
+ export declare function receiverBaseName(node: TSESTree.MemberExpression): string | undefined;
158
+ export declare function createUnscopedMutationRule(config: UnscopedMutationRuleConfig): TSESLint.RuleModule<UnscopedMutationMessageIds, []>;
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.propertyKeyName = propertyKeyName;
4
+ exports.hasTruthyKey = hasTruthyKey;
5
+ exports.hasArgumentScope = hasArgumentScope;
6
+ exports.chainMethodNames = chainMethodNames;
7
+ exports.driverBindings = driverBindings;
8
+ exports.receiverBaseName = receiverBaseName;
9
+ exports.createUnscopedMutationRule = createUnscopedMutationRule;
10
+ const ast_node_types_1 = require("../ast-node-types");
11
+ const messaging_1 = require("../messaging");
12
+ const DEFAULT_SCOPE_KEYS = ['where'];
13
+ const DEFAULT_SCOPE_METHODS = ['where'];
14
+ function propertyKeyName(prop) {
15
+ if (prop.type !== ast_node_types_1.AST_NODE_TYPES.Property)
16
+ return undefined;
17
+ if (prop.computed)
18
+ return undefined;
19
+ if (prop.key.type === ast_node_types_1.AST_NODE_TYPES.Identifier)
20
+ return prop.key.name;
21
+ if (prop.key.type === ast_node_types_1.AST_NODE_TYPES.Literal && typeof prop.key.value === 'string') {
22
+ return prop.key.value;
23
+ }
24
+ return undefined;
25
+ }
26
+ function hasTruthyKey(obj, keys) {
27
+ return obj.properties.some((prop) => {
28
+ if (prop.type !== ast_node_types_1.AST_NODE_TYPES.Property)
29
+ return false;
30
+ const name = propertyKeyName(prop);
31
+ if (name === undefined || !keys.includes(name))
32
+ return false;
33
+ return !(prop.value.type === ast_node_types_1.AST_NODE_TYPES.Literal && !prop.value.value);
34
+ });
35
+ }
36
+ function hasArgumentScope(args, scopeKeys) {
37
+ return args.some((arg) => {
38
+ if (arg.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression) {
39
+ return arg.properties.some((prop) => {
40
+ if (prop.type === ast_node_types_1.AST_NODE_TYPES.SpreadElement)
41
+ return true;
42
+ const name = propertyKeyName(prop);
43
+ if (name === undefined)
44
+ return true;
45
+ if (!scopeKeys.includes(name))
46
+ return false;
47
+ if (prop.type === ast_node_types_1.AST_NODE_TYPES.Property &&
48
+ prop.value.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression &&
49
+ prop.value.properties.length === 0) {
50
+ return false;
51
+ }
52
+ return true;
53
+ });
54
+ }
55
+ return arg.type !== ast_node_types_1.AST_NODE_TYPES.Literal;
56
+ });
57
+ }
58
+ function chainMethodNames(node) {
59
+ let root = node;
60
+ for (;;) {
61
+ const parent = root.parent;
62
+ if (!parent)
63
+ break;
64
+ if (parent.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression && parent.object === root) {
65
+ root = parent;
66
+ continue;
67
+ }
68
+ if (parent.type === ast_node_types_1.AST_NODE_TYPES.CallExpression && parent.callee === root) {
69
+ root = parent;
70
+ continue;
71
+ }
72
+ break;
73
+ }
74
+ const names = new Set();
75
+ let cursor = root;
76
+ for (;;) {
77
+ if (cursor.type === ast_node_types_1.AST_NODE_TYPES.CallExpression) {
78
+ cursor = cursor.callee;
79
+ continue;
80
+ }
81
+ if (cursor.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression) {
82
+ if (!cursor.computed && cursor.property.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
83
+ names.add(cursor.property.name);
84
+ }
85
+ cursor = cursor.object;
86
+ continue;
87
+ }
88
+ break;
89
+ }
90
+ return names;
91
+ }
92
+ function driverBindings(program, modules) {
93
+ const names = new Set();
94
+ const isDriver = (source) => modules.some((m) => source === m || source.startsWith(`${m}/`));
95
+ for (const stmt of program.body) {
96
+ if (stmt.type === ast_node_types_1.AST_NODE_TYPES.ImportDeclaration) {
97
+ if (typeof stmt.source.value !== 'string' || !isDriver(stmt.source.value))
98
+ continue;
99
+ for (const spec of stmt.specifiers)
100
+ names.add(spec.local.name);
101
+ continue;
102
+ }
103
+ if (stmt.type !== ast_node_types_1.AST_NODE_TYPES.VariableDeclaration)
104
+ continue;
105
+ for (const decl of stmt.declarations) {
106
+ const init = decl.init;
107
+ if (!init ||
108
+ init.type !== ast_node_types_1.AST_NODE_TYPES.CallExpression ||
109
+ init.callee.type !== ast_node_types_1.AST_NODE_TYPES.Identifier ||
110
+ init.callee.name !== 'require') {
111
+ continue;
112
+ }
113
+ const arg = init.arguments[0];
114
+ if (!arg ||
115
+ arg.type !== ast_node_types_1.AST_NODE_TYPES.Literal ||
116
+ typeof arg.value !== 'string' ||
117
+ !isDriver(arg.value)) {
118
+ continue;
119
+ }
120
+ if (decl.id.type === ast_node_types_1.AST_NODE_TYPES.Identifier)
121
+ names.add(decl.id.name);
122
+ if (decl.id.type === ast_node_types_1.AST_NODE_TYPES.ObjectPattern) {
123
+ for (const prop of decl.id.properties) {
124
+ if (prop.type === ast_node_types_1.AST_NODE_TYPES.Property && prop.value.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
125
+ names.add(prop.value.name);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ return names;
132
+ }
133
+ function receiverBaseName(node) {
134
+ let cursor = node.object;
135
+ for (;;) {
136
+ if (cursor.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression) {
137
+ if (cursor.object.type === ast_node_types_1.AST_NODE_TYPES.ThisExpression &&
138
+ !cursor.computed &&
139
+ cursor.property.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
140
+ return cursor.property.name;
141
+ }
142
+ cursor = cursor.object;
143
+ continue;
144
+ }
145
+ if (cursor.type === ast_node_types_1.AST_NODE_TYPES.CallExpression) {
146
+ cursor = cursor.callee;
147
+ continue;
148
+ }
149
+ return cursor.type === ast_node_types_1.AST_NODE_TYPES.Identifier ? cursor.name : undefined;
150
+ }
151
+ }
152
+ function createUnscopedMutationRule(config) {
153
+ const sinks = new Set(config.methods);
154
+ const scopeKeys = config.scopeKeys ?? DEFAULT_SCOPE_KEYS;
155
+ const scopeMethods = config.scopeMethods ?? DEFAULT_SCOPE_METHODS;
156
+ const truncateKeys = config.truncateKeys ?? [];
157
+ const argumentRole = config.argumentRole ?? 'options';
158
+ return {
159
+ meta: {
160
+ type: config.meta.type,
161
+ docs: { ...config.meta.docs },
162
+ messages: {
163
+ unscopedMutation: (0, messaging_1.formatLLMMessage)({
164
+ icon: messaging_1.MessageIcons.SECURITY,
165
+ issueName: 'Unscoped Bulk Mutation',
166
+ description: 'Bulk mutation with no filter detected. This rewrites or deletes every row in the table.',
167
+ severity: 'HIGH',
168
+ cwe: config.meta.docs.cwe,
169
+ owasp: 'A01:2021',
170
+ compliance: ['SOC2', 'NIST-CSF'],
171
+ effort: 'low',
172
+ fix: config.fix,
173
+ documentationLink: config.documentationLink,
174
+ }),
175
+ explicitTruncate: (0, messaging_1.formatLLMMessage)({
176
+ icon: messaging_1.MessageIcons.SECURITY,
177
+ issueName: 'Unscoped Bulk Mutation',
178
+ description: 'Table truncation detected. This ignores any filter and empties the whole table.',
179
+ severity: 'HIGH',
180
+ cwe: config.meta.docs.cwe,
181
+ owasp: 'A01:2021',
182
+ compliance: ['SOC2', 'NIST-CSF'],
183
+ effort: 'low',
184
+ fix: 'Remove the truncate flag and delete by filter, or move the truncation to an explicit maintenance script.',
185
+ documentationLink: config.documentationLink,
186
+ }),
187
+ },
188
+ schema: [],
189
+ },
190
+ defaultOptions: [],
191
+ create(context) {
192
+ let bindings = new Set();
193
+ return {
194
+ Program(program) {
195
+ bindings = driverBindings(program, config.modules);
196
+ },
197
+ CallExpression(node) {
198
+ if (bindings.size === 0)
199
+ return;
200
+ if (node.callee.type !== ast_node_types_1.AST_NODE_TYPES.MemberExpression ||
201
+ node.callee.computed ||
202
+ node.callee.property.type !== ast_node_types_1.AST_NODE_TYPES.Identifier ||
203
+ !sinks.has(node.callee.property.name)) {
204
+ return;
205
+ }
206
+ const base = receiverBaseName(node.callee);
207
+ if (base === undefined)
208
+ return;
209
+ if (!bindings.has(base) && !config.receiverPattern.test(base))
210
+ return;
211
+ if (truncateKeys.length > 0) {
212
+ const truncating = node.arguments.some((arg) => arg.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression && hasTruthyKey(arg, truncateKeys));
213
+ if (truncating) {
214
+ context.report({ node, messageId: 'explicitTruncate' });
215
+ return;
216
+ }
217
+ }
218
+ if (argumentRole === 'options') {
219
+ if (config.requireOptionsObject === true &&
220
+ !node.arguments.some((arg) => arg.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression)) {
221
+ return;
222
+ }
223
+ if (hasArgumentScope(node.arguments, scopeKeys))
224
+ return;
225
+ }
226
+ const chained = chainMethodNames(node);
227
+ if (scopeMethods.some((name) => chained.has(name)))
228
+ return;
229
+ context.report({ node, messageId: 'unscopedMutation' });
230
+ },
231
+ };
232
+ },
233
+ };
234
+ }
@@ -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
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./security-utils"), exports);
17
+ __exportStar(require("./security-utils"), exports);
@@ -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
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./type-utils"), exports);
17
+ __exportStar(require("./type-utils"), exports);
5
18
  require("./meta-augmentation");