Skip to main content

SKY-D242 · Security in code

MCP resource template that exposes any file path

HighCWE-22

An MCP resource is data the server offers to the AI client under a URI. A resource template such as docs://{path} lets the client fill in part of that URI. SKY-D242 reports a Python resource template whose placeholder looks like a file path chosen by the caller.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
MCP overly permissive resource URI
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The model fills in the placeholder, and a prompt-injected model will happily ask for ../../home/app/.env. If the handler joins that value onto a folder, the server returns files outside the folder it was meant to share.

What Skylos flags

server/docs.py · PythonReported on line 9
from pathlib import Path from mcp.server.fastmcp import FastMCP DOCS = Path("/srv/docs")mcp = FastMCP("docs")  @mcp.resource("docs://{path}")def read_doc(path: str) -> str:    """Return one documentation page."""    return (DOCS / path).read_text()

What Skylos leaves alone

server/docs.py · Python
from mcp.server.fastmcp import FastMCP from docs_app import store mcp = FastMCP("docs")  @mcp.resource("notes://{note_id}")def read_note(note_id: str) -> str:    """Return one saved note by its ID."""    return store.get_note(note_id).body

Why Skylos leaves it alone

The placeholder is an ID that the handler looks up in a store; no file path is built from it. Skylos reads only the URI template: it reports file:// templates and placeholders named like a path, and note_id is neither.

How Skylos decides

  1. Runs with --danger on Python files that import mcp, fastmcp or a module under mcp., on functions decorated with a call named resource, such as @mcp.resource("...").
  2. Takes the URI from the decorator's string-literal arguments and its uri= keyword. A URI held in a variable or built with an f-string is not read.
  3. Reports HIGH for a file:// URI with any placeholder after the scheme, such as file:///{path} or file:///srv/{name}.
  4. Also reports HIGH when the template has a placeholder named path, file, filename, dir, directory or filepath (any case) and the first placeholder comes straight after the scheme or after one fixed segment: docs://{path}, docs://pages/{file} and repo://{owner}/{path} are reported; docs://v1/pages/{path} is not.
  5. The handler's body is not read, so a check inside it neither adds nor removes a finding. The finding sits on the decorator line.

How to fix it

Let the caller choose a name, not a path, and resolve it against a fixed list of what you mean to share. If you must accept a path, resolve it and refuse anything outside the folder; Skylos still reports the template then, so mark the reviewed line.

server/docs.py · Python · the fix, against the flagged file
from pathlib import Path from mcp.server.fastmcp import FastMCP DOCS = Path("/srv/docs")Added: PAGES = {page.stem: page for page in DOCS.glob("*.md")}mcp = FastMCP("docs")  Removed: @mcp.resource("docs://{path}")Removed: def read_doc(path: str) -> str:Removed:     """Return one documentation page."""Removed:     return (DOCS / path).read_text()Added: @mcp.resource("docs://pages/{slug}")Added: def read_doc(slug: str) -> str:Added:     """Return one documentation page by its name."""Added:     page = PAGES.get(slug)Added:     if page is None:Added:         raise ValueError(f"unknown page: {slug}")Added:     return page.read_text()

When it can be wrong

  • A handler that resolves the path and checks that it stays inside the shared folder is still reported, because only the template is read.
  • Path-like placeholders are missed when they have another name ({doc}), sit deeper in the URI (docs://v1/pages/{path}) or use FastMCP's multi-segment wildcard (docs://{path*}), which accepts slashes and is the riskiest form.
  • Resource handlers in TypeScript MCP servers are not checked.

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

  • Mark the decorator line once the handler confines the path, and say how.

    Python
    @mcp.resource("docs://{path}")  # skylos: ignore[SKY-D242] resolved under DOCS
  • skylos baseline ., then --baseline, accepts existing findings by file and line.

  • [tool.skylos] ignore = ["SKY-D242"] turns the check off for the project.

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