Skip to content

scaffold_resource_tool overwrites existing files and writes relative to the CWD #25

Closed

Description

@TMHSDigital

Summary

scaffold_resource_tool writes into a directory named after the name argument, relative to the MCP server process's working directory, and opens every file in "w" mode. Re-scaffolding an existing resource name silently replaces the user's files, and the tool has no input validation on name or escaping of values written into Lua.

Where

  • mcp-server/tools/scaffold.py:45 (scaffold_resource, only normalisation of name)
  • mcp-server/tools/scaffold.py:62-64 (base = name, os.makedirs(base, exist_ok=True))
  • mcp-server/tools/scaffold.py:55-57 (workspace_path only used to read an author)
  • mcp-server/tools/scaffold.py:96 (_build_manifest, f"description '{name}'")
  • mcp-server/tools/scaffold.py:260-264 (_write, open(full, "w"))
  • mcp-server/server.py:31-48 (scaffold_resource_tool)

Details

name = name.strip().lower().replace(" ", "-")   # line 45
...
base = name                                      # line 62
os.makedirs(base, exist_ok=True)                 # line 64
...
def _write(base, path, content, files_created):  # line 260
    full = os.path.join(base, path)
    with open(full, "w", encoding="utf-8") as f:
  • There is no check for an existing directory or file, no overwrite flag, and no backup.
  • The output location is the server's CWD. workspace_path is never used as the output directory, so with the shipped .cursor/mcp.json resources land wherever the client launched python mcp-server/server.py. The summary does not print the absolute path.
  • name is not validated: "" raises an uncaught FileNotFoundError from os.makedirs(''), and values containing path separators, .., or an absolute path are used as-is, so files can be created outside the intended folder.
  • name, author and description are interpolated into single-quoted Lua strings without escaping. name="it's" writes description 'it's', which is invalid Lua. The same unescaped interpolation exists in manifest_gen.py (tracked in "generate_manifest emits Lua tables without commas, mishandles scanned scripts").

Impact

This is the only MCP tool that writes to disk. An agent that scaffolds shop while a shop resource already exists in the CWD truncates and replaces its fxmanifest.lua, config.lua, client/main.lua and server/main.lua (or the JS/C# equivalents), then reports "Scaffolded resource". User code is lost with no warning.

Steps to reproduce

  1. In a scratch directory, create r/server/main.lua containing -- my code.
  2. From that directory, run python -c "import sys; sys.path.insert(0, '<repo>/mcp-server'); from tools.scaffold import scaffold_resource as s; print(s('r','gta5','lua','standalone'))".
  3. The tool reports success and r/server/main.lua now contains the boilerplate AddEventHandler('onResourceStart' ....
  4. s('', 'gta5', 'lua', 'standalone') raises FileNotFoundError. s("it's", ...) writes an unparseable manifest.

Suggested fix

  • Validate name against the documented resource-name format (for example ^[a-z0-9][a-z0-9_-]{0,63}$) and return an Error: string otherwise.
  • Add an output_path parameter (default: workspace_path, else an explicit configured root). Resolve the target with os.path.realpath and refuse if it is not contained in that base directory.
  • Refuse when the target directory exists and is non-empty unless overwrite=True is passed; open files with mode "x" by default.
  • Escape \ and ' in every value written into Lua strings (shared helper in manifest_common.py, also used by manifest_gen.py).
  • Return the absolute output path in the summary.

Acceptance criteria

  • Scaffolding into an existing non-empty directory returns an error and leaves the original files byte-identical, unless overwrite=True.
  • name values that are empty, contain /, \, .., or are absolute paths are rejected and nothing is created.
  • Files are written under the requested output_path (or workspace_path), never relative to the server CWD by accident, and the summary shows the absolute path.
  • A name, author or description containing ' produces a manifest that parses as Lua (or is rejected).
  • Tests (pytest with tmp_path and monkeypatch.chdir) cover: default Lua output files and manifest contents; each framework's dependency and init line; javascript (valid package.json, node_version '22') and csharp (csproj, Client/ClientMain.cs, Server/ServerMain.cs); game="both" and game="RDR3 " normalisation; invalid game/language/framework creates no directory; the rejection and overwrite cases above; workspace_path author pickup and fallback to YourName.

Getting started

  • Relevant files: mcp-server/tools/scaffold.py, mcp-server/tools/manifest_common.py, mcp-server/server.py
  • How to run checks: there is no test suite yet; run the MCP server with cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in .github/workflows/validate.yml
  • Related docs: skills/resource-scaffolding/SKILL.md, mcp-server/README.md

Filed by repo-audit/full-audit at 701824d. Severity: high. Effort: S. audit-key: bug|mcp-server/tools/scaffold.py|scaffold_resource

Activity

  1. added
    bug
    on Nov 21, 2026
  2. TMHSDigital commented on Nov 21, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 0f1822c.

    Validated resource names, added output_path (default workspace_path, then CFX_SCAFFOLD_ROOT, then CWD) with realpath containment, refused to write into non-empty directories unless overwrite=True (files opened with mode "x"), escaped Lua strings, and reported the absolute output path.

    Verified: Ran the scaffolder in a scratch directory: re-scaffolding an existing name returned an error and left the edited file intact; overwrite=True replaced it; empty, ../x, a/b, C:\x, .. and /abs names were rejected with nothing created; invalid framework created no directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugseverity: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions