mcp-server-go-v1
12 rules · Keryn Software Licence · rules 0.8.0 · all packs
How to read a rule
- Severity
- How bad the finding is if it is real:
errorfails a default gate,warningandinfodo not. - Confidence
- P0 exploitable as written; P1 dangerous in context; P2 a heuristic or a posture check: confirm by reading the code.
- False-positive risk
- low: an exact API or flag, so hits are almost always real; medium: the pattern is legitimate in many programs, so check each hit; high: it finds a lead to confirm, so expect benign hits.
- Edge
- The relationship the finding sits on. reaches: content or traffic gets to a thing; calls: one thing invokes another; reads: one thing reads from another; writes: one thing writes to another; sends: data leaves for another party; grants: authority is given or left unchecked; depends_on: something relies on a component it does not verify; trusts: one party believes another without evidence. The boundary it crosses, when there is one: user->prompt (untrusted input reaching a prompt); model->code (model output reaching code, a shell, a query or a page); secret->outside (a secret leaving the trusted side); supply-chain (code, models or prompts pulled in from outside).
- Taxonomy chips
- References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.
seceng.mcp.go.tool-exec-command
Section titled “seceng.mcp.go.tool-exec-command”error go data-flow rule mcp, go
An MCP tool handler passes a tool argument as the program to exec.Command/CommandContext; the model (or an injected prompt) chooses which binary runs. Hard-code the executable or map an enum argument to a fixed argv.
Confidence P0: exploitable as written. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
CWE-78 CWE-88 LLM06 ASI05 ASI02
Fix: Never let a tool argument select the executable. Expose one tool per fixed command, validate arguments against an enum or allow-list, pass them as separate argv entries after a “–” separator, run with a minimal environment and require human approval for state-changing commands.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.tool-exec-shell-c
Section titled “seceng.mcp.go.tool-exec-shell-c”error go data-flow rule mcp, go
An MCP tool handler builds a sh -c / bash -c command string from a tool argument, giving shell injection. Pass an argv without a shell and validate each argument.
Confidence P0: exploitable as written. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
Fix: Replace exec.Command("sh", "-c", s) with exec.Command of a fixed binary and discrete arguments. If shell syntax is unavoidable, quote with a vetted library and allow-list the command words.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.tool-file-read
Section titled “seceng.mcp.go.tool-file-read”error go data-flow rule mcp, go
An MCP tool handler reads a file whose path comes from a tool argument; the model can read any file the server process can open. Resolve against a fixed root and verify the result stays inside it.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reads one thing reads from another.
CWE-22 CWE-200 LLM02 LLM06 ASI02 ASI03
Fix: Join the argument onto a fixed root, call filepath.Clean (or os.Root / securejoin.SecureJoin), then check strings.HasPrefix(resolved, root+string(os.PathSeparator)) before opening. Reject absolute paths and “..” segments, and also resolve symlinks with filepath.EvalSymlinks.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.tool-file-write
Section titled “seceng.mcp.go.tool-file-write”error go data-flow rule mcp, go
An MCP tool handler writes or creates a file at a path taken from a tool argument; a prompt injection can overwrite config, SSH keys or code. Constrain writes to a fixed root and require approval.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: writes one thing writes to another.
CWE-22 CWE-73 LLM06 ASI02 ASI03
Fix: Confine the path to a dedicated output directory (Clean + prefix check or os.Root), refuse symlinks and absolute paths, set restrictive file modes and gate writes behind user approval.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.tool-file-delete
Section titled “seceng.mcp.go.tool-file-delete”error go data-flow rule mcp, go
An MCP tool handler deletes a path taken from a tool argument; os.RemoveAll with a model-chosen path is destructive. Confine to a fixed root and require approval.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: writes one thing writes to another.
CWE-22 CWE-73 LLM06 ASI02 ASI03
Fix: Resolve the argument under a fixed root, verify the cleaned path keeps the root prefix, prefer os.Remove over os.RemoveAll, and put destructive tools behind explicit user confirmation.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.tool-path-join-unchecked
Section titled “seceng.mcp.go.tool-path-join-unchecked”warning go data-flow rule mcp, go
A tool argument is joined onto a base directory with filepath.Join but the function never performs a strings.HasPrefix containment check; filepath.Join does not stop “..” escapes. Check the cleaned result still starts with the base.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reads one thing reads from another.
Fix: After filepath.Join, call filepath.Clean and filepath.EvalSymlinks and verify strings.HasPrefix(result, base + separator); or use os.Root / securejoin which enforce containment.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.tool-http-request-ssrf
Section titled “seceng.mcp.go.tool-http-request-ssrf”error go data-flow rule mcp, go
An MCP tool handler requests a URL taken from a tool argument; the model can reach cloud metadata and internal services (SSRF). Allow-list hosts and block private ranges.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reaches content or traffic gets to a thing; it crosses the user->prompt boundary (untrusted input reaching a prompt).
Fix: Parse the URL, require https and a host on an allow-list, resolve the address and reject loopback, link-local (169.254.169.254) and RFC1918 ranges using a custom net.Dialer Control hook, and disable redirects or re-validate each hop.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.tool-sql-string-built
Section titled “seceng.mcp.go.tool-sql-string-built”error go data-flow rule mcp, go
An MCP tool handler runs a database/sql query built from a tool argument via string formatting or concatenation; the model can inject SQL. Use placeholders and bind the argument.
Confidence P0: exploitable as written. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
CWE-89 LLM06 LLM05 ASI02 ASI05
Fix: Use constant SQL with placeholders ($1 or ?) and pass tool arguments as bound parameters; allow-list identifiers (table or column names) explicitly; connect with a least-privilege, read-only database role.
References: https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/server/tools
seceng.mcp.go.token-passthrough
Section titled “seceng.mcp.go.token-passthrough”error go data-flow rule mcp, go
The inbound Authorization header (the MCP client’s token) is copied onto an outgoing upstream request; the MCP authorization spec forbids token passthrough because the upstream token was not issued to this server. Obtain a separate upstream token (token exchange / OBO).
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: grants authority is given or left unchecked.
CWE-441 CWE-522 LLM02 LLM06 ASI03 ASI07
Fix: Validate the inbound token for your own audience and do not forward it. Obtain a distinct upstream credential via OAuth token exchange (RFC 8693), an on-behalf-of flow or a service credential scoped to this server.
References: https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization · https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices · https://github.com/mark3labs/mcp-go
seceng.mcp.go.mark3labs-http-bind-all
Section titled “seceng.mcp.go.mark3labs-http-bind-all”warning go mcp, go
mcp-go SSE / Streamable HTTP server started on all interfaces (“:PORT” or 0.0.0.0). Without Origin/Host validation and authentication, any web page or LAN host can drive the tools (DNS rebinding). Bind 127.0.0.1 or front it with an authenticating proxy.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reaches content or traffic gets to a thing; it crosses the user->prompt boundary (untrusted input reaching a prompt).
CWE-1327 CWE-346 CWE-306 LLM06 ASI07 ASI03
Fix: Bind to 127.0.0.1 for local servers. For network servers, wrap the handler in middleware that rejects requests whose Origin or Host header is not on an allow-list (spec: servers MUST validate Origin) and that verifies OAuth 2.1 access tokens issued for this resource.
References: https://github.com/mark3labs/mcp-go · https://modelcontextprotocol.io/specification/2025-06-18/basic/transports
seceng.mcp.go.go-sdk-http-bind-all
Section titled “seceng.mcp.go.go-sdk-http-bind-all”warning go mcp, go
Official Go SDK Streamable HTTP/SSE handler served on all interfaces with http.ListenAndServe(“:PORT”). Without Origin/Host validation and authentication, any web page or LAN host can drive the tools. Bind loopback or add auth and Origin checks.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reaches content or traffic gets to a thing; it crosses the user->prompt boundary (untrusted input reaching a prompt).
CWE-1327 CWE-346 CWE-306 LLM06 ASI07 ASI03
Fix: Listen on 127.0.0.1 for local use. Wrap the mcp handler in middleware that validates Origin/Host against an allow-list and enforces bearer-token authentication (auth.RequireBearerToken) before the request reaches the MCP handler.
References: https://github.com/modelcontextprotocol/go-sdk · https://modelcontextprotocol.io/specification/2025-06-18/basic/transports
seceng.mcp.go.mark3labs-base-url-cleartext
Section titled “seceng.mcp.go.mark3labs-base-url-cleartext”warning go mcp, go
mcp-go server advertises a non-local http:// base URL; the SSE message endpoint and any session identifiers are sent in cleartext. Use https:// behind TLS.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party; it crosses the secret->outside boundary (a secret leaving the trusted side).
Fix: Set WithBaseURL to an https:// origin terminated by TLS (directly or at a reverse proxy) and only use http:// for localhost development.
References: https://github.com/mark3labs/mcp-go · https://modelcontextprotocol.io/specification/2025-06-18/basic/transports