eslint-plugin-mcp-sdk-security 2.0.2 → 2.1.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-mcp-sdk-security",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "ESLint MCP security rules for the Model Context Protocol SDK — 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
|
"sideEffects": false,
|
|
@@ -67,7 +67,15 @@
|
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"eslint": "^8.40.0 || ^9.0.0 || ^10.0.0",
|
|
70
|
-
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
70
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
71
|
+
"@modelcontextprotocol/server": "^2.0.0",
|
|
72
|
+
"@modelcontextprotocol/client": "^2.0.0",
|
|
73
|
+
"@modelcontextprotocol/core": "^2.0.0",
|
|
74
|
+
"@modelcontextprotocol/node": "^2.0.0",
|
|
75
|
+
"@modelcontextprotocol/express": "^2.0.0",
|
|
76
|
+
"@modelcontextprotocol/hono": "^2.0.0",
|
|
77
|
+
"@modelcontextprotocol/fastify": "^2.0.0",
|
|
78
|
+
"@modelcontextprotocol/server-legacy": "^2.0.0"
|
|
71
79
|
},
|
|
72
80
|
"peerDependenciesMeta": {
|
|
73
81
|
"eslint": {
|
|
@@ -75,6 +83,30 @@
|
|
|
75
83
|
},
|
|
76
84
|
"@modelcontextprotocol/sdk": {
|
|
77
85
|
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@modelcontextprotocol/server": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@modelcontextprotocol/client": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@modelcontextprotocol/core": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"@modelcontextprotocol/node": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"@modelcontextprotocol/express": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
"@modelcontextprotocol/hono": {
|
|
103
|
+
"optional": true
|
|
104
|
+
},
|
|
105
|
+
"@modelcontextprotocol/fastify": {
|
|
106
|
+
"optional": true
|
|
107
|
+
},
|
|
108
|
+
"@modelcontextprotocol/server-legacy": {
|
|
109
|
+
"optional": true
|
|
78
110
|
}
|
|
79
111
|
},
|
|
80
112
|
"dependencies": {
|
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:"2.0
|
|
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.1.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.requireHttpTransportHardening=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 module_resolver_1=require("../../utils/module-resolver");const tool_handlers_1=require("../../utils/tool-handlers");const guards_1=require("../../utils/guards");const tool_registration_1=require("../../utils/tool-registration");const HTTP_TRANSPORTS=new Map([["StreamableHTTPServerTransport",0],["SSEServerTransport",2],["NodeStreamableHTTPServerTransport",0],["WebStandardStreamableHTTPServerTransport",0]]);const TRANSPORT_OPTION_PACKAGES=["@modelcontextprotocol/sdk","@modelcontextprotocol/server-legacy"];const MCP_APP_FACTORIES=new Set(["createMcpExpressApp","createMcpHonoApp","createMcpFastifyApp"]);const RAW_APPS={express:"",hono:"Hono",fastify:""};const ROUTE_METHODS=new Set(["get","post","put","patch","delete","all","route","on"]);const HOST_VALIDATORS=new Set(["hostHeaderValidation","localhostHostValidation"]);const AUTH_EXPORTS=new Set(["requireBearerAuth","mcpAuthRouter","mcpAuthMetadataRouter"]);const LOOPBACK_HOSTS=new Set(["127.0.0.1","localhost","::1"]);const DEFAULT_ALL_INTERFACES={express:"",http:"createServer",https:"createServer"};const DEFAULT_LISTEN_HOST="::";const REQUEST_HEADER_READS=new Set(["headers","header","get"]);const ALL_INTERFACE_HOSTS=new Set(["0.0.0.0","::"]);const TRANSPORT_SECURITY_DOCS="https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#security-warning";exports.requireHttpTransportHardening=(0,eslint_devkit_1.createRule)({name:"require-http-transport-hardening",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/require-http-transport-hardening.md",description:"Require an MCP HTTP server transport to validate the Host header and a network-reachable MCP server to authenticate its callers",cwe:"CWE-346",cvss:8.1},messages:{missingRebindingProtection:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP HTTP Transport Without DNS-Rebinding Protection",cwe:"CWE-346",owasp:"A05:2021",cvss:8.1,description:"`{{transport}}` is built without `enableDnsRebindingProtection: true` and a non-empty `allowedHosts`, and nothing in this file validates the Host header, so a web page the user opens can rebind its hostname to this server and call its tools",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Pass `enableDnsRebindingProtection: true, allowedHosts: ['127.0.0.1:3000', 'localhost:3000']` (the exact Host header values clients send; the transport compares them with the port), or serve the transport from `createMcpExpressApp()` or behind `hostHeaderValidation([...])`.",documentationLink:TRANSPORT_SECURITY_DOCS}),appWithoutHostValidation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP App Without Host Validation",cwe:"CWE-346",owasp:"A05:2021",cvss:8.1,description:"This {{framework}} app serves an SDK v2 MCP transport and nothing in this file validates the Host header \u2014 v2 transports leave DNS-rebinding protection to the app \u2014 so a web page the user opens can rebind its hostname to this server and call its tools",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Build the app with `createMcpExpressApp()` / `createMcpHonoApp()` (localhost validation by default, `allowedHosts` for other hosts), or mount `hostHeaderValidation(['mcp.example.com'])` / `localhostHostValidation()` before the MCP route.",documentationLink:TRANSPORT_SECURITY_DOCS}),allInterfacesWithoutAllowedHosts:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Express App on All Interfaces Without allowedHosts",cwe:"CWE-346",owasp:"A05:2021",cvss:8.1,description:"`{{factory}}({ host: '{{host}}' })` binds every interface and, with no `allowedHosts`, installs no Host validation; the SDK only logs a warning",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Pass `allowedHosts: ['mcp.example.com']` with the host names clients use, or bind to `127.0.0.1` when the server is local-only.",documentationLink:TRANSPORT_SECURITY_DOCS}),missingAuth:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Network-Reachable MCP Server Without Authentication",cwe:"CWE-306",owasp:"A05:2021",cvss:8.1,description:"This MCP HTTP server binds every interface ('{{host}}') and nothing in this file authenticates its callers (no SDK auth middleware, no custom `.use()` middleware, no middleware in front of the route that calls `handleRequest`), so anyone who can reach the port can call every tool",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Mount `requireBearerAuth({ verifier })` or your own auth middleware on the MCP route in this file (`app.post('/mcp', requireBearerAuth({ verifier }), handler)`), or bind to `127.0.0.1`.",documentationLink:"https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization"})},schema:[]},defaultOptions:[],skipTestFiles:true,createOnce(context){let sourceCode;let resolve;let builtBy;let unhardened;let constructsTransport;let servesV2;let rawApps;let validatesHost;let authenticates;let customUse;let binds;let openFactories;let handleRequestCalls;let serveCalls;function appVariables(bind){const found=[];const add=node=>{if(node?.type==="CallExpression"){for(const arg of node.arguments)add(arg);return}if(node?.type!=="Identifier")return;const variable=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node));if(variable===void 0||found.includes(variable))return;found.push(variable);const def=variable.defs[0];if(def?.type==="Variable")add(def.node.init)};if(bind.type==="CallExpression"&&bind.callee.type==="MemberExpression")add(bind.callee.object);else if(bind.parent?.type==="VariableDeclarator")add(bind.parent.id);return found}function appEscapes(bind){return appVariables(bind).some(variable=>variable.references.some(ref=>{const call=ref.identifier.parent;if(call?.type!=="CallExpression"||!call.arguments.includes(ref.identifier))return false;if((0,tool_registration_1.resolveFunction)(call.callee,sourceCode.getScope(call)))return false;const callee=(0,eslint_devkit_1.resolveModuleBinding)(call.callee,sourceCode.getScope(call));return!(callee!==void 0&&DEFAULT_ALL_INTERFACES[callee.module]===callee.path.join("."))}))}function listensOnAllByDefault(receiver){const app=builtBy(receiver);if(app===void 0)return false;if((0,mcp_evidence_1.isMcpModule)(app.module))return app.path[app.path.length-1]==="createMcpExpressApp";return DEFAULT_ALL_INTERFACES[app.module]===app.path.join(".")}function rootedAt(node,request){let current=node;while(current.type==="MemberExpression")current=current.object;return current.type==="Identifier"&&(0,tool_registration_1.lookupVariable)(current.name,sourceCode.getScope(current))===request}function readsHeader(test,request){const seen=new Set;const visit=node=>{if((0,tool_registration_1.isFunctionNode)(node)&&node.parent?.type!=="CallExpression")return false;if(node.type==="MemberExpression"&&REQUEST_HEADER_READS.has((0,eslint_devkit_1.propertyName)(node)??"")&&rootedAt(node.object,request))return true;if(node.type==="Identifier"){const variable=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node));if(variable===void 0||seen.has(variable))return false;seen.add(variable);return variable.defs.some(def=>def.type==="Variable"&&def.node.init!==null&&visit(def.node.init))}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"&&visit(child))return true}return false};return visit(test)}function gatedInline(call){const requests=[];for(let node=call.parent;node;node=node.parent){if(!(0,tool_registration_1.isFunctionNode)(node))continue;if(registrationsOf(node).some(behindSdkAuth))return true;const param=node.params[0];if(param?.type!=="Identifier")continue;requests.push(sourceCode.getDeclaredVariables(node).find(v=>v.defs[0]?.name===param))}let child=call;for(let node=call.parent;node;node=node.parent){if(node.type==="BlockStatement")for(const statement of node.body){if(statement===child)break;if(statement.type==="IfStatement"&&(0,guards_1.exits)(statement.consequent)&&requests.some(request=>readsHeader(statement.test,request)))return true}child=node}return false}function behindSdkAuth(route){return route.arguments.some(arg=>arg.type==="CallExpression"&&AUTH_EXPORTS.has((0,tool_handlers_1.mcpExport)(arg.callee,sourceCode.getScope(arg))??""))}function servedBehindCredentialCheck(){return serveCalls.length>0&&serveCalls.every(gatedInline)}function hostOf(node){return(0,eslint_devkit_1.staticString)(resolve(node))}function readOptions(node){if(node.type==="SpreadElement")return null;const object=resolve(node);if(object?.type!=="ObjectExpression")return null;const options=new Map;for(const prop of object.properties){if(prop.type==="SpreadElement")return null;const key=(0,tool_registration_1.propertyKey)(prop);if(key===void 0)return null;options.set(key,prop.value)}return options}function rebindingProtection(options){const flag=options.get("enableDnsRebindingProtection");if(flag===void 0)return"no";const value=resolve(flag);if(value?.type!=="Literal"||typeof value.value!=="boolean")return"unknown";return value.value?"yes":"no"}function nonEmptyHosts(options){const hosts=options.get("allowedHosts");if(hosts===void 0)return"no";const value=resolve(hosts);if(value?.type!=="ArrayExpression")return"unknown";return value.elements.length>0?"yes":"no"}function expressAppState(call){const arg=call.arguments[0];if(arg===void 0)return{kind:"guarded"};const options=readOptions(arg);if(options===null||options.has("allowedHosts"))return{kind:"guarded"};const hostNode=options.get("host");if(hostNode===void 0)return{kind:"guarded"};const host=hostOf(hostNode);if(host===null||LOOPBACK_HOSTS.has(host))return{kind:"guarded"};return ALL_INTERFACE_HOSTS.has(host)?{kind:"allInterfaces",host}:{kind:"other"}}function registrationsOf(fn){const parent=fn.parent;if(parent.type==="CallExpression"&&parent.arguments.includes(fn))return[parent];const declared=fn.type==="FunctionDeclaration"?fn:parent.type==="VariableDeclarator"?parent:void 0;if(declared===void 0)return[];const calls=[];for(const variable of sourceCode.getDeclaredVariables(declared)){for(const ref of variable.references){const site=ref.identifier.parent;if(site.type==="CallExpression"&&site.arguments.includes(ref.identifier))calls.push(site)}}return calls}function routeHasMiddleware(){for(const call of handleRequestCalls){for(let node=call.parent;node;node=node.parent){if(!(0,tool_registration_1.isFunctionNode)(node))continue;if(registrationsOf(node).some(route=>route.arguments.length>2))return true}}return false}function noteRawApp(node,scope){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding!==void 0&&RAW_APPS[binding.module]===binding.path.join("."))rawApps.push({node,framework:binding.module})}function registersRoute(node){const declarator=node.parent;if(declarator?.type!=="VariableDeclarator")return false;return sourceCode.getDeclaredVariables(declarator).some(variable=>variable.references.some(ref=>{const member=ref.identifier.parent;return member.type==="MemberExpression"&&member.object===ref.identifier&&member.parent.type==="CallExpression"&&member.parent.callee===member&&ROUTE_METHODS.has((0,eslint_devkit_1.propertyName)(member)??"")}))}return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;resolve=(0,module_resolver_1.valueResolverFor)(context);builtBy=(0,instances_1.createInstanceResolver)(context);unhardened=[];constructsTransport=false;servesV2=false;rawApps=[];validatesHost=false;authenticates=false;customUse=false;binds=[];openFactories=[];handleRequestCalls=[];serveCalls=[];return true},NewExpression(node){const scope=sourceCode.getScope(node);noteRawApp(node,scope);const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding===void 0||!(0,mcp_evidence_1.isMcpModule)(binding.module))return;const transport=String(binding.path[binding.path.length-1]);const index=HTTP_TRANSPORTS.get(transport);if(index===void 0)return;constructsTransport=true;if(transport==="SSEServerTransport")serveCalls.push(node);if(!TRANSPORT_OPTION_PACKAGES.some(pkg=>binding.module===pkg||binding.module.startsWith(`${pkg}/`))){servesV2=true;return}const arg=node.arguments[index];if(arg===void 0){unhardened.push({node,transport});return}const options=readOptions(arg);if(options===null)return;if(rebindingProtection(options)==="no"||nonEmptyHosts(options)==="no")unhardened.push({node,transport})},CallExpression(node){const scope=sourceCode.getScope(node);noteRawApp(node,scope);if(node.callee.type==="Identifier"){const init=(0,tool_registration_1.constInitializer)(node.callee,scope);if(init?.type==="CallExpression"&&(0,tool_handlers_1.mcpExport)(init.callee,scope)!==void 0)serveCalls.push(node)}const name=(0,tool_handlers_1.mcpExport)(node.callee,scope);if(name!==void 0){if(HOST_VALIDATORS.has(name))validatesHost=true;else if(AUTH_EXPORTS.has(name))authenticates=true;else if(name==="createMcpHandler")servesV2=true;else if(MCP_APP_FACTORIES.has(name)){const state=expressAppState(node);if(state.kind==="guarded")validatesHost=true;else if(state.kind==="allInterfaces"){openFactories.push({node,factory:name,host:state.host});binds.push({node,host:state.host})}}return}if(node.callee.type!=="MemberExpression")return;const method=(0,eslint_devkit_1.propertyName)(node.callee);if(method==="use"){if(node.arguments.some(arg=>arg.type==="Identifier"||(0,tool_registration_1.isFunctionNode)(arg)))customUse=true}else if(method==="handleRequest"){handleRequestCalls.push(node);serveCalls.push(node)}else if(method==="handlePostMessage"){serveCalls.push(node)}else if(method==="listen"){const[first,second]=node.arguments;const options=first?.type==="ObjectExpression"?readOptions(first):null;const hostNode=first?.type==="ObjectExpression"?options?.get("host"):second!==void 0&&!(0,tool_registration_1.isFunctionNode)(second)?second:void 0;const host=hostNode===void 0?null:hostOf(hostNode);if(host!==null&&ALL_INTERFACE_HOSTS.has(host))binds.push({node,host});else if(hostNode===void 0&&(first?.type!=="ObjectExpression"||options!==null)&&listensOnAllByDefault(node.callee.object))binds.push({node,host:DEFAULT_LISTEN_HOST})}},"Program:exit"(){const gated=servedBehindCredentialCheck();if(!gated)for(const{node,factory,host}of openFactories)context.report({node,messageId:"allInterfacesWithoutAllowedHosts",data:{factory,host}});if(!validatesHost&&!gated){for(const{node,transport}of unhardened)context.report({node,messageId:"missingRebindingProtection",data:{transport}});if(servesV2){for(const{node,framework}of rawApps)if(registersRoute(node))context.report({node,messageId:"appWithoutHostValidation",data:{framework}})}}if(!constructsTransport||binds.length===0||authenticates||gated||customUse||routeHasMiddleware())return;for(const{node,host}of binds)if(!appEscapes(node))context.report({node,messageId:"missingAuth",data:{host}})}}}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireHttpTransportHardening=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 module_resolver_1=require("../../utils/module-resolver");const tool_handlers_1=require("../../utils/tool-handlers");const guards_1=require("../../utils/guards");const tool_registration_1=require("../../utils/tool-registration");const HTTP_TRANSPORTS=new Map([["StreamableHTTPServerTransport",0],["SSEServerTransport",2],["NodeStreamableHTTPServerTransport",0],["WebStandardStreamableHTTPServerTransport",0]]);const TRANSPORT_OPTION_PACKAGES=["@modelcontextprotocol/sdk","@modelcontextprotocol/server-legacy"];const MCP_APP_FACTORIES=new Set(["createMcpExpressApp","createMcpHonoApp","createMcpFastifyApp"]);const RAW_APPS={express:"",hono:"Hono",fastify:""};const ROUTE_METHODS=new Set(["get","post","put","patch","delete","all","route","on"]);const HOST_VALIDATORS=new Set(["hostHeaderValidation","localhostHostValidation"]);const AUTH_EXPORTS=new Set(["requireBearerAuth","mcpAuthRouter","mcpAuthMetadataRouter"]);const LOOPBACK_HOSTS=new Set(["127.0.0.1","localhost","::1"]);const DEFAULT_ALL_INTERFACES={express:"",http:"createServer",https:"createServer"};const OPTIONS_SERVERS={"@hono/node-server":"serve"};const DEFAULT_LISTEN_HOST="::";const REQUEST_HEADER_READS=new Set(["headers","header","get"]);const ALL_INTERFACE_HOSTS=new Set(["0.0.0.0","::"]);const TRANSPORT_SECURITY_DOCS="https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#security-warning";exports.requireHttpTransportHardening=(0,eslint_devkit_1.createRule)({name:"require-http-transport-hardening",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/require-http-transport-hardening.md",description:"Require an MCP HTTP server transport to validate the Host header and a network-reachable MCP server to authenticate its callers",cwe:"CWE-346",cvss:8.1},messages:{missingRebindingProtection:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP HTTP Transport Without DNS-Rebinding Protection",cwe:"CWE-346",owasp:"A05:2021",cvss:8.1,description:"`{{transport}}` is built without `enableDnsRebindingProtection: true` and a non-empty `allowedHosts`, and nothing in this file validates the Host header, so a web page the user opens can rebind its hostname to this server and call its tools",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Pass `enableDnsRebindingProtection: true, allowedHosts: ['127.0.0.1:3000', 'localhost:3000']` (the exact Host header values clients send; the transport compares them with the port), or serve the transport from `createMcpExpressApp()` or behind `hostHeaderValidation([...])`.",documentationLink:TRANSPORT_SECURITY_DOCS}),appWithoutHostValidation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP App Without Host Validation",cwe:"CWE-346",owasp:"A05:2021",cvss:8.1,description:"This {{framework}} app serves an SDK v2 MCP transport and nothing in this file validates the Host header \u2014 v2 transports leave DNS-rebinding protection to the app \u2014 so a web page the user opens can rebind its hostname to this server and call its tools",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Build the app with `createMcpExpressApp()` / `createMcpHonoApp()` (localhost validation by default, `allowedHosts` for other hosts), or mount `hostHeaderValidation(['mcp.example.com'])` / `localhostHostValidation()` before the MCP route.",documentationLink:TRANSPORT_SECURITY_DOCS}),allInterfacesWithoutAllowedHosts:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MCP Express App on All Interfaces Without allowedHosts",cwe:"CWE-346",owasp:"A05:2021",cvss:8.1,description:"`{{factory}}({ host: '{{host}}' })` binds every interface and, with no `allowedHosts`, installs no Host validation; the SDK only logs a warning",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Pass `allowedHosts: ['mcp.example.com']` with the host names clients use, or bind to `127.0.0.1` when the server is local-only.",documentationLink:TRANSPORT_SECURITY_DOCS}),missingAuth:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Network-Reachable MCP Server Without Authentication",cwe:"CWE-306",owasp:"A05:2021",cvss:8.1,description:"This MCP HTTP server binds every interface ('{{host}}') and nothing in this file authenticates its callers (no SDK auth middleware, no custom `.use()` middleware, no middleware in front of the route that calls `handleRequest`), so anyone who can reach the port can call every tool",severity:"HIGH",compliance:["SOC2","NIST-CSF"],fix:"Mount `requireBearerAuth({ verifier })` or your own auth middleware on the MCP route in this file (`app.post('/mcp', requireBearerAuth({ verifier }), handler)`), or bind to `127.0.0.1`.",documentationLink:"https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization"})},schema:[]},defaultOptions:[],skipTestFiles:true,createOnce(context){let sourceCode;let resolve;let builtBy;let unhardened;let constructsTransport;let servesV2;let rawApps;let validatesHost;let authenticates;let customUse;let binds;let openFactories;let handleRequestCalls;let serveCalls;function appVariables(bind){const found=[];const add=node=>{if(node?.type==="CallExpression"){for(const arg of node.arguments)add(arg);return}if(node?.type!=="Identifier")return;const variable=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node));if(variable===void 0||found.includes(variable))return;found.push(variable);const def=variable.defs[0];if(def?.type==="Variable")add(def.node.init)};if(bind.type==="CallExpression"&&bind.callee.type==="MemberExpression")add(bind.callee.object);else if(bind.parent?.type==="VariableDeclarator")add(bind.parent.id);if(bind.type==="CallExpression"&&bind.arguments[0]?.type==="ObjectExpression"){for(const property of bind.arguments[0].properties){if(property.type==="Property"&&(0,tool_registration_1.propertyKey)(property)==="fetch"&&property.value.type==="MemberExpression")add(property.value.object)}}return found}function appEscapes(bind){return appVariables(bind).some(variable=>variable.references.some(ref=>{const call=ref.identifier.parent;if(call?.type!=="CallExpression"||!call.arguments.includes(ref.identifier))return false;if((0,tool_registration_1.resolveFunction)(call.callee,sourceCode.getScope(call)))return false;const callee=(0,eslint_devkit_1.resolveModuleBinding)(call.callee,sourceCode.getScope(call));return!(callee!==void 0&&DEFAULT_ALL_INTERFACES[callee.module]===callee.path.join("."))}))}function listensOnAllByDefault(receiver){const app=builtBy(receiver);if(app===void 0)return false;if((0,mcp_evidence_1.isMcpModule)(app.module))return app.path[app.path.length-1]==="createMcpExpressApp";return DEFAULT_ALL_INTERFACES[app.module]===app.path.join(".")}function rootedAt(node,request){let current=node;while(current.type==="MemberExpression")current=current.object;return current.type==="Identifier"&&(0,tool_registration_1.lookupVariable)(current.name,sourceCode.getScope(current))===request}function readsHeader(test,request){const seen=new Set;const visit=node=>{if((0,tool_registration_1.isFunctionNode)(node)&&node.parent?.type!=="CallExpression")return false;if(node.type==="MemberExpression"&&REQUEST_HEADER_READS.has((0,eslint_devkit_1.propertyName)(node)??"")&&rootedAt(node.object,request))return true;if(node.type==="Identifier"){const variable=(0,tool_registration_1.lookupVariable)(node.name,sourceCode.getScope(node));if(variable===void 0||seen.has(variable))return false;seen.add(variable);return variable.defs.some(def=>def.type==="Variable"&&def.node.init!==null&&visit(def.node.init))}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"&&visit(child))return true}return false};return visit(test)}function gatedInline(call){const requests=[];for(let node=call.parent;node;node=node.parent){if(!(0,tool_registration_1.isFunctionNode)(node))continue;if(registrationsOf(node).some(behindSdkAuth))return true;const param=node.params[0];if(param?.type!=="Identifier")continue;requests.push(sourceCode.getDeclaredVariables(node).find(v=>v.defs[0]?.name===param))}let child=call;for(let node=call.parent;node;node=node.parent){if(node.type==="BlockStatement")for(const statement of node.body){if(statement===child)break;if(statement.type==="IfStatement"&&(0,guards_1.exits)(statement.consequent)&&requests.some(request=>readsHeader(statement.test,request)))return true}child=node}return false}function behindSdkAuth(route){return route.arguments.some(arg=>arg.type==="CallExpression"&&AUTH_EXPORTS.has((0,tool_handlers_1.mcpExport)(arg.callee,sourceCode.getScope(arg))??""))}function servedBehindCredentialCheck(){return serveCalls.length>0&&serveCalls.every(gatedInline)}function hostOf(node){return(0,eslint_devkit_1.staticString)(resolve(node))}function readOptions(node){if(node.type==="SpreadElement")return null;const object=resolve(node);if(object?.type!=="ObjectExpression")return null;const options=new Map;for(const prop of object.properties){if(prop.type==="SpreadElement")return null;const key=(0,tool_registration_1.propertyKey)(prop);if(key===void 0)return null;options.set(key,prop.value)}return options}function rebindingProtection(options){const flag=options.get("enableDnsRebindingProtection");if(flag===void 0)return"no";const value=resolve(flag);if(value?.type!=="Literal"||typeof value.value!=="boolean")return"unknown";return value.value?"yes":"no"}function nonEmptyHosts(options){const hosts=options.get("allowedHosts");if(hosts===void 0)return"no";const value=resolve(hosts);if(value?.type!=="ArrayExpression")return"unknown";return value.elements.length>0?"yes":"no"}function expressAppState(call){const arg=call.arguments[0];if(arg===void 0)return{kind:"guarded"};const options=readOptions(arg);if(options===null||options.has("allowedHosts"))return{kind:"guarded"};const hostNode=options.get("host");if(hostNode===void 0)return{kind:"guarded"};const host=hostOf(hostNode);if(host===null||LOOPBACK_HOSTS.has(host))return{kind:"guarded"};return ALL_INTERFACE_HOSTS.has(host)?{kind:"allInterfaces",host}:{kind:"other"}}function registrationsOf(fn){const parent=fn.parent;if(parent.type==="CallExpression"&&parent.arguments.includes(fn))return[parent];const declared=fn.type==="FunctionDeclaration"?fn:parent.type==="VariableDeclarator"?parent:void 0;if(declared===void 0)return[];const calls=[];for(const variable of sourceCode.getDeclaredVariables(declared)){for(const ref of variable.references){const site=ref.identifier.parent;if(site.type==="CallExpression"&&site.arguments.includes(ref.identifier))calls.push(site)}}return calls}function routeHasMiddleware(){for(const call of handleRequestCalls){for(let node=call.parent;node;node=node.parent){if(!(0,tool_registration_1.isFunctionNode)(node))continue;if(registrationsOf(node).some(route=>route.arguments.length>2))return true}}return false}function noteRawApp(node,scope){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding!==void 0&&RAW_APPS[binding.module]===binding.path.join("."))rawApps.push({node,framework:binding.module})}function registersRoute(node){const declarator=node.parent;if(declarator?.type!=="VariableDeclarator")return false;return sourceCode.getDeclaredVariables(declarator).some(variable=>variable.references.some(ref=>{const member=ref.identifier.parent;return member.type==="MemberExpression"&&member.object===ref.identifier&&member.parent.type==="CallExpression"&&member.parent.callee===member&&ROUTE_METHODS.has((0,eslint_devkit_1.propertyName)(member)??"")}))}return{before(){if(!(0,mcp_evidence_1.fileUsesMcpSdk)(context.sourceCode.ast))return false;sourceCode=context.sourceCode;resolve=(0,module_resolver_1.valueResolverFor)(context);builtBy=(0,instances_1.createInstanceResolver)(context);unhardened=[];constructsTransport=false;servesV2=false;rawApps=[];validatesHost=false;authenticates=false;customUse=false;binds=[];openFactories=[];handleRequestCalls=[];serveCalls=[];return true},NewExpression(node){const scope=sourceCode.getScope(node);noteRawApp(node,scope);const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);if(binding===void 0||!(0,mcp_evidence_1.isMcpModule)(binding.module))return;const transport=String(binding.path[binding.path.length-1]);const index=HTTP_TRANSPORTS.get(transport);if(index===void 0)return;constructsTransport=true;if(transport==="SSEServerTransport")serveCalls.push(node);if(!TRANSPORT_OPTION_PACKAGES.some(pkg=>binding.module===pkg||binding.module.startsWith(`${pkg}/`))){servesV2=true;return}const arg=node.arguments[index];if(arg===void 0){unhardened.push({node,transport});return}const options=readOptions(arg);if(options===null)return;if(rebindingProtection(options)==="no"||nonEmptyHosts(options)==="no")unhardened.push({node,transport})},CallExpression(node){const scope=sourceCode.getScope(node);noteRawApp(node,scope);if(node.callee.type==="Identifier"){const init=(0,tool_registration_1.constInitializer)(node.callee,scope);if(init?.type==="CallExpression"&&(0,tool_handlers_1.mcpExport)(init.callee,scope)!==void 0)serveCalls.push(node)}if(node.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(node.callee)==="fetch"&&node.callee.object.type==="Identifier"){const init=(0,tool_registration_1.constInitializer)(node.callee.object,scope);if(init?.type==="CallExpression"&&(0,tool_handlers_1.mcpExport)(init.callee,scope)==="createMcpHandler")serveCalls.push(node)}const name=(0,tool_handlers_1.mcpExport)(node.callee,scope);if(name!==void 0){if(HOST_VALIDATORS.has(name))validatesHost=true;else if(AUTH_EXPORTS.has(name))authenticates=true;else if(name==="createMcpHandler"){servesV2=true;constructsTransport=true}else if(MCP_APP_FACTORIES.has(name)){const state=expressAppState(node);if(state.kind==="guarded")validatesHost=true;else if(state.kind==="allInterfaces"){openFactories.push({node,factory:name,host:state.host});binds.push({node,host:state.host})}}return}const server=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,scope);const[first]=node.arguments;if(server!==void 0&&OPTIONS_SERVERS[server.module]===server.path.join(".")&&first?.type==="ObjectExpression"){const options=readOptions(first);if(options===null)return;const hostNode=options.get("hostname");const host=hostNode===void 0?DEFAULT_LISTEN_HOST:hostOf(hostNode);if(host!==null&&ALL_INTERFACE_HOSTS.has(host))binds.push({node,host});return}if(node.callee.type!=="MemberExpression")return;const method=(0,eslint_devkit_1.propertyName)(node.callee);if(method==="use"){if(node.arguments.some(arg=>arg.type==="Identifier"||(0,tool_registration_1.isFunctionNode)(arg)))customUse=true}else if(method==="handleRequest"){handleRequestCalls.push(node);serveCalls.push(node)}else if(method==="handlePostMessage"){serveCalls.push(node)}else if(method==="listen"){const[first2,second]=node.arguments;const options=first2?.type==="ObjectExpression"?readOptions(first2):null;const hostNode=first2?.type==="ObjectExpression"?options?.get("host"):second!==void 0&&!(0,tool_registration_1.isFunctionNode)(second)?second:void 0;const host=hostNode===void 0?null:hostOf(hostNode);if(host!==null&&ALL_INTERFACE_HOSTS.has(host))binds.push({node,host});else if(hostNode===void 0&&(first2?.type!=="ObjectExpression"||options!==null)&&listensOnAllByDefault(node.callee.object))binds.push({node,host:DEFAULT_LISTEN_HOST})}},"Program:exit"(){const gated=servedBehindCredentialCheck();if(!gated)for(const{node,factory,host}of openFactories)context.report({node,messageId:"allInterfacesWithoutAllowedHosts",data:{factory,host}});if(!validatesHost&&!gated){for(const{node,transport}of unhardened)context.report({node,messageId:"missingRebindingProtection",data:{transport}});if(servesV2){for(const{node,framework}of rawApps)if(registersRoute(node))context.report({node,messageId:"appWithoutHostValidation",data:{framework}})}}if(!constructsTransport||binds.length===0||authenticates||gated||customUse||routeHasMiddleware())return;for(const{node,host}of binds)if(!appEscapes(node))context.report({node,messageId:"missingAuth",data:{host}})}}}});
|