@interlace/eslint-devkit 1.7.0 → 1.9.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.7.0",
3
+ "version": "1.9.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);
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * @fileoverview Shared CWE-522 detector — an inference SDK's browser escape
8
+ * hatch turned on.
9
+ *
10
+ * Both the OpenAI and Anthropic Node SDKs refuse to run in a browser by
11
+ * default, and both unlock it with the same opt-in flag. Turning it on means
12
+ * the API key is shipped to the client and is readable by anyone who opens
13
+ * devtools; a leaked key is billable by whoever finds it.
14
+ *
15
+ * ## Which SDKs this can cover, and which it cannot
16
+ *
17
+ * Verified against the published tarballs (2026-08-05), not assumed:
18
+ *
19
+ * | SDK | Flag |
20
+ * |---|---|
21
+ * | `openai@6` | `dangerouslyAllowBrowser` |
22
+ * | `@anthropic-ai/sdk@0.115` | `dangerouslyAllowBrowser` (`client.d.ts:140`) |
23
+ * | `@google/generative-ai@0.24` | none |
24
+ * | `@google/genai@2.15` | none |
25
+ *
26
+ * Neither Gemini SDK has a browser escape hatch, because neither refuses the
27
+ * browser in the first place — there is no flag to detect and no equivalent
28
+ * structural signal a linter can read without knowing whether the file ships
29
+ * to a client. So this factory has two instantiations, not three. Inventing a
30
+ * fuzzy third would report correct code.
31
+ *
32
+ * The gate compares against an exact SDK module specifier, which by the
33
+ * taxonomy contract keeps it in the SDK's plugin rather than in
34
+ * `browser-security`.
35
+ */
36
+ import type { TSESTree } from '@typescript-eslint/utils';
37
+ /** The opt-in both SDKs spell identically. */
38
+ export declare const BROWSER_ESCAPE_FLAG = "dangerouslyAllowBrowser";
39
+ export interface BrowserEscapeHatchRuleConfig {
40
+ /** Rule id, e.g. `no-browser-api-key-exposure`. */
41
+ ruleName: string;
42
+ /** Vendor name for the message, e.g. `OpenAI`. */
43
+ vendor: string;
44
+ /** Module names that open the gate — exact specifier or subpath. */
45
+ modules: readonly string[];
46
+ /** Rule documentation URL. */
47
+ docsUrl: string;
48
+ /** Vendor documentation link carried in the message. */
49
+ documentationLink: string;
50
+ }
51
+ export type FlagVerdict = 'enabled' | 'absent' | 'unreadable';
52
+ /**
53
+ * Whether the client options literal turns the browser escape hatch on.
54
+ *
55
+ * A non-literal value is `unreadable` — `{ dangerouslyAllowBrowser: isBrowser }`
56
+ * could be either at runtime, and reporting on a guess would flag correct code.
57
+ * An explicit `false` is `absent`: the author already made the safe choice.
58
+ *
59
+ * Spreads are positional, not fatal. Only a spread that can *override* the flag
60
+ * hides it:
61
+ *
62
+ * { ...base } → unreadable, base may set it
63
+ * { dangerouslyAllowBrowser: true, ...base } → unreadable, base may unset it
64
+ * { ...base, dangerouslyAllowBrowser: true } → ENABLED — the explicit key
65
+ * wins, whatever base held
66
+ *
67
+ * Bailing on the first spread seen made that last shape silent, which is a
68
+ * false negative on a definite finding rather than caution about an
69
+ * ambiguous one.
70
+ */
71
+ export declare function readFlag(options: TSESTree.ObjectExpression): FlagVerdict;
72
+ export declare function createBrowserEscapeHatchRule(config: BrowserEscapeHatchRuleConfig): import("./rule-creator").RuleModuleWithName<"browserKeyExposure", [], unknown>;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BROWSER_ESCAPE_FLAG = void 0;
4
+ exports.readFlag = readFlag;
5
+ exports.createBrowserEscapeHatchRule = createBrowserEscapeHatchRule;
6
+ const rule_creator_1 = require("./rule-creator");
7
+ const messaging_1 = require("../messaging");
8
+ const sdk_api_key_rule_1 = require("./sdk-api-key-rule");
9
+ exports.BROWSER_ESCAPE_FLAG = 'dangerouslyAllowBrowser';
10
+ function isFlagProperty(prop) {
11
+ return (prop.type !== 'SpreadElement' &&
12
+ !prop.computed &&
13
+ ((prop.key.type === 'Identifier' && prop.key.name === exports.BROWSER_ESCAPE_FLAG) ||
14
+ (prop.key.type === 'Literal' && prop.key.value === exports.BROWSER_ESCAPE_FLAG)));
15
+ }
16
+ function readFlag(options) {
17
+ const props = options.properties;
18
+ const index = props.findIndex(isFlagProperty);
19
+ if (index === -1) {
20
+ return props.some((prop) => prop.type === 'SpreadElement') ? 'unreadable' : 'absent';
21
+ }
22
+ for (let i = index + 1; i < props.length; i++) {
23
+ if (props[i].type === 'SpreadElement')
24
+ return 'unreadable';
25
+ }
26
+ const value = props[index].value;
27
+ if (value.type === 'Literal' && value.value === true)
28
+ return 'enabled';
29
+ if (value.type === 'Literal')
30
+ return 'absent';
31
+ return 'unreadable';
32
+ }
33
+ function createBrowserEscapeHatchRule(config) {
34
+ return (0, rule_creator_1.createRule)({
35
+ name: config.ruleName,
36
+ meta: {
37
+ type: 'problem',
38
+ docs: {
39
+ url: config.docsUrl,
40
+ description: `Forbid ${exports.BROWSER_ESCAPE_FLAG}, which exposes the ${config.vendor} API key to the client`,
41
+ cwe: 'CWE-522',
42
+ cvss: 8.6,
43
+ },
44
+ messages: {
45
+ browserKeyExposure: (0, messaging_1.formatLLMMessage)({
46
+ icon: messaging_1.MessageIcons.SECURITY,
47
+ issueName: `${config.vendor} API Key Exposed to the Browser`,
48
+ cwe: 'CWE-522',
49
+ owasp: 'A07:2021',
50
+ cvss: 8.6,
51
+ description: 'dangerouslyAllowBrowser lets the SDK run client-side, which ships the API key to every visitor',
52
+ severity: 'HIGH',
53
+ compliance: ['SOC2', 'PCI-DSS'],
54
+ fix: `Call ${config.vendor} from a server route and forward the result, so the key never leaves the server`,
55
+ documentationLink: config.documentationLink,
56
+ }),
57
+ },
58
+ schema: [],
59
+ },
60
+ defaultOptions: [],
61
+ create(context) {
62
+ let importsSdk = false;
63
+ const candidates = [];
64
+ function inspect(node, args) {
65
+ const options = args[0];
66
+ if (options?.type !== 'ObjectExpression')
67
+ return;
68
+ if (readFlag(options) === 'enabled')
69
+ candidates.push(node);
70
+ }
71
+ return {
72
+ ImportDeclaration(node) {
73
+ if ((0, sdk_api_key_rule_1.matchesModule)(String(node.source.value), config.modules))
74
+ importsSdk = true;
75
+ },
76
+ NewExpression(node) {
77
+ inspect(node, node.arguments);
78
+ },
79
+ CallExpression(node) {
80
+ if (node.callee.type === 'Identifier' &&
81
+ node.callee.name === 'require' &&
82
+ node.arguments[0]?.type === 'Literal' &&
83
+ typeof node.arguments[0].value === 'string' &&
84
+ (0, sdk_api_key_rule_1.matchesModule)(node.arguments[0].value, config.modules)) {
85
+ importsSdk = true;
86
+ return;
87
+ }
88
+ inspect(node, node.arguments);
89
+ },
90
+ 'Program:exit'() {
91
+ if (!importsSdk)
92
+ return;
93
+ for (const node of candidates) {
94
+ context.report({ node, messageId: 'browserKeyExposure' });
95
+ }
96
+ },
97
+ };
98
+ },
99
+ });
100
+ }
@@ -0,0 +1,81 @@
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
+ /**
8
+ * Two ids because the fixes differ in shape.
9
+ *
10
+ * A `password` property is replaced in place with `process.env.…`. A URL has
11
+ * to be rebuilt, or — better — split so the secret never sits in the string.
12
+ */
13
+ export type HardcodedCredentialsMessageIds = 'hardcodedPassword' | 'credentialsInUrl';
14
+ export interface HardcodedCredentialsRuleConfig {
15
+ /**
16
+ * The rule's own `meta.type` + `meta.docs`, spelled out by the caller.
17
+ *
18
+ * Deliberately not derived in here: `scripts/audit-rule-meta-completeness.ts`
19
+ * statically parses each rule's source, so metadata hidden inside a factory
20
+ * is invisible to it.
21
+ */
22
+ readonly meta: {
23
+ readonly type: 'problem';
24
+ readonly docs: {
25
+ readonly description: string;
26
+ readonly url: string;
27
+ readonly cwe: string;
28
+ readonly cweJustification?: string;
29
+ readonly cvss: number;
30
+ readonly confidence: 'high' | 'medium' | 'low';
31
+ };
32
+ };
33
+ /** Driver modules — the plugin-scope gate. */
34
+ readonly modules: readonly string[];
35
+ /** Extra keys that mark an object as this driver's connection config. */
36
+ readonly connectionKeys?: readonly string[];
37
+ /** URL schemes this driver accepts, e.g. `['postgres', 'postgresql']`. */
38
+ readonly urlSchemes: readonly string[];
39
+ /** Remediation for a literal credential property. */
40
+ readonly fix: string;
41
+ /** Remediation for a credential embedded in a URL. */
42
+ readonly urlFix: string;
43
+ readonly documentationLink: string;
44
+ }
45
+ /**
46
+ * Does this URL embed a password?
47
+ *
48
+ * Requires the `user:pass@` form specifically. `postgres://localhost:5432/app`
49
+ * and `postgres://app@host/db` carry no secret and are safe to commit — the
50
+ * whole point of this helper is that they do not report.
51
+ *
52
+ * The username may be empty, so `postgres://:pw@host/db` reports: that is a
53
+ * real password. The known over-match is `scheme://host:5432@other/db`, where
54
+ * a host:port lands in the userinfo slot and `5432` reads as the password.
55
+ * That URL is malformed for every driver here, so accepting the over-match is
56
+ * cheaper than a parser — but it is a deliberate choice, not an oversight.
57
+ */
58
+ export declare function urlEmbedsCredentials(value: string, schemes: readonly string[]): boolean;
59
+ /**
60
+ * The static string value of a node, or `undefined` if it has none.
61
+ *
62
+ * A template literal with no interpolations is a string constant that happens
63
+ * to use backticks — `password: \`hunter2\`` is exactly as committed, exactly
64
+ * as unrotatable, as the single-quoted spelling. Reading only `Literal` let
65
+ * both credential paths be bypassed by changing one character.
66
+ *
67
+ * An *interpolated* template stays `undefined`: its value is decided at
68
+ * runtime, so there is no secret in the file.
69
+ */
70
+ export declare function staticStringValue(node: TSESTree.Node): string | undefined;
71
+ /**
72
+ * A non-empty static string — the only value shape that is a real secret.
73
+ *
74
+ * `process.env.DB_PASSWORD` is the fix, and an interpolated template is a
75
+ * runtime value; neither is reported. An empty string is a driver-specific
76
+ * "no password" sentinel, common in local trust-auth setups, and reporting it
77
+ * teaches people the rule cries wolf.
78
+ */
79
+ export declare function isLiteralSecret(node: TSESTree.Node): boolean;
80
+ /** Build a CWE-798 rule for one driver's connection surface. */
81
+ export declare function createHardcodedCredentialsRule(config: HardcodedCredentialsRuleConfig): TSESLint.RuleModule<HardcodedCredentialsMessageIds, []>;