eslint-plugin-mcp-sdk-security 0.4.1 → 0.4.3
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,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://eslint.interlace.tools
|
|
2
|
+
<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" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="90" /></picture></a>
|
|
3
3
|
|
|
4
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
5
|
|
|
@@ -192,5 +192,5 @@ MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
|
192
192
|
</p>
|
|
193
193
|
|
|
194
194
|
<p align="center">
|
|
195
|
-
<a href="https://eslint.interlace.tools
|
|
195
|
+
<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" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="70" /></picture></a>
|
|
196
196
|
</p>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-mcp-sdk-security",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
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
6
|
"main": "./src/index.js",
|
|
@@ -74,10 +74,20 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@interlace/eslint-devkit": "^1.
|
|
77
|
+
"@interlace/eslint-devkit": "^1.19.0"
|
|
78
78
|
},
|
|
79
79
|
"funding": {
|
|
80
80
|
"type": "github",
|
|
81
81
|
"url": "https://github.com/ofri-peretz/eslint"
|
|
82
|
+
},
|
|
83
|
+
"interlace": {
|
|
84
|
+
"surface": {
|
|
85
|
+
"kind": "npm",
|
|
86
|
+
"modules": [
|
|
87
|
+
"@modelcontextprotocol/sdk/server/mcp.js",
|
|
88
|
+
"@modelcontextprotocol/sdk/client/index.js"
|
|
89
|
+
],
|
|
90
|
+
"note": "The SDK has no root export — only subpaths. Declaring the bare package read as \"surface: 0\", which is indistinguishable from a plugin with no surface at all."
|
|
91
|
+
}
|
|
82
92
|
}
|
|
83
93
|
}
|
package/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=exports.requireToolInputSchema=exports.noUnvalidatedToolArgs=exports.noToolDescriptionInjection=exports.noCommandInjectionInTool=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");var no_command_injection_in_tool_2=require("./rules/no-command-injection-in-tool");Object.defineProperty(exports,"noCommandInjectionInTool",{enumerable:true,get:function(){return no_command_injection_in_tool_2.noCommandInjectionInTool}});var no_tool_description_injection_2=require("./rules/no-tool-description-injection");Object.defineProperty(exports,"noToolDescriptionInjection",{enumerable:true,get:function(){return no_tool_description_injection_2.noToolDescriptionInjection}});var no_unvalidated_tool_args_2=require("./rules/no-unvalidated-tool-args");Object.defineProperty(exports,"noUnvalidatedToolArgs",{enumerable:true,get:function(){return no_unvalidated_tool_args_2.noUnvalidatedToolArgs}});var require_tool_input_schema_2=require("./rules/require-tool-input-schema");Object.defineProperty(exports,"requireToolInputSchema",{enumerable:true,get:function(){return require_tool_input_schema_2.requireToolInputSchema}});exports.rules={get"no-command-injection-in-tool"(){return require("./rules/no-command-injection-in-tool").noCommandInjectionInTool},get"no-tool-description-injection"(){return require("./rules/no-tool-description-injection").noToolDescriptionInjection},get"no-unvalidated-tool-args"(){return require("./rules/no-unvalidated-tool-args").noUnvalidatedToolArgs},get"require-tool-input-schema"(){return require("./rules/require-tool-input-schema").requireToolInputSchema}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-mcp-sdk-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-mcp-sdk-security",version:"0.4.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=exports.requireToolInputSchema=exports.noUnvalidatedToolArgs=exports.noToolDescriptionInjection=exports.noCommandInjectionInTool=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");var no_command_injection_in_tool_2=require("./rules/no-command-injection-in-tool");Object.defineProperty(exports,"noCommandInjectionInTool",{enumerable:true,get:function(){return no_command_injection_in_tool_2.noCommandInjectionInTool}});var no_tool_description_injection_2=require("./rules/no-tool-description-injection");Object.defineProperty(exports,"noToolDescriptionInjection",{enumerable:true,get:function(){return no_tool_description_injection_2.noToolDescriptionInjection}});var no_unvalidated_tool_args_2=require("./rules/no-unvalidated-tool-args");Object.defineProperty(exports,"noUnvalidatedToolArgs",{enumerable:true,get:function(){return no_unvalidated_tool_args_2.noUnvalidatedToolArgs}});var require_tool_input_schema_2=require("./rules/require-tool-input-schema");Object.defineProperty(exports,"requireToolInputSchema",{enumerable:true,get:function(){return require_tool_input_schema_2.requireToolInputSchema}});exports.rules={get"no-command-injection-in-tool"(){return require("./rules/no-command-injection-in-tool").noCommandInjectionInTool},get"no-tool-description-injection"(){return require("./rules/no-tool-description-injection").noToolDescriptionInjection},get"no-unvalidated-tool-args"(){return require("./rules/no-unvalidated-tool-args").noUnvalidatedToolArgs},get"require-tool-input-schema"(){return require("./rules/require-tool-input-schema").requireToolInputSchema}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-mcp-sdk-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-mcp-sdk-security",version:"0.4.3"},rules:exports.rules};const minimalConfig={plugins:{"mcp-sdk-security":exports.plugin},rules:{"mcp-sdk-security/require-tool-input-schema":"error"}};const recommendedConfig={plugins:{"mcp-sdk-security":exports.plugin},rules:{"mcp-sdk-security/require-tool-input-schema":"error"}};const strictConfig={plugins:{"mcp-sdk-security":exports.plugin},rules:Object.fromEntries(Object.keys(exports.rules).map(ruleName=>[`mcp-sdk-security/${ruleName}`,"error"]))};exports.configs={minimal:minimalConfig,recommended:recommendedConfig,strict:strictConfig};exports.default={...exports.plugin,configs:exports.configs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCommandInjectionInTool=void 0;exports.isBuiltString=isBuiltString;exports.handlerArgNames=handlerArgNames;const eslint_devkit_1=require("@interlace/eslint-devkit");const mcp_evidence_1=require("../../utils/mcp-evidence");const REGISTER_TOOL="registerTool";const LEGACY_TOOL="tool";const PROCESS_SINKS=new Set(["exec","execSync","execFile","execFileSync","spawn","spawnSync","fork"]);function isBuiltString(node){if(node.type==="TemplateLiteral")return node.expressions.length>0;if(node.type==="BinaryExpression"&&node.operator==="+")return true;return false}function handlerArgNames(handler){const direct=new Set;const objects=new Set;if(handler.type!=="ArrowFunctionExpression"&&handler.type!=="FunctionExpression"&&handler.type!=="FunctionDeclaration"){return{direct,objects}}const first=handler.params[0];if(first===void 0)return{direct,objects};if(first.type==="Identifier"){objects.add(first.name);return{direct,objects}}if(first.type==="ObjectPattern"){collectPatternNames(first,direct,objects)}return{direct,objects}}function collectPatternNames(pattern,into,objects){for(const prop of pattern.properties){if(prop.type==="RestElement"){objects.add(prop.argument.name);continue}let value=prop.value;if(value.type==="AssignmentPattern")value=value.left;if(value.type==="Identifier")into.add(value.name);else if(value.type==="ObjectPattern")collectPatternNames(value,into,objects)}}exports.noCommandInjectionInTool=(0,eslint_devkit_1.createRule)({name:"no-command-injection-in-tool",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-command-injection-in-tool.md",description:"Disallow an MCP tool argument being used directly as the command in a child_process call",cwe:"CWE-78",cvss:9.8},messages:{toolArgToShell:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Tool Argument Reaches a Process Sink",cwe:"CWE-78",owasp:"A03:2021",cvss:9.8,description:"Tool argument `{{arg}}` is passed straight to `{{sink}}()`, so whatever steers the model chooses what runs on this host",severity:"CRITICAL",compliance:["SOC2","NIST-CSF"],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 \u2014 `execFile(ALLOWED[op], [value])` \u2014 never as the executable.",documentationLink:"https://modelcontextprotocol.io/docs/concepts/tools"})},schema:[]},defaultOptions:[],create(context){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return{};const handlers=[];const candidates=[];function enclosingHandler(node){let innermost;for(const h of handlers){if(node.range[0]>=h.range[0]&&node.range[1]<=h.range[1])innermost=h}return innermost}return{CallExpression(node){if(node.callee.type==="MemberExpression"
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCommandInjectionInTool=void 0;exports.isBuiltString=isBuiltString;exports.handlerArgNames=handlerArgNames;const eslint_devkit_1=require("@interlace/eslint-devkit");const mcp_evidence_1=require("../../utils/mcp-evidence");const REGISTER_TOOL="registerTool";const LEGACY_TOOL="tool";const PROCESS_SINKS=new Set(["exec","execSync","execFile","execFileSync","spawn","spawnSync","fork"]);function isBuiltString(node){if(node.type==="TemplateLiteral")return node.expressions.length>0;if(node.type==="BinaryExpression"&&node.operator==="+")return true;return false}function handlerArgNames(handler){const direct=new Set;const objects=new Set;if(handler.type!=="ArrowFunctionExpression"&&handler.type!=="FunctionExpression"&&handler.type!=="FunctionDeclaration"){return{direct,objects}}const first=handler.params[0];if(first===void 0)return{direct,objects};if(first.type==="Identifier"){objects.add(first.name);return{direct,objects}}if(first.type==="ObjectPattern"){collectPatternNames(first,direct,objects)}return{direct,objects}}function collectPatternNames(pattern,into,objects){for(const prop of pattern.properties){if(prop.type==="RestElement"){objects.add(prop.argument.name);continue}let value=prop.value;if(value.type==="AssignmentPattern")value=value.left;if(value.type==="Identifier")into.add(value.name);else if(value.type==="ObjectPattern")collectPatternNames(value,into,objects)}}exports.noCommandInjectionInTool=(0,eslint_devkit_1.createRule)({name:"no-command-injection-in-tool",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-command-injection-in-tool.md",description:"Disallow an MCP tool argument being used directly as the command in a child_process call",cwe:"CWE-78",cvss:9.8},messages:{toolArgToShell:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Tool Argument Reaches a Process Sink",cwe:"CWE-78",owasp:"A03:2021",cvss:9.8,description:"Tool argument `{{arg}}` is passed straight to `{{sink}}()`, so whatever steers the model chooses what runs on this host",severity:"CRITICAL",compliance:["SOC2","NIST-CSF"],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 \u2014 `execFile(ALLOWED[op], [value])` \u2014 never as the executable.",documentationLink:"https://modelcontextprotocol.io/docs/concepts/tools"})},schema:[]},defaultOptions:[],create(context){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return{};const handlers=[];const candidates=[];function enclosingHandler(node){let innermost;for(const h of handlers){if(node.range[0]>=h.range[0]&&node.range[1]<=h.range[1])innermost=h}return innermost}return{CallExpression(node){if(node.callee.type==="MemberExpression"&&((0,eslint_devkit_1.propertyName)(node.callee)===REGISTER_TOOL||(0,eslint_devkit_1.propertyName)(node.callee)===LEGACY_TOOL)){const handler=node.arguments[node.arguments.length-1];if(handler!==void 0){const{direct,objects}=handlerArgNames(handler);if(direct.size>0||objects.size>0){handlers.push({range:handler.range,direct,objects})}}}const sinkName=node.callee.type==="Identifier"?node.callee.name:node.callee.type==="MemberExpression"&&!node.callee.computed&&node.callee.property.type==="Identifier"?node.callee.property.name:void 0;if(sinkName===void 0||!PROCESS_SINKS.has(sinkName))return;const commandArg=node.arguments[0];if(commandArg===void 0)return;if(isBuiltString(commandArg))return;candidates.push({node:commandArg,arg:"",sink:sinkName})},"Program:exit"(){for(const candidate of candidates){const handler=enclosingHandler(candidate.node);if(handler===void 0)continue;const command=candidate.node;let argName;if(command.type==="Identifier"&&handler.direct.has(command.name)){argName=command.name}if(command.type==="MemberExpression"&&!command.computed&&command.object.type==="Identifier"&&handler.objects.has(command.object.name)&&command.property.type==="Identifier"){argName=`${command.object.name}.${command.property.name}`}if(argName===void 0)continue;context.report({node:command,messageId:"toolArgToShell",data:{arg:argName,sink:candidate.sink}})}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireToolInputSchema=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const mcp_evidence_1=require("../../utils/mcp-evidence");const REGISTER_TOOL="registerTool";const LEGACY_TOOL="tool";const HANDLER_NODE_TYPES=new Set(["ArrowFunctionExpression","FunctionExpression","Identifier"]);function readInputSchema(config){for(const prop of config.properties){if(prop.type==="SpreadElement")return"unreadable";if(prop.computed)continue;if(prop.key.type==="Identifier"&&prop.key.name==="inputSchema")return"declared";if(prop.key.type==="Literal"&&prop.key.value==="inputSchema")return"declared"}return"missing"}exports.requireToolInputSchema=(0,eslint_devkit_1.createRule)({name:"require-tool-input-schema",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/require-tool-input-schema.md",description:"Require an input schema when registering an MCP tool",cwe:"CWE-20",cvss:7.5},messages:{missingInputSchema:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Tool Registered Without an Input Schema",cwe:"CWE-20",owasp:"A03:2021",cvss:7.5,description:'Tool "{{tool}}" is registered without an input schema, so its handler receives unvalidated client-supplied arguments',severity:"HIGH",compliance:["SOC2"],fix:'Declare the accepted shape: registerTool("{{tool}}", { inputSchema: { path: z.string() } }, handler)',documentationLink:"https://modelcontextprotocol.io/docs/concepts/tools"})},schema:[]},defaultOptions:[],create(context){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return{};const candidates=[];function toolNameOf(node){const first=node.arguments[0];if(first?.type==="Literal"&&typeof first.value==="string")return first.value;return"unknown"}return{CallExpression(node){if(node.callee.type!=="MemberExpression"
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireToolInputSchema=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const mcp_evidence_1=require("../../utils/mcp-evidence");const REGISTER_TOOL="registerTool";const LEGACY_TOOL="tool";const HANDLER_NODE_TYPES=new Set(["ArrowFunctionExpression","FunctionExpression","Identifier"]);function readInputSchema(config){for(const prop of config.properties){if(prop.type==="SpreadElement")return"unreadable";if(prop.computed)continue;if(prop.key.type==="Identifier"&&prop.key.name==="inputSchema")return"declared";if(prop.key.type==="Literal"&&prop.key.value==="inputSchema")return"declared"}return"missing"}exports.requireToolInputSchema=(0,eslint_devkit_1.createRule)({name:"require-tool-input-schema",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/require-tool-input-schema.md",description:"Require an input schema when registering an MCP tool",cwe:"CWE-20",cvss:7.5},messages:{missingInputSchema:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Tool Registered Without an Input Schema",cwe:"CWE-20",owasp:"A03:2021",cvss:7.5,description:'Tool "{{tool}}" is registered without an input schema, so its handler receives unvalidated client-supplied arguments',severity:"HIGH",compliance:["SOC2"],fix:'Declare the accepted shape: registerTool("{{tool}}", { inputSchema: { path: z.string() } }, handler)',documentationLink:"https://modelcontextprotocol.io/docs/concepts/tools"})},schema:[]},defaultOptions:[],create(context){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return{};const candidates=[];function toolNameOf(node){const first=node.arguments[0];if(first?.type==="Literal"&&typeof first.value==="string")return first.value;return"unknown"}return{CallExpression(node){if(node.callee.type!=="MemberExpression")return;const method=(0,eslint_devkit_1.propertyName)(node.callee);if(method===null)return;if(method===REGISTER_TOOL){const config=node.arguments[1];if(config?.type!=="ObjectExpression")return;if(readInputSchema(config)==="missing"){candidates.push({node,tool:toolNameOf(node)})}return}if(method===LEGACY_TOOL&&node.arguments.length===2){const handler=node.arguments[1];if(HANDLER_NODE_TYPES.has(handler.type)){candidates.push({node,tool:toolNameOf(node)})}}},"Program:exit"(){for(const{node,tool}of candidates){context.report({node,messageId:"missingInputSchema",data:{tool}})}}}}});
|