eslint-plugin-mcp-sdk-security 0.1.0 โ†’ 0.2.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,7 +1,11 @@
1
1
  <p align="center">
2
- <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="90" /></a>
2
+ <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security" target="blank"><img src="https://eslint.interlace.tools/logos/interlace.svg" alt="Interlace" height="90" /></a>
3
3
  &nbsp;&nbsp;
4
- <a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/eslint-logo.svg" alt="ESLint" height="90" /></a>
4
+ <a href="https://modelcontextprotocol.io" target="_blank"><img src="https://eslint.interlace.tools/logos/mcp.svg" alt="Model Context Protocol" height="90" /></a>
5
+ &nbsp;&nbsp;
6
+ <a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/logos/oxlint.svg" alt="oxlint" height="90" /></a>
7
+ &nbsp;&nbsp;
8
+ <a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/logos/eslint.svg" alt="ESLint" height="90" /></a>
5
9
  </p>
6
10
 
7
11
  <p align="center">
@@ -26,12 +30,27 @@ Security rules for code built on [`@modelcontextprotocol/sdk`](https://www.npmjs
26
30
 
27
31
  **Interlace** fosters **strength through integration**. Instead of stacking isolated rules, we **interlace** security directly into your workflow to create a resilient fabric of code. We believe tools should **guide rather than gatekeep**, providing educational feedback that strengthens the developer with every interaction.
28
32
 
29
- ## Installation
33
+ ## Getting Started
34
+
35
+ - To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security). ๐Ÿ“š
36
+ - ่ฆๆŸฅ็œ‹ไธญๆ–‡ [ๆŒ‡ๅ—](https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security), ่ฏท่ฎฟ้—ฎ [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security). ๐Ÿ“š
37
+ - [๊ฐ€์ด๋“œ](https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security) ๋ฌธ์„œ๋Š” [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security)์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ“š
38
+ - [ใ‚ฌใ‚คใƒ‰](https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security)ใฏ [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security)ใงใ”็ขบ่ชใใ ใ•ใ„ใ€‚ ๐Ÿ“š
39
+ - Para ver la [guรญa](https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security), visita [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security). ๐Ÿ“š
40
+ - ู„ู„ุงุทู„ุงุน ุนู„ู‰ [ุงู„ุฏู„ูŠู„](https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security)ุŒ ู‚ู… ุจุฒูŠุงุฑุฉ [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security). ๐Ÿ“š
30
41
 
31
42
  ```bash
32
- npm install --save-dev eslint-plugin-mcp-sdk-security
43
+ npm install eslint-plugin-mcp-sdk-security --save-dev
33
44
  ```
34
45
 
46
+ ## โš™๏ธ Configuration Presets
47
+
48
+ | Preset | Description |
49
+ | :--- | :--- |
50
+ | `recommended` | Enables every rule at `error`. |
51
+ | `strict` | Same set as `recommended`; reserved for rules that are not yet safe by default. |
52
+ | `minimal` | Same set as `recommended`; reserved for a reduced high-signal subset. |
53
+
35
54
  ## Usage
36
55
 
37
56
  ```js
@@ -66,39 +85,66 @@ Every rule in this plugin runs on [oxlint](https://oxc.rs) as well as ESLint:
66
85
  { "jsPlugins": ["eslint-plugin-mcp-sdk-security/oxlint"] }
67
86
  ```
68
87
 
88
+ ## ๐Ÿ“ฆ Compatibility
89
+
90
+ | Package | Version |
91
+ | :--- | :--- |
92
+ | `@modelcontextprotocol/sdk` | [![npm](https://img.shields.io/npm/v/@modelcontextprotocol/sdk.svg?style=flat-square)](https://www.npmjs.com/package/@modelcontextprotocol/sdk) |
93
+ | ESLint | [![npm](https://img.shields.io/npm/v/eslint.svg?style=flat-square)](https://www.npmjs.com/package/eslint) |
94
+ | Node.js | [![node](https://img.shields.io/badge/node-%5E18.0.0-green?style=flat-square)](https://nodejs.org/) |
95
+
96
+ See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) for the full matrix.
97
+
69
98
  ## Rules
70
99
 
71
- | Rule | Description | CWE | Recommended |
72
- | --- | --- | --- | --- |
73
- | [require-tool-input-schema](./docs/rules/require-tool-input-schema.md) | Require an input schema when registering an MCP tool | CWE-20 | โœ… error |
100
+ **Legend**
74
101
 
75
- ## What it catches
102
+ | Icon | Description |
103
+ | :---: | :--- |
104
+ | ๐Ÿ’ผ | **Recommended**: Included in the recommended preset. |
105
+ | โš ๏ธ | **Warns**: Set to warn in recommended preset. |
106
+ | ๐Ÿ”ง | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
107
+ | ๐Ÿ’ก | **Suggestions**: Providing code suggestions in IDE. |
108
+ | ๐Ÿšซ | **Deprecated**: This rule is deprecated. |
109
+ | ๐ŸŸข | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
110
+ | ๐ŸŸก | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
111
+ | ๐ŸŸ  | **Type-aware (graceful)**: requires TS program; silent without it. |
76
112
 
77
- ```ts
78
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
113
+ | Rule | CWE | OWASP | CVSS | Description | ๐Ÿง  | ๐Ÿ’ผ | โš ๏ธ | ๐Ÿ”ง | ๐Ÿ’ก | ๐Ÿšซ |
114
+ | :--- | :--- | :--- | :--- | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
115
+ | [require-tool-input-schema](./docs/rules/require-tool-input-schema.md) | CWE-20 | A03:2021 | 7.5 | Require an input schema when registering an MCP tool | ๐ŸŸข | ๐Ÿ’ผ | | | | |
79
116
 
80
- // โŒ handler receives whatever the client sends
81
- server.registerTool('read_file', { description: 'Read a file' }, async (args) => {
82
- return readFileSync(args.path, 'utf8');
83
- });
117
+ <!-- INTERLACE:STAR_CTA:START -->
118
+ ## โญ Support & follow
84
119
 
85
- // โœ… arguments are constrained before the handler runs
86
- server.registerTool('read_file', {
87
- description: 'Read a file',
88
- inputSchema: { path: z.string() },
89
- }, async (args) => {
90
- return readFileSync(args.path, 'utf8');
91
- });
92
- ```
120
+ If this plugin caught a real bug for you, **[star the repo](https://github.com/ofri-peretz/eslint)** โ€” stars are the signal that keeps the Interlace ESLint ecosystem maintained โ€” and **[follow the writeups on Dev.to](https://dev.to/ofri-peretz)** for the benchmarks and security research behind these rules.
121
+
122
+ [![GitHub stars](https://img.shields.io/github/stars/ofri-peretz/eslint?style=social)](https://github.com/ofri-peretz/eslint)
123
+
124
+ <!-- INTERLACE:STAR_CTA:END -->
125
+
126
+ ## ๐Ÿ”— Related ESLint Plugins
93
127
 
94
- ## Roadmap
128
+ Part of the **Interlace ESLint Ecosystem** โ€” AI-native security plugins with LLM-optimized error messages:
95
129
 
96
- `0.1.x` covers the tool-registration surface โ€” the entry point for tool poisoning and argument injection. Next: transport authentication on streamable HTTP, resource path traversal, and tool-output handling.
130
+ | Plugin | Downloads | Description |
131
+ | :--- | :---: | :--- |
132
+ | [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-vercel-ai-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security โ€” prompt injection, output handling. |
133
+ | [`eslint-plugin-openai-security`](https://www.npmjs.com/package/eslint-plugin-openai-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-openai-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-openai-security) | OpenAI SDK security. |
134
+ | [`eslint-plugin-anthropic-security`](https://www.npmjs.com/package/eslint-plugin-anthropic-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-anthropic-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-anthropic-security) | Anthropic SDK and Claude Agent SDK security. |
135
+ | [`eslint-plugin-gemini-security`](https://www.npmjs.com/package/eslint-plugin-gemini-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-gemini-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-gemini-security) | Google Gemini SDK security. |
136
+ | [`eslint-plugin-mcp-sdk-security`](https://www.npmjs.com/package/eslint-plugin-mcp-sdk-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-mcp-sdk-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-mcp-sdk-security) | Model Context Protocol SDK security. |
137
+ | [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-secure-coding.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-secure-coding) | General security rules & OWASP guidelines. |
138
+ | [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-node-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-node-security) | Node.js core-module security (fs, child_process, vm, crypto, Buffer). |
97
139
 
98
140
  ## ๐Ÿ“„ License
99
141
 
100
142
  MIT ยฉ [Ofri Peretz](https://github.com/ofri-peretz)
101
143
 
144
+ <p align="center">
145
+ <a href="https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security"><img src="https://eslint.interlace.tools/images/og-mcp-sdk-security.png" alt="ESLint Interlace Plugin" width="100%" /></a>
146
+ </p>
147
+
102
148
  <p align="center">
103
149
  <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="70" /></a>
104
150
  </p>
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "eslint-plugin-mcp-sdk-security",
3
- "version": "0.1.0",
4
- "description": "ESLint plugin for Model Context Protocol (MCP) SDK security โ€” catches tools registered without an input schema, so handlers never run on unvalidated client-supplied arguments.",
3
+ "version": "0.2.0",
4
+ "description": "ESLint plugin for Model Context Protocol (MCP) SDK security โ€” catches tools registered without an input schema, handlers reading arguments the schema never declared, model-visible descriptions built from dynamic text, and tool arguments reaching a shell.",
5
5
  "type": "commonjs",
6
- "main": "./dist/src/index.js",
7
- "types": "./dist/src/index.d.ts",
6
+ "main": "./src/index.js",
7
+ "types": "./src/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/src/index.d.ts",
11
- "default": "./dist/src/index.js"
10
+ "types": "./src/index.d.ts",
11
+ "default": "./src/index.js"
12
12
  },
13
13
  "./oxlint": {
14
14
  "types": "./src/oxlint.d.ts",
@@ -20,7 +20,7 @@
20
20
  "homepage": "https://eslint.interlace.tools/docs/security/plugin-mcp-sdk-security?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-mcp-sdk-security",
21
21
  "repository": {
22
22
  "type": "git",
23
- "url": "https://github.com/ofri-peretz/eslint",
23
+ "url": "git+https://github.com/ofri-peretz/eslint.git",
24
24
  "directory": "packages/eslint-plugin-mcp-sdk-security"
25
25
  },
26
26
  "bugs": {
@@ -31,10 +31,8 @@
31
31
  },
32
32
  "files": [
33
33
  "src/",
34
- "dist/",
35
34
  "README.md",
36
- "LICENSE",
37
- "CHANGELOG.md"
35
+ "LICENSE"
38
36
  ],
39
37
  "keywords": [
40
38
  "eslint",
@@ -67,7 +65,8 @@
67
65
  "node": ">=18.0.0"
68
66
  },
69
67
  "peerDependencies": {
70
- "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0"
68
+ "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
69
+ "@modelcontextprotocol/sdk": "^1.0.0"
71
70
  },
72
71
  "peerDependenciesMeta": {
73
72
  "@modelcontextprotocol/sdk": {
@@ -75,18 +74,7 @@
75
74
  }
76
75
  },
77
76
  "dependencies": {
78
- "tslib": "^2.3.0",
79
- "@interlace/eslint-devkit": "^1.4.4"
80
- },
81
- "devDependencies": {
82
- "@typescript-eslint/parser": "^8.46.2",
83
- "@typescript-eslint/rule-tester": "^8.46.2"
84
- },
85
- "scripts": {
86
- "build": "tsx ../../scripts/build-package.ts",
87
- "test": "vitest run",
88
- "test:coverage": "vitest run --coverage",
89
- "typecheck": "tsc -p tsconfig.lib.json --noEmit"
77
+ "@interlace/eslint-devkit": "^1.9.0"
90
78
  },
91
79
  "funding": {
92
80
  "type": "github",
package/src/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Minimal declaration written by scripts/build-package.ts.
2
+ //
3
+ // tsc's generated entry declaration inlined every inferred rule-option type
4
+ // (up to 166 kB per plugin) for an API no consumer calls directly. This types
5
+ // what a flat config actually touches. Per-rule option types remain available
6
+ // from the "./types" subpath export where a plugin provides one.
7
+ import type { Linter, Rule } from 'eslint';
8
+
9
+ export declare const rules: Record<string, Rule.RuleModule>;
10
+ export declare const configs: Record<string, Linter.Config>;
11
+ export declare const plugin: {
12
+ meta: { name: string; version: string };
13
+ rules: Record<string, Rule.RuleModule>;
14
+ };
15
+
16
+ declare const _default: typeof plugin;
17
+ export default _default;
package/src/index.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configs = exports.plugin = exports.rules = exports.requireToolInputSchema = exports.noUnvalidatedToolArgs = exports.noToolDescriptionInjection = exports.noCommandInjectionInTool = void 0;
4
+ var no_command_injection_in_tool_2 = require("./rules/no-command-injection-in-tool");
5
+ Object.defineProperty(exports, "noCommandInjectionInTool", { enumerable: true, get: function () { return no_command_injection_in_tool_2.noCommandInjectionInTool; } });
6
+ var no_tool_description_injection_2 = require("./rules/no-tool-description-injection");
7
+ Object.defineProperty(exports, "noToolDescriptionInjection", { enumerable: true, get: function () { return no_tool_description_injection_2.noToolDescriptionInjection; } });
8
+ var no_unvalidated_tool_args_2 = require("./rules/no-unvalidated-tool-args");
9
+ Object.defineProperty(exports, "noUnvalidatedToolArgs", { enumerable: true, get: function () { return no_unvalidated_tool_args_2.noUnvalidatedToolArgs; } });
10
+ var require_tool_input_schema_2 = require("./rules/require-tool-input-schema");
11
+ Object.defineProperty(exports, "requireToolInputSchema", { enumerable: true, get: function () { return require_tool_input_schema_2.requireToolInputSchema; } });
12
+ exports.rules = {
13
+ get 'no-command-injection-in-tool'() { return require("./rules/no-command-injection-in-tool").noCommandInjectionInTool; },
14
+ get 'no-tool-description-injection'() { return require("./rules/no-tool-description-injection").noToolDescriptionInjection; },
15
+ get 'no-unvalidated-tool-args'() { return require("./rules/no-unvalidated-tool-args").noUnvalidatedToolArgs; },
16
+ get 'require-tool-input-schema'() { return require("./rules/require-tool-input-schema").requireToolInputSchema; },
17
+
18
+ };
19
+ exports.plugin = {
20
+ meta: {
21
+ name: 'eslint-plugin-mcp-sdk-security',
22
+ version: '0.2.0',
23
+ },
24
+ rules: exports.rules,
25
+ };
26
+ const minimalConfig = {
27
+ plugins: {
28
+ 'mcp-sdk-security': exports.plugin,
29
+ },
30
+ rules: {
31
+ 'mcp-sdk-security/require-tool-input-schema': 'error',
32
+ },
33
+ };
34
+ const recommendedConfig = {
35
+ plugins: {
36
+ 'mcp-sdk-security': exports.plugin,
37
+ },
38
+ rules: {
39
+ 'mcp-sdk-security/require-tool-input-schema': 'error',
40
+ },
41
+ };
42
+ const strictConfig = {
43
+ plugins: {
44
+ 'mcp-sdk-security': exports.plugin,
45
+ },
46
+ rules: Object.fromEntries(Object.keys(exports.rules).map((ruleName) => [`mcp-sdk-security/${ruleName}`, 'error'])),
47
+ };
48
+ exports.configs = {
49
+ minimal: minimalConfig,
50
+ recommended: recommendedConfig,
51
+ strict: strictConfig,
52
+ };
53
+ exports.default = {
54
+ ...exports.plugin,
55
+ configs: exports.configs,
56
+ };
@@ -0,0 +1,17 @@
1
+ // Minimal declaration written by scripts/build-package.ts.
2
+ //
3
+ // tsc's generated entry declaration inlined every inferred rule-option type
4
+ // (up to 166 kB per plugin) for an API no consumer calls directly. This types
5
+ // what a flat config actually touches. Per-rule option types remain available
6
+ // from the "./types" subpath export where a plugin provides one.
7
+ import type { Linter, Rule } from 'eslint';
8
+
9
+ export declare const rules: Record<string, Rule.RuleModule>;
10
+ export declare const configs: Record<string, Linter.Config>;
11
+ export declare const plugin: {
12
+ meta: { name: string; version: string };
13
+ rules: Record<string, Rule.RuleModule>;
14
+ };
15
+
16
+ declare const _default: typeof plugin;
17
+ export default _default;
package/src/oxlint.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const index_1 = require("./index");
3
+ module.exports = index_1.plugin;
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noCommandInjectionInTool = void 0;
4
+ exports.isBuiltString = isBuiltString;
5
+ exports.handlerArgNames = handlerArgNames;
6
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
7
+ const MCP_MODULE_PREFIX = '@modelcontextprotocol/sdk';
8
+ const REGISTER_TOOL = 'registerTool';
9
+ const LEGACY_TOOL = 'tool';
10
+ const PROCESS_SINKS = new Set([
11
+ 'exec',
12
+ 'execSync',
13
+ 'execFile',
14
+ 'execFileSync',
15
+ 'spawn',
16
+ 'spawnSync',
17
+ 'fork',
18
+ ]);
19
+ function isBuiltString(node) {
20
+ if (node.type === 'TemplateLiteral')
21
+ return node.expressions.length > 0;
22
+ if (node.type === 'BinaryExpression' && node.operator === '+')
23
+ return true;
24
+ return false;
25
+ }
26
+ function handlerArgNames(handler) {
27
+ const direct = new Set();
28
+ const objects = new Set();
29
+ if (handler.type !== 'ArrowFunctionExpression' &&
30
+ handler.type !== 'FunctionExpression' &&
31
+ handler.type !== 'FunctionDeclaration') {
32
+ return { direct, objects };
33
+ }
34
+ const first = handler.params[0];
35
+ if (first === undefined)
36
+ return { direct, objects };
37
+ if (first.type === 'Identifier') {
38
+ objects.add(first.name);
39
+ return { direct, objects };
40
+ }
41
+ if (first.type === 'ObjectPattern') {
42
+ collectPatternNames(first, direct, objects);
43
+ }
44
+ return { direct, objects };
45
+ }
46
+ function collectPatternNames(pattern, into, objects) {
47
+ for (const prop of pattern.properties) {
48
+ if (prop.type === 'RestElement') {
49
+ objects.add(prop.argument.name);
50
+ continue;
51
+ }
52
+ let value = prop.value;
53
+ if (value.type === 'AssignmentPattern')
54
+ value = value.left;
55
+ if (value.type === 'Identifier')
56
+ into.add(value.name);
57
+ else if (value.type === 'ObjectPattern')
58
+ collectPatternNames(value, into, objects);
59
+ }
60
+ }
61
+ exports.noCommandInjectionInTool = (0, eslint_devkit_1.createRule)({
62
+ name: 'no-command-injection-in-tool',
63
+ meta: {
64
+ type: 'problem',
65
+ docs: {
66
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-command-injection-in-tool.md',
67
+ description: 'Disallow an MCP tool argument being used directly as the command in a child_process call',
68
+ cwe: 'CWE-78',
69
+ cvss: 9.8,
70
+ },
71
+ messages: {
72
+ toolArgToShell: (0, eslint_devkit_1.formatLLMMessage)({
73
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
74
+ issueName: 'MCP Tool Argument Reaches a Process Sink',
75
+ cwe: 'CWE-78',
76
+ owasp: 'A03:2021',
77
+ cvss: 9.8,
78
+ description: 'Tool argument `{{arg}}` is passed straight to `{{sink}}()`, so whatever steers the model chooses what runs on this host',
79
+ severity: 'CRITICAL',
80
+ compliance: ['SOC2', 'NIST-CSF'],
81
+ fix: 'Do not let the argument name the command. Map it through a fixed allowlist of permitted operations, and pass user data as an argv array element โ€” `execFile(ALLOWED[op], [value])` โ€” never as the executable.',
82
+ documentationLink: 'https://modelcontextprotocol.io/docs/concepts/tools',
83
+ }),
84
+ },
85
+ schema: [],
86
+ },
87
+ defaultOptions: [],
88
+ create(context) {
89
+ let importsMcpSdk = false;
90
+ const handlers = [];
91
+ const candidates = [];
92
+ function enclosingHandler(node) {
93
+ let innermost;
94
+ for (const h of handlers) {
95
+ if (node.range[0] >= h.range[0] && node.range[1] <= h.range[1])
96
+ innermost = h;
97
+ }
98
+ return innermost;
99
+ }
100
+ return {
101
+ ImportDeclaration(node) {
102
+ if (node.source.value.startsWith(MCP_MODULE_PREFIX))
103
+ importsMcpSdk = true;
104
+ },
105
+ CallExpression(node) {
106
+ if (node.callee.type === 'Identifier' &&
107
+ node.callee.name === 'require' &&
108
+ node.arguments[0]?.type === 'Literal' &&
109
+ typeof node.arguments[0].value === 'string' &&
110
+ node.arguments[0].value.startsWith(MCP_MODULE_PREFIX)) {
111
+ importsMcpSdk = true;
112
+ return;
113
+ }
114
+ if (node.callee.type === 'MemberExpression' &&
115
+ !node.callee.computed &&
116
+ node.callee.property.type === 'Identifier' &&
117
+ (node.callee.property.name === REGISTER_TOOL ||
118
+ node.callee.property.name === LEGACY_TOOL)) {
119
+ const handler = node.arguments[node.arguments.length - 1];
120
+ if (handler !== undefined) {
121
+ const { direct, objects } = handlerArgNames(handler);
122
+ if (direct.size > 0 || objects.size > 0) {
123
+ handlers.push({ range: handler.range, direct, objects });
124
+ }
125
+ }
126
+ }
127
+ const sinkName = node.callee.type === 'Identifier'
128
+ ? node.callee.name
129
+ : node.callee.type === 'MemberExpression' &&
130
+ !node.callee.computed &&
131
+ node.callee.property.type === 'Identifier'
132
+ ? node.callee.property.name
133
+ : undefined;
134
+ if (sinkName === undefined || !PROCESS_SINKS.has(sinkName))
135
+ return;
136
+ const commandArg = node.arguments[0];
137
+ if (commandArg === undefined)
138
+ return;
139
+ if (isBuiltString(commandArg))
140
+ return;
141
+ candidates.push({ node: commandArg, arg: '', sink: sinkName });
142
+ },
143
+ 'Program:exit'() {
144
+ if (!importsMcpSdk)
145
+ return;
146
+ for (const candidate of candidates) {
147
+ const handler = enclosingHandler(candidate.node);
148
+ if (handler === undefined)
149
+ continue;
150
+ const command = candidate.node;
151
+ let argName;
152
+ if (command.type === 'Identifier' && handler.direct.has(command.name)) {
153
+ argName = command.name;
154
+ }
155
+ if (command.type === 'MemberExpression' &&
156
+ !command.computed &&
157
+ command.object.type === 'Identifier' &&
158
+ handler.objects.has(command.object.name) &&
159
+ command.property.type === 'Identifier') {
160
+ argName = `${command.object.name}.${command.property.name}`;
161
+ }
162
+ if (argName === undefined)
163
+ continue;
164
+ context.report({
165
+ node: command,
166
+ messageId: 'toolArgToShell',
167
+ data: { arg: argName, sink: candidate.sink },
168
+ });
169
+ }
170
+ },
171
+ };
172
+ },
173
+ });
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noToolDescriptionInjection = void 0;
4
+ exports.isStaticText = isStaticText;
5
+ exports.modelFacingProperties = modelFacingProperties;
6
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
7
+ const MCP_MODULE_PREFIX = '@modelcontextprotocol/sdk';
8
+ const REGISTER_TOOL = 'registerTool';
9
+ const LEGACY_TOOL = 'tool';
10
+ const MODEL_FACING_KEYS = ['description', 'title'];
11
+ function isStaticText(node) {
12
+ if (node.type === 'Literal')
13
+ return typeof node.value === 'string';
14
+ if (node.type === 'TemplateLiteral')
15
+ return node.expressions.length === 0;
16
+ if (node.type === 'BinaryExpression' && node.operator === '+') {
17
+ return isStaticText(node.left) && isStaticText(node.right);
18
+ }
19
+ return false;
20
+ }
21
+ function modelFacingProperties(config) {
22
+ const found = [];
23
+ for (const prop of config.properties) {
24
+ if (prop.type !== 'Property' || prop.computed)
25
+ continue;
26
+ const key = prop.key.type === 'Identifier'
27
+ ? prop.key.name
28
+ : prop.key.type === 'Literal' && typeof prop.key.value === 'string'
29
+ ? prop.key.value
30
+ : undefined;
31
+ if (key === undefined)
32
+ continue;
33
+ if (!MODEL_FACING_KEYS.includes(key))
34
+ continue;
35
+ if (isStaticText(prop.value))
36
+ continue;
37
+ found.push({ key, value: prop.value });
38
+ }
39
+ return found;
40
+ }
41
+ exports.noToolDescriptionInjection = (0, eslint_devkit_1.createRule)({
42
+ name: 'no-tool-description-injection',
43
+ meta: {
44
+ type: 'problem',
45
+ docs: {
46
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-tool-description-injection.md',
47
+ description: 'Require MCP tool descriptions and titles to be static text, since they reach the model as instructions',
48
+ cwe: 'CWE-1427',
49
+ cvss: 8.6,
50
+ },
51
+ messages: {
52
+ dynamicDescription: (0, eslint_devkit_1.formatLLMMessage)({
53
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
54
+ issueName: 'MCP Tool Description Built at Runtime',
55
+ cwe: 'CWE-1427',
56
+ owasp: 'A03:2021',
57
+ cvss: 8.6,
58
+ description: 'The `{{key}}` for tool "{{tool}}" is assembled at runtime, so it reaches the model as instruction text this file does not control',
59
+ severity: 'HIGH',
60
+ compliance: ['SOC2'],
61
+ fix: 'Write the {{key}} as a literal. If it genuinely varies, register a separate tool per variant rather than interpolating โ€” the text lands in the model\'s instruction block, so whoever controls the value controls the instructions.',
62
+ documentationLink: 'https://modelcontextprotocol.io/docs/concepts/tools',
63
+ }),
64
+ },
65
+ schema: [],
66
+ },
67
+ defaultOptions: [],
68
+ create(context) {
69
+ let importsMcpSdk = false;
70
+ const candidates = [];
71
+ function toolNameOf(node) {
72
+ const first = node.arguments[0];
73
+ if (first?.type === 'Literal' && typeof first.value === 'string')
74
+ return first.value;
75
+ return 'unknown';
76
+ }
77
+ return {
78
+ ImportDeclaration(node) {
79
+ if (node.source.value.startsWith(MCP_MODULE_PREFIX))
80
+ importsMcpSdk = true;
81
+ },
82
+ CallExpression(node) {
83
+ if (node.callee.type === 'Identifier' &&
84
+ node.callee.name === 'require' &&
85
+ node.arguments[0]?.type === 'Literal' &&
86
+ typeof node.arguments[0].value === 'string' &&
87
+ node.arguments[0].value.startsWith(MCP_MODULE_PREFIX)) {
88
+ importsMcpSdk = true;
89
+ return;
90
+ }
91
+ if (node.callee.type !== 'MemberExpression' || node.callee.computed)
92
+ return;
93
+ if (node.callee.property.type !== 'Identifier')
94
+ return;
95
+ const method = node.callee.property.name;
96
+ if (method !== REGISTER_TOOL && method !== LEGACY_TOOL)
97
+ return;
98
+ const config = node.arguments[1];
99
+ if (config?.type !== 'ObjectExpression')
100
+ return;
101
+ for (const finding of modelFacingProperties(config)) {
102
+ candidates.push({ node: finding.value, tool: toolNameOf(node), key: finding.key });
103
+ }
104
+ },
105
+ 'Program:exit'() {
106
+ if (!importsMcpSdk)
107
+ return;
108
+ for (const { node, tool, key } of candidates) {
109
+ context.report({ node, messageId: 'dynamicDescription', data: { tool, key } });
110
+ }
111
+ },
112
+ };
113
+ },
114
+ });