Skip to main content

SKY-D244 · Security in code

Secret as the default value of an MCP tool parameter

CriticalCWE-798

An MCP server offers tools that an AI model can call; each tool's parameters, with their default values, are sent to the model as the tool's schema. SKY-D244 reports a Python MCP tool whose parameter has a default value shaped like a real API key, token or JWT.

Languages
Python
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
Finding type
review
Catalog name
MCP hardcoded tool parameter secret
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The key is stored in the source and in Git history, and every client that lists the server's tools receives it in the tool schema, so the model and its logs see it too. Anyone who gets it can call the provider's API with your account, here reading and creating Stripe charges.

What Skylos flags

server/billing.py · PythonReported on line 10
import httpxfrom mcp.server.fastmcp import FastMCP mcp = FastMCP("billing-tools")  @mcp.tool()def list_charges(    customer_id: str,    api_key: str = "sk_live_51HandbookDemo0nlyMcpTool",) -> list[dict]:    """List a customer's recent Stripe charges."""    response = httpx.get(        "https://api.stripe.com/v1/charges",        params={"customer": customer_id, "limit": 20},        auth=(api_key, ""),    )    return response.json()["data"]

What Skylos leaves alone

server/billing.py · Python
import os import httpxfrom mcp.server.fastmcp import FastMCP mcp = FastMCP("billing-tools")  @mcp.tool()def list_charges(    customer_id: str,    created_after: str = "2024-01-01T00:00:00Z",) -> list[dict]:    """List a customer's Stripe charges created after a date."""    response = httpx.get(        "https://api.stripe.com/v1/charges",        params={"customer": customer_id, "created[gte]": created_after},        auth=(os.environ["STRIPE_SECRET_KEY"], ""),    )    return response.json()["data"]

Why Skylos leaves it alone

The key is read from the environment inside the tool, so it is in neither the source nor the tool's schema. The one long string default is a timestamp, which matches none of the key shapes Skylos knows.

How Skylos decides

  1. Runs with --danger on Python files that import mcp, fastmcp or a module under mcp..
  2. Looks at functions with a decorator named tool, resource or prompt, such as @mcp.tool() or @server.resource(...).
  3. Reads the default values of positional and keyword-only parameters. Only plain string literals of 10 characters or more are checked.
  4. Reports CRITICAL, on the line of the default value, when the string has the shape of a known credential: an OpenAI (sk-) or Anthropic (sk-ant-) key, an AWS access key ID (AKIA), a GitHub (ghp_, gho_) or GitLab (glpat-) token, a Slack token (xoxb- and similar), a Stripe live key (sk_live_, rk_live_), a Bearer or Basic authorization value, or a JWT (starts with eyJ).

How to fix it

Remove the key from the tool's parameters and read it on the server, from the environment or a secret store. The model should never choose or see the credential. Then revoke the leaked key: it stays in Git history.

server/billing.py · Python · the fix, against the flagged file
Added: import osAdded:  import httpxfrom mcp.server.fastmcp import FastMCP mcp = FastMCP("billing-tools")  @mcp.tool()Removed: def list_charges(Removed:     customer_id: str,Removed:     api_key: str = "sk_live_51HandbookDemo0nlyMcpTool",Removed: ) -> list[dict]:Added: def list_charges(customer_id: str) -> list[dict]:    """List a customer's recent Stripe charges."""    response = httpx.get(        "https://api.stripe.com/v1/charges",        params={"customer": customer_id, "limit": 20},Removed:         auth=(api_key, ""),Added:         auth=(os.environ["STRIPE_SECRET_KEY"], ""),    )    return response.json()["data"]

When it can be wrong

  • A placeholder in the shape of a key is reported, for example token: str = "Bearer paste-your-token-here-xx" in a sample server.
  • In a file that imports MCP, any function with a decorator named tool, resource or prompt, such as a LangChain @tool, is checked the same way.
  • Missed: keys of other providers (for example Google AIza… keys or Stripe test keys), a default built from several strings, and a key held in a module constant or set inside the function body. The secrets scan (--secrets, SKY-S101) covers most of those.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • For a published sample whose value is not a real key, mark the parameter line and say so.

    Python
    token: str = "Bearer paste-your-token-here-xx",  # skylos: ignore[SKY-D244] placeholder
  • [tool.skylos] ignore = ["SKY-D244"] turns the rule off for the whole project. A real key should be removed and revoked instead.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.