eslint-plugin-mcp-sdk-security 1.1.0 → 2.0.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 +3 -2
- package/package.json +3 -3
- package/src/index.js +1 -1
- package/src/rules/no-credential-leak-in-tool/index.js +1 -1
- package/src/rules/no-predictable-session-id/index.js +1 -1
- package/src/rules/no-shared-stateless-transport/index.js +1 -1
- package/src/rules/no-untrusted-tool-metadata-in-prompt/index.js +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,9 @@ npm install oxlint-plugin-mcp-sdk-security --save-dev
|
|
|
65
65
|
// vite.config.ts
|
|
66
66
|
import { defineConfig } from 'vite-plus';
|
|
67
67
|
|
|
68
|
-
export default defineConfig({
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
lint: { jsPlugins: ['oxlint-plugin-mcp-sdk-security'] },
|
|
70
|
+
});
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
**ESLint:**
|
|
@@ -245,7 +247,6 @@ Part of the **Interlace ESLint ecosystem** — AI-native rules with LLM-optimize
|
|
|
245
247
|
|
|
246
248
|
| Plugin | Downloads | Description |
|
|
247
249
|
| :--- | :---: | :--- |
|
|
248
|
-
| [`eslint-plugin-cli-floor`](https://www.npmjs.com/package/eslint-plugin-cli-floor) | [](https://www.npmjs.com/package/eslint-plugin-cli-floor) | CLI floor for commander, yargs and burgee. |
|
|
249
250
|
| [`eslint-plugin-conventions`](https://www.npmjs.com/package/eslint-plugin-conventions) | [](https://www.npmjs.com/package/eslint-plugin-conventions) | Team-specific habits and styles. |
|
|
250
251
|
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://www.npmjs.com/package/eslint-plugin-import-next) | Fast cycle + import-graph analysis. |
|
|
251
252
|
| [`eslint-plugin-maintainability`](https://www.npmjs.com/package/eslint-plugin-maintainability) | [](https://www.npmjs.com/package/eslint-plugin-maintainability) | Cognitive load and clean-code patterns. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-mcp-sdk-security",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "ESLint plugin for Model Context Protocol (MCP) SDK security — follows tool arguments into shells, file paths, URLs, SQL and eval; catches credential leaks, untrusted text in model-facing descriptions and prompts, unhardened HTTP transports, shared stateless servers, predictable session ids, untrusted stdio commands and schema/handler drift.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"typescript"
|
|
63
63
|
],
|
|
64
64
|
"engines": {
|
|
65
|
-
"node": ">=
|
|
65
|
+
"node": ">=22.13.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"eslint": "^8.40.0 || ^9.0.0 || ^10.0.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@interlace/eslint-devkit": "^
|
|
80
|
+
"@interlace/eslint-devkit": "^2.0.0"
|
|
81
81
|
},
|
|
82
82
|
"funding": {
|
|
83
83
|
"type": "github",
|
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.requireHttpTransportHardening=exports.noUnvalidatedToolArgs=exports.noUntrustedToolMetadataInPrompt=exports.noUntrustedStdioCommand=exports.noToolDescriptionInjection=exports.noSsrfInTool=exports.noSqlInjectionInTool=exports.noSharedStatelessTransport=exports.noPredictableSessionId=exports.noPathTraversalInTool=exports.noDuplicateToolName=exports.noCredentialLeakInTool=exports.noCommandInjectionInTool=exports.noCodeInjectionInTool=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");var no_code_injection_in_tool_2=require("./rules/no-code-injection-in-tool");Object.defineProperty(exports,"noCodeInjectionInTool",{enumerable:true,get:function(){return no_code_injection_in_tool_2.noCodeInjectionInTool}});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_credential_leak_in_tool_2=require("./rules/no-credential-leak-in-tool");Object.defineProperty(exports,"noCredentialLeakInTool",{enumerable:true,get:function(){return no_credential_leak_in_tool_2.noCredentialLeakInTool}});var no_duplicate_tool_name_2=require("./rules/no-duplicate-tool-name");Object.defineProperty(exports,"noDuplicateToolName",{enumerable:true,get:function(){return no_duplicate_tool_name_2.noDuplicateToolName}});var no_path_traversal_in_tool_2=require("./rules/no-path-traversal-in-tool");Object.defineProperty(exports,"noPathTraversalInTool",{enumerable:true,get:function(){return no_path_traversal_in_tool_2.noPathTraversalInTool}});var no_predictable_session_id_2=require("./rules/no-predictable-session-id");Object.defineProperty(exports,"noPredictableSessionId",{enumerable:true,get:function(){return no_predictable_session_id_2.noPredictableSessionId}});var no_shared_stateless_transport_2=require("./rules/no-shared-stateless-transport");Object.defineProperty(exports,"noSharedStatelessTransport",{enumerable:true,get:function(){return no_shared_stateless_transport_2.noSharedStatelessTransport}});var no_sql_injection_in_tool_2=require("./rules/no-sql-injection-in-tool");Object.defineProperty(exports,"noSqlInjectionInTool",{enumerable:true,get:function(){return no_sql_injection_in_tool_2.noSqlInjectionInTool}});var no_ssrf_in_tool_2=require("./rules/no-ssrf-in-tool");Object.defineProperty(exports,"noSsrfInTool",{enumerable:true,get:function(){return no_ssrf_in_tool_2.noSsrfInTool}});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_untrusted_stdio_command_2=require("./rules/no-untrusted-stdio-command");Object.defineProperty(exports,"noUntrustedStdioCommand",{enumerable:true,get:function(){return no_untrusted_stdio_command_2.noUntrustedStdioCommand}});var no_untrusted_tool_metadata_in_prompt_2=require("./rules/no-untrusted-tool-metadata-in-prompt");Object.defineProperty(exports,"noUntrustedToolMetadataInPrompt",{enumerable:true,get:function(){return no_untrusted_tool_metadata_in_prompt_2.noUntrustedToolMetadataInPrompt}});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_http_transport_hardening_2=require("./rules/require-http-transport-hardening");Object.defineProperty(exports,"requireHttpTransportHardening",{enumerable:true,get:function(){return require_http_transport_hardening_2.requireHttpTransportHardening}});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-code-injection-in-tool"(){return require("./rules/no-code-injection-in-tool").noCodeInjectionInTool},get"no-command-injection-in-tool"(){return require("./rules/no-command-injection-in-tool").noCommandInjectionInTool},get"no-credential-leak-in-tool"(){return require("./rules/no-credential-leak-in-tool").noCredentialLeakInTool},get"no-duplicate-tool-name"(){return require("./rules/no-duplicate-tool-name").noDuplicateToolName},get"no-path-traversal-in-tool"(){return require("./rules/no-path-traversal-in-tool").noPathTraversalInTool},get"no-predictable-session-id"(){return require("./rules/no-predictable-session-id").noPredictableSessionId},get"no-shared-stateless-transport"(){return require("./rules/no-shared-stateless-transport").noSharedStatelessTransport},get"no-sql-injection-in-tool"(){return require("./rules/no-sql-injection-in-tool").noSqlInjectionInTool},get"no-ssrf-in-tool"(){return require("./rules/no-ssrf-in-tool").noSsrfInTool},get"no-tool-description-injection"(){return require("./rules/no-tool-description-injection").noToolDescriptionInjection},get"no-untrusted-stdio-command"(){return require("./rules/no-untrusted-stdio-command").noUntrustedStdioCommand},get"no-untrusted-tool-metadata-in-prompt"(){return require("./rules/no-untrusted-tool-metadata-in-prompt").noUntrustedToolMetadataInPrompt},get"no-unvalidated-tool-args"(){return require("./rules/no-unvalidated-tool-args").noUnvalidatedToolArgs},get"require-http-transport-hardening"(){return require("./rules/require-http-transport-hardening").requireHttpTransportHardening},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:"
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=exports.requireToolInputSchema=exports.requireHttpTransportHardening=exports.noUnvalidatedToolArgs=exports.noUntrustedToolMetadataInPrompt=exports.noUntrustedStdioCommand=exports.noToolDescriptionInjection=exports.noSsrfInTool=exports.noSqlInjectionInTool=exports.noSharedStatelessTransport=exports.noPredictableSessionId=exports.noPathTraversalInTool=exports.noDuplicateToolName=exports.noCredentialLeakInTool=exports.noCommandInjectionInTool=exports.noCodeInjectionInTool=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");var no_code_injection_in_tool_2=require("./rules/no-code-injection-in-tool");Object.defineProperty(exports,"noCodeInjectionInTool",{enumerable:true,get:function(){return no_code_injection_in_tool_2.noCodeInjectionInTool}});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_credential_leak_in_tool_2=require("./rules/no-credential-leak-in-tool");Object.defineProperty(exports,"noCredentialLeakInTool",{enumerable:true,get:function(){return no_credential_leak_in_tool_2.noCredentialLeakInTool}});var no_duplicate_tool_name_2=require("./rules/no-duplicate-tool-name");Object.defineProperty(exports,"noDuplicateToolName",{enumerable:true,get:function(){return no_duplicate_tool_name_2.noDuplicateToolName}});var no_path_traversal_in_tool_2=require("./rules/no-path-traversal-in-tool");Object.defineProperty(exports,"noPathTraversalInTool",{enumerable:true,get:function(){return no_path_traversal_in_tool_2.noPathTraversalInTool}});var no_predictable_session_id_2=require("./rules/no-predictable-session-id");Object.defineProperty(exports,"noPredictableSessionId",{enumerable:true,get:function(){return no_predictable_session_id_2.noPredictableSessionId}});var no_shared_stateless_transport_2=require("./rules/no-shared-stateless-transport");Object.defineProperty(exports,"noSharedStatelessTransport",{enumerable:true,get:function(){return no_shared_stateless_transport_2.noSharedStatelessTransport}});var no_sql_injection_in_tool_2=require("./rules/no-sql-injection-in-tool");Object.defineProperty(exports,"noSqlInjectionInTool",{enumerable:true,get:function(){return no_sql_injection_in_tool_2.noSqlInjectionInTool}});var no_ssrf_in_tool_2=require("./rules/no-ssrf-in-tool");Object.defineProperty(exports,"noSsrfInTool",{enumerable:true,get:function(){return no_ssrf_in_tool_2.noSsrfInTool}});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_untrusted_stdio_command_2=require("./rules/no-untrusted-stdio-command");Object.defineProperty(exports,"noUntrustedStdioCommand",{enumerable:true,get:function(){return no_untrusted_stdio_command_2.noUntrustedStdioCommand}});var no_untrusted_tool_metadata_in_prompt_2=require("./rules/no-untrusted-tool-metadata-in-prompt");Object.defineProperty(exports,"noUntrustedToolMetadataInPrompt",{enumerable:true,get:function(){return no_untrusted_tool_metadata_in_prompt_2.noUntrustedToolMetadataInPrompt}});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_http_transport_hardening_2=require("./rules/require-http-transport-hardening");Object.defineProperty(exports,"requireHttpTransportHardening",{enumerable:true,get:function(){return require_http_transport_hardening_2.requireHttpTransportHardening}});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-code-injection-in-tool"(){return require("./rules/no-code-injection-in-tool").noCodeInjectionInTool},get"no-command-injection-in-tool"(){return require("./rules/no-command-injection-in-tool").noCommandInjectionInTool},get"no-credential-leak-in-tool"(){return require("./rules/no-credential-leak-in-tool").noCredentialLeakInTool},get"no-duplicate-tool-name"(){return require("./rules/no-duplicate-tool-name").noDuplicateToolName},get"no-path-traversal-in-tool"(){return require("./rules/no-path-traversal-in-tool").noPathTraversalInTool},get"no-predictable-session-id"(){return require("./rules/no-predictable-session-id").noPredictableSessionId},get"no-shared-stateless-transport"(){return require("./rules/no-shared-stateless-transport").noSharedStatelessTransport},get"no-sql-injection-in-tool"(){return require("./rules/no-sql-injection-in-tool").noSqlInjectionInTool},get"no-ssrf-in-tool"(){return require("./rules/no-ssrf-in-tool").noSsrfInTool},get"no-tool-description-injection"(){return require("./rules/no-tool-description-injection").noToolDescriptionInjection},get"no-untrusted-stdio-command"(){return require("./rules/no-untrusted-stdio-command").noUntrustedStdioCommand},get"no-untrusted-tool-metadata-in-prompt"(){return require("./rules/no-untrusted-tool-metadata-in-prompt").noUntrustedToolMetadataInPrompt},get"no-unvalidated-tool-args"(){return require("./rules/no-unvalidated-tool-args").noUnvalidatedToolArgs},get"require-http-transport-hardening"(){return require("./rules/require-http-transport-hardening").requireHttpTransportHardening},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:"2.0.0"},rules:exports.rules};const minimalRules={"mcp-sdk-security/no-command-injection-in-tool":"error","mcp-sdk-security/require-tool-input-schema":"error"};const recommendedRules={"mcp-sdk-security/no-code-injection-in-tool":"error","mcp-sdk-security/no-command-injection-in-tool":"error","mcp-sdk-security/no-credential-leak-in-tool":"error","mcp-sdk-security/no-duplicate-tool-name":"warn","mcp-sdk-security/no-path-traversal-in-tool":"error","mcp-sdk-security/no-predictable-session-id":"error","mcp-sdk-security/no-shared-stateless-transport":"error","mcp-sdk-security/no-sql-injection-in-tool":"error","mcp-sdk-security/no-ssrf-in-tool":"error","mcp-sdk-security/no-tool-description-injection":"error","mcp-sdk-security/no-untrusted-stdio-command":"error","mcp-sdk-security/no-untrusted-tool-metadata-in-prompt":"error","mcp-sdk-security/no-unvalidated-tool-args":"error","mcp-sdk-security/require-http-transport-hardening":"error","mcp-sdk-security/require-tool-input-schema":"error"};const strictRules={...Object.fromEntries(Object.keys(exports.rules).map(ruleName=>[`mcp-sdk-security/${ruleName}`,"error"])),...recommendedRules};exports.configs={minimal:{plugins:{"mcp-sdk-security":exports.plugin},rules:minimalRules},recommended:{plugins:{"mcp-sdk-security":exports.plugin},rules:recommendedRules},strict:{plugins:{"mcp-sdk-security":exports.plugin},rules:strictRules}};exports.default={...exports.plugin,configs:exports.configs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCredentialLeakInTool=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const http_clients_1=require("../../utils/http-clients");const instances_1=require("../../utils/instances");const mcp_evidence_1=require("../../utils/mcp-evidence");const module_resolver_1=require("../../utils/module-resolver");const tool_handlers_1=require("../../utils/tool-handlers");const tool_registration_1=require("../../utils/tool-registration");const value_flow_1=require("../../utils/value-flow");const TOKEN_KEY="token";const UPSTREAM_TRANSPORTS=new Set(["StreamableHTTPClientTransport","SSEClientTransport"]);const MAX_RESULT_DEPTH=8;const message=(issueName,cwe,description,fix)=>(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName,cwe,owasp:"A01:2021",cvss:7.5,description,severity:"HIGH",compliance:["SOC2","GDPR","NIST-CSF"],fix,documentationLink:"https://modelcontextprotocol.io/specification/2025-06-18/basic/security_best_practices"});function children(node){const out=[];for(const[key,value]of Object.entries(node)){if(key==="parent")continue;for(const child of Array.isArray(value)?value:[value]){if(child!==null&&typeof child==="object"&&typeof child.type==="string")out.push(child)}}return out}exports.noCredentialLeakInTool=(0,eslint_devkit_1.createRule)({name:"no-credential-leak-in-tool",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-credential-leak-in-tool.md",description:"Disallow an MCP tool returning the server's environment or the caller's token, or forwarding that token upstream",cwe:"CWE-200",cvss:7.5},messages:{envInResult:message("MCP Tool Returns the Server Environment","CWE-526","This tool result carries `{{what}}`, so every credential the server was started with reaches the model and anything that can steer it","Return only the specific, non-secret values the tool exists to report, each named in code. Never return `process.env` or let an argument choose which variable is read."),tokenInResult:message("MCP Tool Returns the Caller's Token","CWE-200","This tool result carries `{{arg}}` \u2014 the bearer token this request was authorised with \u2014 so the model, the host log and any later tool call can read it","Return what the token grants (the user id, the scopes) instead of the token itself."),tokenPassthrough:message("MCP Tool Forwards the Caller's Token","CWE-441","`{{arg}}` \u2014 the bearer token this MCP server received \u2014 is forwarded through `{{client}}`. The MCP spec forbids token passthrough: the downstream API trusts a token not issued for it, and the call is attributed to the wrong party","Authenticate to the downstream API with a credential issued to this server (OAuth token exchange / on-behalf-of, or the server\u2019s own client credentials). Never forward the inbound token.")},schema:[]},defaultOptions:[],skipTestFiles:true,createOnce(context){let sourceCode;let builtBy;let argumentRoots;let contextRoots;let outbound;function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCredentialLeakInTool=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const http_clients_1=require("../../utils/http-clients");const instances_1=require("../../utils/instances");const mcp_evidence_1=require("../../utils/mcp-evidence");const module_resolver_1=require("../../utils/module-resolver");const tool_handlers_1=require("../../utils/tool-handlers");const tool_registration_1=require("../../utils/tool-registration");const value_flow_1=require("../../utils/value-flow");const TOKEN_KEY="token";const UPSTREAM_TRANSPORTS=new Set(["StreamableHTTPClientTransport","SSEClientTransport"]);const MAX_RESULT_DEPTH=8;const message=(issueName,cwe,description,fix)=>(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName,cwe,owasp:"A01:2021",cvss:7.5,description,severity:"HIGH",compliance:["SOC2","GDPR","NIST-CSF"],fix,documentationLink:"https://modelcontextprotocol.io/specification/2025-06-18/basic/security_best_practices"});function children(node){const out=[];for(const[key,value]of Object.entries(node)){if(key==="parent")continue;for(const child of Array.isArray(value)?value:[value]){if(child!==null&&typeof child==="object"&&typeof child.type==="string")out.push(child)}}return out}exports.noCredentialLeakInTool=(0,eslint_devkit_1.createRule)({name:"no-credential-leak-in-tool",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-credential-leak-in-tool.md",description:"Disallow an MCP tool returning the server's environment or the caller's token, or forwarding that token upstream",cwe:"CWE-200",cvss:7.5},messages:{envInResult:message("MCP Tool Returns the Server Environment","CWE-526","This tool result carries `{{what}}`, so every credential the server was started with reaches the model and anything that can steer it","Return only the specific, non-secret values the tool exists to report, each named in code. Never return `process.env` or let an argument choose which variable is read."),tokenInResult:message("MCP Tool Returns the Caller's Token","CWE-200","This tool result carries `{{arg}}` \u2014 the bearer token this request was authorised with \u2014 so the model, the host log and any later tool call can read it","Return what the token grants (the user id, the scopes) instead of the token itself."),tokenPassthrough:message("MCP Tool Forwards the Caller's Token","CWE-441","`{{arg}}` \u2014 the bearer token this MCP server received \u2014 is forwarded through `{{client}}`. The MCP spec forbids token passthrough: the downstream API trusts a token not issued for it, and the call is attributed to the wrong party","Authenticate to the downstream API with a credential issued to this server (OAuth token exchange / on-behalf-of, or the server\u2019s own client credentials). Never forward the inbound token.")},schema:[]},defaultOptions:[],skipTestFiles:true,createOnce(context){let sourceCode;let builtBy;let argumentRoots;let contextRoots;let outbound;function isGlobalProcess(node){return node?.type==="Identifier"&&node.name==="process"&&!(0,tool_registration_1.lookupVariable)("process",sourceCode.getScope(node))?.defs.length}function isEnvBinding(node){const parent=node.parent;if(parent?.type==="Property"&&parent.key===node&&!parent.computed||parent?.type==="MemberExpression"&&parent.property===node&&!parent.computed)return false;const scope=sourceCode.getScope(node);const binding=(0,eslint_devkit_1.resolveModuleBinding)(node,scope);if(binding)return binding.module==="process"&&binding.path.join(".")==="env";const def=(0,tool_registration_1.lookupVariable)(node.name,scope)?.defs[0];return def?.type==="Variable"&&def.node.id.type==="ObjectPattern"&&isGlobalProcess(def.node.init)&&def.node.id.properties.some(p=>p.type==="Property"&&(p.value.type==="AssignmentPattern"?p.value.left:p.value)===def.name&&(0,eslint_devkit_1.objectKeyName)(p)==="env")}function isProcessEnv(node){if(node.type==="Identifier")return isEnvBinding(node);if(node.type!=="MemberExpression"||(0,eslint_devkit_1.propertyName)(node)!=="env")return false;if(isGlobalProcess(node.object))return true;const binding=(0,eslint_devkit_1.resolveModuleBinding)(node,sourceCode.getScope(node));return binding?.module==="process"&&binding.path.join(".")==="env"}function isObjectKeysOf(node){const call=node.parent;return call?.type==="CallExpression"&&call.arguments[0]===node&&call.callee.type==="MemberExpression"&&call.callee.object.type==="Identifier"&&call.callee.object.name==="Object"&&(0,eslint_devkit_1.propertyName)(call.callee)==="keys"&&!(0,tool_registration_1.lookupVariable)("Object",sourceCode.getScope(call))?.defs.length}return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;const resolve=(0,module_resolver_1.valueResolverFor)(context);builtBy=(0,instances_1.createInstanceResolver)(context);argumentRoots=(0,tool_handlers_1.createHandlerCollector)(context,resolve,"arguments");contextRoots=(0,tool_handlers_1.createHandlerCollector)(context,resolve,"context");outbound=[];return true},CallExpression(node){argumentRoots.visit(node);contextRoots.visit(node);const request=(0,http_clients_1.httpRequestOf)(node,sourceCode.getScope(node),builtBy);if(request!==void 0)for(const arg of node.arguments)outbound.push({node:arg,client:request.client})},NewExpression(node){const name=(0,tool_handlers_1.mcpExport)(node.callee,sourceCode.getScope(node));if(name!==void 0&&UPSTREAM_TRANSPORTS.has(name))for(const arg of node.arguments)outbound.push({node:arg,client:`new ${name}()`})},"Program:exit"(){const handlers=new Set([...argumentRoots.roots.keys(),...contextRoots.roots.keys()]);const fromArgs=(0,value_flow_1.createFlow)(sourceCode,fn=>argumentRoots.roots.get(fn),void 0,(0,value_flow_1.flowOptionsFor)(context));const fromContext=(0,value_flow_1.createFlow)(sourceCode,fn=>contextRoots.roots.get(fn),(node,follow)=>{if(node.type!=="CallExpression"||node.callee.type!=="MemberExpression"||node.callee.object.type!=="Identifier"||node.callee.object.name!=="JSON"||(0,eslint_devkit_1.propertyName)(node.callee)!=="stringify"||(0,tool_registration_1.lookupVariable)("JSON",sourceCode.getScope(node))?.defs.length||node.arguments[0]===void 0)return void 0;const t=follow(node.arguments[0]);return t?.kind==="object"?{kind:"value",text:t.text,key:TOKEN_KEY}:t},(0,value_flow_1.flowOptionsFor)(context));const tokenIn=(node,depth=0)=>{if(depth>MAX_RESULT_DEPTH)return null;if(node.type==="ObjectExpression"){for(const prop of node.properties){const value=prop.type==="Property"?prop.value:prop.argument;const t2=tokenIn(value,depth+1);if(t2)return t2}return null}if(node.type==="ArrayExpression"){for(const element of node.elements){const t2=element&&tokenIn(element,depth+1);if(t2)return t2}return null}if(node.type==="Identifier"){const variable=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node));const def=variable?.defs[0];if(def?.type==="Variable"&&def.node.id===def.name&&(def.node.init?.type==="ObjectExpression"||def.node.init?.type==="ArrayExpression"))return tokenIn(def.node.init,depth+1)}const t=fromContext(node);return t?.kind==="value"&&t.key===TOKEN_KEY?t:null};const envIn=root=>{const found=[];const seen=new Set;const visit=node=>{if((0,tool_registration_1.isFunctionNode)(node))return;if(isProcessEnv(node)){const parent=node.parent;if(isObjectKeysOf(node))return;if(parent?.type!=="MemberExpression"||parent.object!==node)found.push(node);else if(parent.computed&&fromArgs(parent.property)?.kind==="value")found.push(parent);return}if(node.type==="Identifier"){const variable=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node));if(variable===void 0||seen.has(variable))return;seen.add(variable);for(const def of variable.defs)if(def.type==="Variable"&&def.node.init)visit(def.node.init);return}for(const child of children(node))visit(child)};visit(root);return found};for(const fn of handlers){for(const result of(0,value_flow_1.returnedExpressions)(fn)){for(const env of envIn(result))context.report({node:env,messageId:"envInResult",data:{what:sourceCode.getText(env)}});const token=tokenIn(result);if(token)context.report({node:result,messageId:"tokenInResult",data:{arg:token.text}})}}for(const{node,client}of outbound){const inner=node.type==="SpreadElement"?node.argument:node;const token=tokenIn(inner);if(token)context.report({node,messageId:"tokenPassthrough",data:{arg:token.text,client}})}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPredictableSessionId=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const mcp_evidence_1=require("../../utils/mcp-evidence");const tool_handlers_1=require("../../utils/tool-handlers");const tool_registration_1=require("../../utils/tool-registration");const value_flow_1=require("../../utils/value-flow");const STREAMABLE_TRANSPORTS=new Set(["StreamableHTTPServerTransport","NodeStreamableHTTPServerTransport","WebStandardStreamableHTTPServerTransport"]);const CSPRNG_EXPORTS=new Map([["crypto",new Set(["randomUUID","randomBytes","getRandomValues"])],["uuid",new Set(["v4","v7"])],["nanoid",new Set(["nanoid"])]]);const GLOBAL_CSPRNG=new Set(["crypto.randomUUID","crypto.getRandomValues"]);const PREDICTABLE_GLOBALS=new Set(["Date.now","performance.now","Math.random","process.hrtime","process.hrtime.bigint"]);const DERIVING_GLOBALS=new Set(["String","Math.floor","Math.round","Math.trunc"]);const DERIVING_METHODS=new Set(["toString","toFixed","toISOString","getTime","valueOf","slice","substring","substr","padStart","padEnd","replace","replaceAll","toUpperCase","toLowerCase","trim","join"]);const MAX_DEPTH=8;function combine(kinds){if(kinds.includes("csprng"))return"csprng";if(kinds.includes("unknown"))return"unknown";if(kinds.includes("predictable"))return"predictable";return"constant"}function opaque(kinds){return kinds.includes("csprng")?"csprng":"unknown"}function insideFunction(node){for(let current=node.parent;current;current=current.parent){if((0,tool_registration_1.isFunctionNode)(current))return true}return false}function globalPath(node,scope){const path=(0,eslint_devkit_1.memberPath)(node);if(path===null||(0,tool_registration_1.lookupVariable)(path[0],scope)?.defs.length)return null;return path.join(".")}const SESSION_DOCS="https://modelcontextprotocol.io/specification/2025-06-18/basic/security_best_practices#session-hijacking";exports.noPredictableSessionId=(0,eslint_devkit_1.createRule)({name:"no-predictable-session-id",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-predictable-session-id.md",description:"Disallow an MCP sessionIdGenerator that returns a counter, a timestamp, Math.random() or a constant",cwe:"CWE-330",cvss:7.5},messages:{predictableSessionId:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Predictable MCP Session ID",cwe:"CWE-330",owasp:"A02:2021",cvss:7.5,description:"This sessionIdGenerator builds the session ID only from timestamps, counters or Math.random(), so a client that sees one ID can guess the IDs of other sessions and send requests into them",severity:"HIGH",compliance:["SOC2","PCI-DSS"],fix:"Return `randomUUID()` from 'node:crypto' (or the global `crypto.randomUUID()`): `sessionIdGenerator: () => randomUUID()`.",documentationLink:SESSION_DOCS}),constantSessionId:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Constant MCP Session ID",cwe:"CWE-330",owasp:"A02:2021",cvss:7.5,description:"This sessionIdGenerator returns the same value for every session, so every client shares one session and can read and drive the others' requests",severity:"HIGH",compliance:["SOC2","PCI-DSS"],fix:"Generate the ID per call: `sessionIdGenerator: () => randomUUID()`. A value computed once at module level is the same for every session.",documentationLink:SESSION_DOCS})},schema:[]},defaultOptions:[],createOnce(context){let sourceCode;function classify(node,depth){if(depth>MAX_DEPTH)return"unknown";const scope=sourceCode.getScope(node);switch(node.type){case"Literal":return"constant";case"UpdateExpression":return"predictable";case"TemplateLiteral":return combine(node.expressions.map(e=>classify(e,depth+1)));case"BinaryExpression":return combine([classify(node.left,depth+1),classify(node.right,depth+1)]);case"NewExpression":return globalPath(node.callee,scope)==="Date"?"predictable":"unknown";case"MemberExpression":return opaque([classify(node.object,depth+1)]);case"CallExpression":return classifyCall(node,scope,depth);case"Identifier":{const init=(0,tool_registration_1.constInitializer)(node,scope);if(init===void 0)return"unknown";if(!insideFunction(init))return"constant";return classify(init,depth+1)}default:return"unknown"}}function classifyCall(node,scope,depth){const args=node.arguments.map(arg=>classify(arg,depth+1));const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding!==void 0){const exported=binding.path.join(".");return CSPRNG_EXPORTS.get(binding.module)?.has(exported)?"csprng":opaque(args)}const global=globalPath(node.callee,scope);if(global!==null){if(GLOBAL_CSPRNG.has(global))return"csprng";if(PREDICTABLE_GLOBALS.has(global))return"predictable";if(DERIVING_GLOBALS.has(global))return combine(args);return opaque(args)}if(node.callee.type==="MemberExpression"){const receiver=classify(node.callee.object,depth+1);const method=(0,eslint_devkit_1.propertyName)(node.callee);if(method!==null&&DERIVING_METHODS.has(method))return combine([receiver,...args]);return opaque([receiver,...args])}const helper=(0,tool_registration_1.resolveFunction)(node.callee,scope);if(helper===void 0)return opaque(args);return combine((0,value_flow_1.returnedExpressions)(helper).map(e=>classify(e,depth+1)))}function check(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPredictableSessionId=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const mcp_evidence_1=require("../../utils/mcp-evidence");const tool_handlers_1=require("../../utils/tool-handlers");const tool_registration_1=require("../../utils/tool-registration");const value_flow_1=require("../../utils/value-flow");const STREAMABLE_TRANSPORTS=new Set(["StreamableHTTPServerTransport","NodeStreamableHTTPServerTransport","WebStandardStreamableHTTPServerTransport"]);const CSPRNG_EXPORTS=new Map([["crypto",new Set(["randomUUID","randomBytes","getRandomValues"])],["uuid",new Set(["v4","v7"])],["nanoid",new Set(["nanoid"])]]);const GLOBAL_CSPRNG=new Set(["crypto.randomUUID","crypto.getRandomValues"]);const PREDICTABLE_GLOBALS=new Set(["Date.now","performance.now","Math.random","process.hrtime","process.hrtime.bigint"]);const DERIVING_GLOBALS=new Set(["String","Math.floor","Math.round","Math.trunc"]);const DERIVING_METHODS=new Set(["toString","toFixed","toISOString","getTime","valueOf","slice","substring","substr","padStart","padEnd","replace","replaceAll","toUpperCase","toLowerCase","trim","join"]);const MAX_DEPTH=8;function combine(kinds){if(kinds.includes("csprng"))return"csprng";if(kinds.includes("unknown"))return"unknown";if(kinds.includes("predictable"))return"predictable";return"constant"}function opaque(kinds){return kinds.includes("csprng")?"csprng":"unknown"}function insideFunction(node){for(let current=node.parent;current;current=current.parent){if((0,tool_registration_1.isFunctionNode)(current))return true}return false}function globalPath(node,scope){const path=(0,eslint_devkit_1.memberPath)(node);if(path===null||(0,tool_registration_1.lookupVariable)(path[0],scope)?.defs.length)return null;return path.join(".")}const SESSION_DOCS="https://modelcontextprotocol.io/specification/2025-06-18/basic/security_best_practices#session-hijacking";exports.noPredictableSessionId=(0,eslint_devkit_1.createRule)({name:"no-predictable-session-id",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-predictable-session-id.md",description:"Disallow an MCP sessionIdGenerator that returns a counter, a timestamp, Math.random() or a constant",cwe:"CWE-330",cvss:7.5},messages:{predictableSessionId:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Predictable MCP Session ID",cwe:"CWE-330",owasp:"A02:2021",cvss:7.5,description:"This sessionIdGenerator builds the session ID only from timestamps, counters or Math.random(), so a client that sees one ID can guess the IDs of other sessions and send requests into them",severity:"HIGH",compliance:["SOC2","PCI-DSS"],fix:"Return `randomUUID()` from 'node:crypto' (or the global `crypto.randomUUID()`): `sessionIdGenerator: () => randomUUID()`.",documentationLink:SESSION_DOCS}),constantSessionId:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Constant MCP Session ID",cwe:"CWE-330",owasp:"A02:2021",cvss:7.5,description:"This sessionIdGenerator returns the same value for every session, so every client shares one session and can read and drive the others' requests",severity:"HIGH",compliance:["SOC2","PCI-DSS"],fix:"Generate the ID per call: `sessionIdGenerator: () => randomUUID()`. A value computed once at module level is the same for every session.",documentationLink:SESSION_DOCS})},schema:[]},defaultOptions:[],createOnce(context){let sourceCode;function classify(node,depth){if(depth>MAX_DEPTH)return"unknown";const scope=sourceCode.getScope(node);switch(node.type){case"Literal":return"constant";case"UpdateExpression":return"predictable";case"TemplateLiteral":return combine(node.expressions.map(e=>classify(e,depth+1)));case"BinaryExpression":return combine([classify(node.left,depth+1),classify(node.right,depth+1)]);case"NewExpression":return globalPath(node.callee,scope)==="Date"?"predictable":"unknown";case"MemberExpression":return opaque([classify(node.object,depth+1)]);case"CallExpression":return classifyCall(node,scope,depth);case"Identifier":{const init=(0,tool_registration_1.constInitializer)(node,scope);if(init===void 0)return"unknown";if(!insideFunction(init))return"constant";return classify(init,depth+1)}default:return"unknown"}}function classifyCall(node,scope,depth){const args=node.arguments.map(arg=>classify(arg,depth+1));const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding!==void 0){const exported=binding.path.join(".");return CSPRNG_EXPORTS.get(binding.module)?.has(exported)?"csprng":opaque(args)}const global=globalPath(node.callee,scope);if(global!==null){if(GLOBAL_CSPRNG.has(global))return"csprng";if(PREDICTABLE_GLOBALS.has(global))return"predictable";if(DERIVING_GLOBALS.has(global))return combine(args);return opaque(args)}if(node.callee.type==="MemberExpression"){const receiver=classify(node.callee.object,depth+1);const method=(0,eslint_devkit_1.propertyName)(node.callee);if(method!==null&&DERIVING_METHODS.has(method))return combine([receiver,...args]);return opaque([receiver,...args])}const helper=(0,tool_registration_1.resolveFunction)(node.callee,scope);if(helper===void 0)return opaque(args);return combine((0,value_flow_1.returnedExpressions)(helper).map(e=>classify(e,depth+1)))}function check(written){const value=(0,eslint_devkit_1.unwrapTypeSyntax)(written);const scope=sourceCode.getScope(value);if(value.type==="MemberExpression"){const global=globalPath(value,scope);if(global!==null&&PREDICTABLE_GLOBALS.has(global))context.report({node:value,messageId:"predictableSessionId"});return}const fn=(0,tool_registration_1.resolveFunction)(value,scope);if(fn===void 0)return;const returned=(0,value_flow_1.returnedExpressions)(fn);if(returned.length===0)return;const kind=combine(returned.map(expression=>classify(expression,0)));if(kind==="predictable")context.report({node:value,messageId:"predictableSessionId"});else if(kind==="constant")context.report({node:value,messageId:"constantSessionId"})}return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;return true},NewExpression(node){const transport=(0,tool_handlers_1.mcpExport)(node.callee,sourceCode.getScope(node));if(transport===void 0||!STREAMABLE_TRANSPORTS.has(transport))return;const options=(0,eslint_devkit_1.unwrapTypeSyntax)(node.arguments[0]);if(options?.type!=="ObjectExpression")return;let generator;for(const prop of options.properties){if(prop.type==="SpreadElement")return;const key=(0,tool_registration_1.propertyKey)(prop);if(key===void 0)return;if(key==="sessionIdGenerator")generator=prop.value}if(generator!==void 0)check(generator)}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSharedStatelessTransport=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const instances_1=require("../../utils/instances");const mcp_evidence_1=require("../../utils/mcp-evidence");const tool_handlers_1=require("../../utils/tool-handlers");const tool_registration_1=require("../../utils/tool-registration");const STREAMABLE_TRANSPORTS=new Set(["StreamableHTTPServerTransport","NodeStreamableHTTPServerTransport","WebStandardStreamableHTTPServerTransport"]);const SERVER_CLASSES=new Set(["McpServer","Server"]);const ADVISORY="https://nvd.nist.gov/vuln/detail/CVE-2026-25536";function ownerOf(node){for(let current=node.parent;current;current=current.parent){if((0,tool_registration_1.isFunctionNode)(current)||current.type==="PropertyDefinition")return current}return void 0}function contains(owner,node){for(let current=node;current;current=current.parent){if(current===owner)return true}return false}exports.noSharedStatelessTransport=(0,eslint_devkit_1.createRule)({name:"no-shared-stateless-transport",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-shared-stateless-transport.md",description:"Disallow sharing one stateless Streamable HTTP transport or one MCP server across requests",cwe:"CWE-488",cvss:7.5},messages:{statelessTransportAtModuleLevel:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Stateless MCP Transport Shared Across Requests",cwe:"CWE-488",owasp:"A04:2021",cvss:7.5,description:"This stateless `{{transport}}` is created once at module level, so every request goes through one transport with no session to key responses by; JSON-RPC IDs from different clients collide and one client receives another's responses (CVE-2026-25536)",severity:"HIGH",compliance:["SOC2","GDPR"],fix:"Create the server and the transport inside the request handler, per request, and close both when the response closes, or switch to stateful mode with `sessionIdGenerator: () => randomUUID()` and a transport per session.",documentationLink:ADVISORY}),sharedServerAcrossRequests:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Server Shared Across Stateless Requests",cwe:"CWE-488",owasp:"A04:2021",cvss:7.5,description:"A per-request stateless transport is connected to an `{{server}}` built outside this handler, so one server instance serves every request and responses can be delivered to the wrong client (CVE-2026-25536)",severity:"HIGH",compliance:["SOC2","GDPR"],fix:"Build the server per request as well: call a `getServer()` factory (or `new McpServer(...)`) inside the handler, connect it to the new transport, and close both when the response closes.",documentationLink:ADVISORY})},schema:[]},defaultOptions:[],createOnce(context){let sourceCode;let builtBy;let perRequest;let connects;function isStateless(node){const options=node.arguments[0];if(options===void 0)return true;if(options.type!=="ObjectExpression")return false;let generator;for(const prop of options.properties){if(prop.type==="SpreadElement")return false;const key=(0,tool_registration_1.propertyKey)(prop);if(key===void 0)return false;if(key==="sessionIdGenerator")generator=prop.value}if(generator===void 0)return true;return generator.type==="Identifier"&&generator.name==="undefined"&&!(0,tool_registration_1.lookupVariable)("undefined",sourceCode.getScope(generator))?.defs.length}return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;builtBy=(0,instances_1.createInstanceResolver)(context);perRequest=new Map;connects=[];return true},NewExpression(node){const transport=(0,tool_handlers_1.mcpExport)(node.callee,sourceCode.getScope(node));if(transport===void 0||!STREAMABLE_TRANSPORTS.has(transport))return;if(!isStateless(node))return;const owner=ownerOf(node);if(owner===void 0){context.report({node,messageId:"statelessTransportAtModuleLevel",data:{transport}});return}perRequest.set(node,owner)},CallExpression(node){if(node.callee.type!=="MemberExpression")return;if((0,eslint_devkit_1.propertyName)(node.callee)!=="connect")return;connects.push(node)},"Program:exit"(){for(const call of connects){const arg=call.arguments[0];if(arg===void 0)continue;const transport=builtBy(arg);const owner=transport&&perRequest.get(transport.call);if(owner===void 0)continue;const server=builtBy(call.callee.object);if(server===void 0||!(0,mcp_evidence_1.isMcpModule)(server.module))continue;const name=server.path[server.path.length-1];if(!SERVER_CLASSES.has(name))continue;if(contains(owner,server.call))continue;context.report({node:call,messageId:"sharedServerAcrossRequests",data:{server:name}})}}}}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSharedStatelessTransport=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const instances_1=require("../../utils/instances");const mcp_evidence_1=require("../../utils/mcp-evidence");const tool_handlers_1=require("../../utils/tool-handlers");const tool_registration_1=require("../../utils/tool-registration");const STREAMABLE_TRANSPORTS=new Set(["StreamableHTTPServerTransport","NodeStreamableHTTPServerTransport","WebStandardStreamableHTTPServerTransport"]);const SERVER_CLASSES=new Set(["McpServer","Server"]);const ADVISORY="https://nvd.nist.gov/vuln/detail/CVE-2026-25536";function ownerOf(node){for(let current=node.parent;current;current=current.parent){if((0,tool_registration_1.isFunctionNode)(current)||current.type==="PropertyDefinition")return current}return void 0}function contains(owner,node){for(let current=node;current;current=current.parent){if(current===owner)return true}return false}exports.noSharedStatelessTransport=(0,eslint_devkit_1.createRule)({name:"no-shared-stateless-transport",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-shared-stateless-transport.md",description:"Disallow sharing one stateless Streamable HTTP transport or one MCP server across requests",cwe:"CWE-488",cvss:7.5},messages:{statelessTransportAtModuleLevel:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Stateless MCP Transport Shared Across Requests",cwe:"CWE-488",owasp:"A04:2021",cvss:7.5,description:"This stateless `{{transport}}` is created once at module level, so every request goes through one transport with no session to key responses by; JSON-RPC IDs from different clients collide and one client receives another's responses (CVE-2026-25536)",severity:"HIGH",compliance:["SOC2","GDPR"],fix:"Create the server and the transport inside the request handler, per request, and close both when the response closes, or switch to stateful mode with `sessionIdGenerator: () => randomUUID()` and a transport per session.",documentationLink:ADVISORY}),sharedServerAcrossRequests:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Server Shared Across Stateless Requests",cwe:"CWE-488",owasp:"A04:2021",cvss:7.5,description:"A per-request stateless transport is connected to an `{{server}}` built outside this handler, so one server instance serves every request and responses can be delivered to the wrong client (CVE-2026-25536)",severity:"HIGH",compliance:["SOC2","GDPR"],fix:"Build the server per request as well: call a `getServer()` factory (or `new McpServer(...)`) inside the handler, connect it to the new transport, and close both when the response closes.",documentationLink:ADVISORY})},schema:[]},defaultOptions:[],createOnce(context){let sourceCode;let builtBy;let perRequest;let connects;function isStateless(node){const options=(0,eslint_devkit_1.unwrapTypeSyntax)(node.arguments[0]);if(options===void 0)return true;if(options.type!=="ObjectExpression")return false;let generator;for(const prop of options.properties){if(prop.type==="SpreadElement")return false;const key=(0,tool_registration_1.propertyKey)(prop);if(key===void 0)return false;if(key==="sessionIdGenerator")generator=prop.value}if(generator===void 0)return true;return generator.type==="Identifier"&&generator.name==="undefined"&&!(0,tool_registration_1.lookupVariable)("undefined",sourceCode.getScope(generator))?.defs.length}return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;builtBy=(0,instances_1.createInstanceResolver)(context);perRequest=new Map;connects=[];return true},NewExpression(node){const transport=(0,tool_handlers_1.mcpExport)(node.callee,sourceCode.getScope(node));if(transport===void 0||!STREAMABLE_TRANSPORTS.has(transport))return;if(!isStateless(node))return;const owner=ownerOf(node);if(owner===void 0){context.report({node,messageId:"statelessTransportAtModuleLevel",data:{transport}});return}perRequest.set(node,owner)},CallExpression(node){if(node.callee.type!=="MemberExpression")return;if((0,eslint_devkit_1.propertyName)(node.callee)!=="connect")return;connects.push(node)},"Program:exit"(){for(const call of connects){const arg=call.arguments[0];if(arg===void 0)continue;const transport=builtBy(arg);const owner=transport&&perRequest.get(transport.call);if(owner===void 0)continue;const server=builtBy(call.callee.object);if(server===void 0||!(0,mcp_evidence_1.isMcpModule)(server.module))continue;const name=server.path[server.path.length-1];if(!SERVER_CLASSES.has(name))continue;if(contains(owner,server.call))continue;context.report({node:call,messageId:"sharedServerAcrossRequests",data:{server:name}})}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUntrustedToolMetadataInPrompt=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const instances_1=require("../../utils/instances");const mcp_evidence_1=require("../../utils/mcp-evidence");const tool_registration_1=require("../../utils/tool-registration");const value_flow_1=require("../../utils/value-flow");const LISTINGS=new Set(["listTools","listPrompts","listResources","listResourceTemplates"]);const ELEMENT_CALLBACKS=new Set(["map","flatMap","filter","forEach","find","some","every"]);const MAPPERS=new Set(["map","flatMap"]);const SELECTORS=new Set(["filter","find","slice","concat","reverse","sort","flat"]);const ELEMENT={toArgs:[],closed:new Set};const OBJECT_SPREADERS=new Set(["values","entries"]);const LLM_CLIENTS={"@anthropic-ai/sdk":new Set(["","Anthropic","default"]),openai:new Set(["","OpenAI","AzureOpenAI","default"]),"@google/genai":new Set(["GoogleGenAI"])};const LLM_METHODS=new Set(["create","stream","parse","generateContent","generateContentStream"]);const AI_SDK_FUNCTIONS=new Set(["generateText","streamText","generateObject","streamObject"]);const TOOL_FIELDS=new Set(["tools","functions","toolChoice","tool_choice"]);function llmCallOf(node,scope,builtBy){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding?.module==="ai"&&AI_SDK_FUNCTIONS.has(binding.path.join(".")))return binding.path.join(".");if(node.callee.type!=="MemberExpression")return void 0;const method=(0,eslint_devkit_1.propertyName)(node.callee);if(method===null||!LLM_METHODS.has(method))return void 0;let receiver=node.callee.object;const path=[method];while(receiver.type==="MemberExpression"){path.unshift((0,eslint_devkit_1.propertyName)(receiver)??"?");receiver=receiver.object}const client=builtBy(receiver);return client!==void 0&&LLM_CLIENTS[client.module]?.has(client.path.join("."))===true?`${client.module} ${path.join(".")}`:void 0}exports.noUntrustedToolMetadataInPrompt=(0,eslint_devkit_1.createRule)({name:"no-untrusted-tool-metadata-in-prompt",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-untrusted-tool-metadata-in-prompt.md",description:"Disallow an MCP client writing a server's tool, prompt or resource metadata into an LLM prompt instead of its tool definitions",cwe:"CWE-1427",cvss:8.6},messages:{toolMetadataInPrompt:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Server Metadata Written into a Prompt",cwe:"CWE-1427",owasp:"A03:2021",cvss:8.6,description:"`{{source}}` \u2014 text an MCP server supplied about itself \u2014 reaches the `{{field}}` of `{{sink}}`, so a malicious or compromised MCP server writes instructions with the authority of this host\u2019s own prompt (tool poisoning)",severity:"HIGH",compliance:["SOC2"],fix:"Pass the server\u2019s tools through the LLM API\u2019s `tools` parameter (name, description, input schema) rather than writing them into `system` or a message. Pin and review tool descriptions per server, and show changes to the user before they reach the model.",documentationLink:"https://modelcontextprotocol.io/specification/2025-06-18/basic/security_best_practices"})},schema:[]},defaultOptions:[],createOnce(context){let sourceCode;let builtBy;let sinks;return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;builtBy=(0,instances_1.createInstanceResolver)(context);sinks=[];return true},CallExpression(node){const sink=llmCallOf(node,sourceCode.getScope(node),builtBy);if(sink!==void 0)sinks.push({call:node,sink})},"Program:exit"(){const mappers=new Set;const callbackRoot=fn=>{if(mappers.has(fn))return ELEMENT;const call=fn.parent;if(call?.type!=="CallExpression"||call.arguments[0]!==fn||call.callee.type!=="MemberExpression"||!ELEMENT_CALLBACKS.has((0,eslint_devkit_1.propertyName)(call.callee)??""))return void 0;return carries(call.callee.object)?ELEMENT:void 0};const carries=(0,value_flow_1.createFlow)(sourceCode,callbackRoot,(node,follow)=>{if(node.type==="Identifier"){const def=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node))?.defs[0];const loop=def?.parent?.parent;if(def?.type!=="Variable"||loop?.type!=="ForOfStatement"||loop.left!==def.parent)return void 0;const iterated=follow(loop.right);if(iterated===null)return null;const element=iterated.kind==="value"?iterated:{kind:"value",text:iterated.text,key:void 0};return(0,value_flow_1.throughPattern)(def.node.id,def.name,element)}if(node.type!=="CallExpression")return void 0;const callee=node.callee;if(callee.type!=="MemberExpression")return void 0;const method=(0,eslint_devkit_1.propertyName)(callee);if(method===null)return void 0;if(LISTINGS.has(method)){const client=builtBy(callee.object);return client!==void 0&&(0,mcp_evidence_1.isMcpModule)(client.module)&&client.path[client.path.length-1]==="Client"?{kind:"object",text:`${sourceCode.getText(callee.object)}.${method}()`,toArgs:[]}:void 0}if(OBJECT_SPREADERS.has(method)&&callee.object.type==="Identifier"&&callee.object.name==="Object"&&!(0,tool_registration_1.lookupVariable)("Object",sourceCode.getScope(node))?.defs.length){const arg=node.arguments[0];return arg===void 0?null:follow(arg)}const receiver=MAPPERS.has(method)||SELECTORS.has(method)?follow(callee.object):null;if(receiver===null)return void 0;if(SELECTORS.has(method))return receiver;const fn=(0,tool_registration_1.resolveFunction)(node.arguments[0],sourceCode.getScope(node));if(fn===void 0)return null;mappers.add(fn);for(const expression of(0,value_flow_1.returnedExpressions)(fn)){const t=follow(expression);if(t?.kind==="value")return t}return null},(0,value_flow_1.flowOptionsFor)(context));const taintIn=(node,depth)=>{if(depth>8)return null;if(node.type==="ObjectExpression"){for(const prop of node.properties){const value=prop.type==="Property"?prop.value:prop.argument;const found=taintIn(value,depth+1);if(found)return found}return null}if(node.type==="ArrayExpression"){for(const element of node.elements){const found=element&&taintIn(element,depth+1);if(found)return found}return null}if(node.type==="Identifier"){const def=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node))?.defs[0];const init=def?.type==="Variable"?def.node.init:null;if(init?.type==="ObjectExpression"||init?.type==="ArrayExpression")return taintIn(init,depth+1)}const taint=carries(node);return taint?.kind==="value"?{node,taint}:null};for(const{call,sink}of sinks){const options=call.arguments[0];if(options?.type!=="ObjectExpression")continue;for(const prop of options.properties){if(prop.type!=="Property")continue;const field=(0,eslint_devkit_1.objectKeyName)(prop);if(field===null||TOOL_FIELDS.has(field))continue;const found=taintIn(prop.value,0);if(found===null)continue;context.report({node:found.node,messageId:"toolMetadataInPrompt",data:{source:found.taint.text,field,sink}})}}}}}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUntrustedToolMetadataInPrompt=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const instances_1=require("../../utils/instances");const mcp_evidence_1=require("../../utils/mcp-evidence");const tool_registration_1=require("../../utils/tool-registration");const value_flow_1=require("../../utils/value-flow");const LISTINGS=new Set(["listTools","listPrompts","listResources","listResourceTemplates"]);const ELEMENT_CALLBACKS=new Set(["map","flatMap","filter","forEach","find","some","every"]);const MAPPERS=new Set(["map","flatMap"]);const SELECTORS=new Set(["filter","find","slice","concat","reverse","sort","flat"]);const ELEMENT={toArgs:[],closed:new Set};const OBJECT_SPREADERS=new Set(["values","entries"]);const LLM_CLIENTS={"@anthropic-ai/sdk":new Set(["","Anthropic","default"]),openai:new Set(["","OpenAI","AzureOpenAI","default"]),"@google/genai":new Set(["GoogleGenAI"])};const LLM_METHODS=new Set(["create","stream","parse","generateContent","generateContentStream"]);const AI_SDK_FUNCTIONS=new Set(["generateText","streamText","generateObject","streamObject"]);const TOOL_FIELDS=new Set(["tools","functions","toolChoice","tool_choice"]);function llmCallOf(node,scope,builtBy){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding?.module==="ai"&&AI_SDK_FUNCTIONS.has(binding.path.join(".")))return binding.path.join(".");if(node.callee.type!=="MemberExpression")return void 0;const method=(0,eslint_devkit_1.propertyName)(node.callee);if(method===null||!LLM_METHODS.has(method))return void 0;let receiver=node.callee.object;const path=[method];while(receiver.type==="MemberExpression"){path.unshift((0,eslint_devkit_1.propertyName)(receiver)??"?");receiver=receiver.object}const client=builtBy(receiver);return client!==void 0&&LLM_CLIENTS[client.module]?.has(client.path.join("."))===true?`${client.module} ${path.join(".")}`:void 0}exports.noUntrustedToolMetadataInPrompt=(0,eslint_devkit_1.createRule)({name:"no-untrusted-tool-metadata-in-prompt",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-mcp-sdk-security/docs/rules/no-untrusted-tool-metadata-in-prompt.md",description:"Disallow an MCP client writing a server's tool, prompt or resource metadata into an LLM prompt instead of its tool definitions",cwe:"CWE-1427",cvss:8.6},messages:{toolMetadataInPrompt:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Server Metadata Written into a Prompt",cwe:"CWE-1427",owasp:"A03:2021",cvss:8.6,description:"`{{source}}` \u2014 text an MCP server supplied about itself \u2014 reaches the `{{field}}` of `{{sink}}`, so a malicious or compromised MCP server writes instructions with the authority of this host\u2019s own prompt (tool poisoning)",severity:"HIGH",compliance:["SOC2"],fix:"Pass the server\u2019s tools through the LLM API\u2019s `tools` parameter (name, description, input schema) rather than writing them into `system` or a message. Pin and review tool descriptions per server, and show changes to the user before they reach the model.",documentationLink:"https://modelcontextprotocol.io/specification/2025-06-18/basic/security_best_practices"})},schema:[]},defaultOptions:[],createOnce(context){let sourceCode;let builtBy;let sinks;return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;builtBy=(0,instances_1.createInstanceResolver)(context);sinks=[];return true},CallExpression(node){const sink=llmCallOf(node,sourceCode.getScope(node),builtBy);if(sink!==void 0)sinks.push({call:node,sink})},"Program:exit"(){const mappers=new Set;const callbackRoot=fn=>{if(mappers.has(fn))return ELEMENT;const call=fn.parent;if(call?.type!=="CallExpression"||call.arguments[0]!==fn||call.callee.type!=="MemberExpression"||!ELEMENT_CALLBACKS.has((0,eslint_devkit_1.propertyName)(call.callee)??""))return void 0;return carries(call.callee.object)?ELEMENT:void 0};const isGlobalJson=node=>{const[root,name]=node.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(node)==="JSON"?[node.object,"globalThis"]:[node,"JSON"];return root.type==="Identifier"&&root.name===name&&!(0,tool_registration_1.lookupVariable)(name,sourceCode.getScope(root))?.defs.length};const carries=(0,value_flow_1.createFlow)(sourceCode,callbackRoot,(node,follow)=>{if(node.type==="Identifier"){const def=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node))?.defs[0];const loop=def?.parent?.parent;if(def?.type!=="Variable"||loop?.type!=="ForOfStatement"||loop.left!==def.parent)return void 0;const iterated=follow(loop.right);if(iterated===null)return null;const element=iterated.kind==="value"?iterated:{kind:"value",text:iterated.text,key:void 0};return(0,value_flow_1.throughPattern)(def.node.id,def.name,element)}if(node.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(node)==="length"&&follow(node.object)!==null)return null;if(node.type!=="CallExpression")return void 0;const callee=node.callee;if(callee.type!=="MemberExpression")return void 0;const method=(0,eslint_devkit_1.propertyName)(callee);if(method===null)return void 0;if(method==="stringify"&&isGlobalJson(callee.object)){const[arg,replacer]=node.arguments;if(arg===void 0||(0,tool_registration_1.isFunctionNode)(replacer))return null;const parts=arg.type==="ObjectExpression"?arg.properties.map(p=>p.type==="Property"?p.value:p.argument):arg.type==="ArrayExpression"?arg.elements:[arg];for(const part of parts){const listed=part&&follow(part);if(listed)return{kind:"value",text:listed.text,key:void 0}}return null}if(LISTINGS.has(method)){const client=builtBy(callee.object);return client!==void 0&&(0,mcp_evidence_1.isMcpModule)(client.module)&&client.path[client.path.length-1]==="Client"?{kind:"object",text:`${sourceCode.getText(callee.object)}.${method}()`,toArgs:[]}:void 0}if(OBJECT_SPREADERS.has(method)&&callee.object.type==="Identifier"&&callee.object.name==="Object"&&!(0,tool_registration_1.lookupVariable)("Object",sourceCode.getScope(node))?.defs.length){const arg=node.arguments[0];return arg===void 0?null:follow(arg)}const receiver=MAPPERS.has(method)||SELECTORS.has(method)?follow(callee.object):null;if(receiver===null)return void 0;if(SELECTORS.has(method))return receiver;const fn=(0,tool_registration_1.resolveFunction)(node.arguments[0],sourceCode.getScope(node));if(fn===void 0)return null;mappers.add(fn);for(const expression of(0,value_flow_1.returnedExpressions)(fn)){const t=follow(expression);if(t?.kind==="value")return t}return null},(0,value_flow_1.flowOptionsFor)(context));const taintIn=(node,depth)=>{if(depth>8)return null;if(node.type==="ObjectExpression"){for(const prop of node.properties){const value=prop.type==="Property"?prop.value:prop.argument;const found=taintIn(value,depth+1);if(found)return found}return null}if(node.type==="ArrayExpression"){for(const element of node.elements){const found=element&&taintIn(element,depth+1);if(found)return found}return null}if(node.type==="Identifier"){const def=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node))?.defs[0];const init=def?.type==="Variable"?def.node.init:null;if(init?.type==="ObjectExpression"||init?.type==="ArrayExpression")return taintIn(init,depth+1)}const taint=carries(node);return taint?.kind==="value"?{node,taint}:null};for(const{call,sink}of sinks){const options=call.arguments[0];if(options?.type!=="ObjectExpression")continue;for(const prop of options.properties){if(prop.type!=="Property")continue;const field=(0,eslint_devkit_1.objectKeyName)(prop);if(field===null||TOOL_FIELDS.has(field))continue;const found=taintIn(prop.value,0);if(found===null)continue;context.report({node:found.node,messageId:"toolMetadataInPrompt",data:{source:found.taint.text,field,sink}})}}}}}});
|