SKY-D242 · Security in code
MCP resource template that exposes any file path
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
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
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
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).bodyWhy 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
- Runs with
--dangeron Python files that importmcp,fastmcpor a module undermcp., on functions decorated with a call namedresource, such as@mcp.resource("..."). - 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. - Reports HIGH for a
file://URI with any placeholder after the scheme, such asfile:///{path}orfile:///srv/{name}. - Also reports HIGH when the template has a placeholder named
path,file,filename,dir,directoryorfilepath(any case) and the first placeholder comes straight after the scheme or after one fixed segment:docs://{path},docs://pages/{file}andrepo://{owner}/{path}are reported;docs://v1/pages/{path}is not. - 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.
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 DOCSskylos baseline ., then--baseline, accepts existing findings by file and line.[tool.skylos] ignore = ["SKY-D242"]turns the check off for the project.