Skip to content

    Type a page, a command such as keryn scan, or a rule id.

    mcp-tool-output-hygiene-v1

    View as Markdown

    9 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: error fails a default gate, warning and info do 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.

    keryn.mcp.py.tool-returns-credential-like-keys

    Section titled “keryn.mcp.py.tool-returns-credential-like-keys”

    warning python mcp, python, fastmcp

    An MCP tool returns a dict whose key names a credential (api_key, password, token, secret, …) with a non-literal value; everything a tool returns lands in the model context, the client transcript and logs. Drop the field or return a redacted form such as the last four characters.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. 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-200 CWE-532 LLM02 LLM06 ASI03

    Fix: Do not put credentials in tool results. Return only the data the model needs; if a credential must be confirmed, return a boolean such as configured: true or a masked suffix.

    References: https://modelcontextprotocol.io/specification/2025-06-18/server/tools · https://github.com/modelcontextprotocol/python-sdk

    keryn.mcp.ts.tool-returns-credential-like-keys

    Section titled “keryn.mcp.ts.tool-returns-credential-like-keys”

    warning typescript, javascript mcp, typescript, nodejs

    An MCP tool handler returns an object whose key names a credential (apiKey, password, token, secret, …) with a non-literal value; tool results flow into the model context, the client transcript and logs. Remove the field or return a masked or boolean form.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. 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-200 CWE-532 LLM02 LLM06 ASI03

    Fix: Do not put credentials in tool results. Return only the data the model needs; to confirm a credential exists, return a boolean or a masked suffix.

    References: https://modelcontextprotocol.io/specification/2025-06-18/server/tools · https://github.com/modelcontextprotocol/typescript-sdk

    keryn.mcp.py.tool-returns-fetched-content-unwrapped

    Section titled “keryn.mcp.py.tool-returns-fetched-content-unwrapped”

    warning python data-flow rule mcp, python, fastmcp, requests, httpx

    An MCP tool returns the body of an outbound HTTP response to the client verbatim; whoever controls that page can plant instructions that the client model reads as tool output (indirect prompt injection). Wrap the content in an explicit untrusted-data delimiter and strip markup before returning it.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. 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-74 CWE-1427 LLM01 LLM05 ASI01

    Fix: Treat fetched pages as data: strip HTML, truncate, and wrap the text in a clear untrusted-content envelope (for example <untrusted_content source=URL>…</untrusted_content>) that the client prompt tells the model not to obey. Prefer returning extracted fields over raw bodies.

    References: https://modelcontextprotocol.io/specification/2025-06-18/server/tools · https://github.com/modelcontextprotocol/python-sdk · https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices

    keryn.mcp.ts.tool-returns-fetched-content-unwrapped

    Section titled “keryn.mcp.ts.tool-returns-fetched-content-unwrapped”

    warning typescript, javascript data-flow rule mcp, typescript, nodejs

    An MCP tool handler returns the body of an outbound HTTP response (fetch or axios) verbatim; whoever controls that page can plant instructions that the client model reads as tool output (indirect prompt injection). Wrap it in an untrusted-data envelope and strip markup first.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. 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-74 CWE-1427 LLM01 LLM05 ASI01

    Fix: Treat fetched pages as data: strip HTML, truncate, and wrap the text in a clear untrusted-content envelope that the client prompt tells the model not to obey. Prefer returning extracted fields over raw bodies.

    References: https://modelcontextprotocol.io/specification/2025-06-18/server/tools · https://github.com/modelcontextprotocol/typescript-sdk · https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices

    warning python mcp, python, client

    An MCP client transport connects to a non-loopback http:// URL, so tool calls, results and any bearer token cross the network unencrypted and can be read or rewritten in transit. Use https://; keep http only for localhost.

    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).

    CWE-319 CWE-300 LLM02 LLM03 ASI07 ASI04

    Fix: Point the transport at an https:// endpoint with a valid certificate. Plain http is acceptable only for loopback development servers.

    References: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports · https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization · https://github.com/modelcontextprotocol/python-sdk · https://pypi.org/project/mcp/1.12.0/ · https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/src/mcp/client/streamable_http.py

    warning typescript, javascript mcp, typescript, nodejs, client

    An MCP client transport connects to a non-loopback http:// URL, so tool calls, results and any bearer token cross the network unencrypted and can be read or rewritten in transit. Use https://; keep http only for localhost.

    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).

    CWE-319 CWE-300 LLM02 LLM03 ASI07 ASI04

    Fix: Point the transport at an https:// endpoint with a valid certificate. Plain http is acceptable only for loopback development servers.

    References: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports · https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization · https://github.com/modelcontextprotocol/typescript-sdk · https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/packages/client/src/client/streamableHttp.ts

    warning go mcp, go

    A Go MCP tool handler asks the client to run a model completion (RequestSampling / CreateMessage) with no approval, consent or policy call anywhere in the same function. Add an explicit gate and token cap before spending the client’s model.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: grants authority is given or left unchecked.

    CWE-862 CWE-345 LLM06 LLM01 ASI09 ASI02

    Fix: Sampling lets a server spend the client’s model and credentials. Gate each request behind an explicit approval or policy check (per-server allow-list, token cap, rate limit) and never build the sampled prompt from untrusted tool input without review.

    References: https://modelcontextprotocol.io/specification/2025-06-18/client/sampling · https://github.com/mark3labs/mcp-go · https://github.com/modelcontextprotocol/go-sdk · https://raw.githubusercontent.com/modelcontextprotocol/go-sdk/main/mcp/server.go · https://raw.githubusercontent.com/mark3labs/mcp-go/main/server/sampling.go

    keryn.mcp.java.sampling-request-no-approval

    Section titled “keryn.mcp.java.sampling-request-no-approval”

    warning java mcp, java

    A Java MCP tool handler calls exchange.createMessage(…) to run a completion on the client with no approval, consent or policy call in the same handler. Add an explicit gate and a token cap before spending the client’s model.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: grants authority is given or left unchecked.

    CWE-862 CWE-345 LLM06 LLM01 ASI09 ASI02

    Fix: Sampling lets a server spend the client’s model and credentials. Gate each request behind an explicit approval or policy check (per-server allow-list, token cap, rate limit) and never build the sampled prompt from untrusted tool input without review.

    References: https://modelcontextprotocol.io/specification/2025-06-18/client/sampling · https://github.com/modelcontextprotocol/java-sdk · https://raw.githubusercontent.com/modelcontextprotocol/java-sdk/main/mcp-core/src/main/java/io/modelcontextprotocol/server/McpSyncServerExchange.java

    keryn.mcp.csharp.sampling-request-no-approval

    Section titled “keryn.mcp.csharp.sampling-request-no-approval”

    warning csharp mcp, csharp, dotnet

    An [McpServerTool] method asks the client to run a completion (SampleAsync / RequestSamplingAsync) with no approval, consent or policy call in the same method. Add an explicit gate and a token cap before spending the client’s model.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: grants authority is given or left unchecked.

    CWE-862 CWE-345 LLM06 LLM01 ASI09 ASI02

    Fix: Sampling lets a server spend the client’s model and credentials. Gate each request behind an explicit approval or policy check (per-server allow-list, token cap, rate limit) and never build the sampled prompt from untrusted tool input without review.

    References: https://modelcontextprotocol.io/specification/2025-06-18/client/sampling · https://github.com/modelcontextprotocol/csharp-sdk · https://raw.githubusercontent.com/mark3labs/mcp-go/main/server/sampling.go