Repository navigation
Description
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 ofname)mcp-server/tools/scaffold.py:62-64(base = name,os.makedirs(base, exist_ok=True))mcp-server/tools/scaffold.py:55-57(workspace_pathonly 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
overwriteflag, and no backup. - The output location is the server's CWD.
workspace_pathis never used as the output directory, so with the shipped.cursor/mcp.jsonresources land wherever the client launchedpython mcp-server/server.py. The summary does not print the absolute path. nameis not validated:""raises an uncaughtFileNotFoundErrorfromos.makedirs(''), and values containing path separators,.., or an absolute path are used as-is, so files can be created outside the intended folder.name,authoranddescriptionare interpolated into single-quoted Lua strings without escaping.name="it's"writesdescription 'it's', which is invalid Lua. The same unescaped interpolation exists inmanifest_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
- In a scratch directory, create
r/server/main.luacontaining-- my code. - 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'))". - The tool reports success and
r/server/main.luanow contains the boilerplateAddEventHandler('onResourceStart' .... s('', 'gta5', 'lua', 'standalone')raisesFileNotFoundError.s("it's", ...)writes an unparseable manifest.
Suggested fix
- Validate
nameagainst the documented resource-name format (for example^[a-z0-9][a-z0-9_-]{0,63}$) and return anError:string otherwise. - Add an
output_pathparameter (default:workspace_path, else an explicit configured root). Resolve the target withos.path.realpathand refuse if it is not contained in that base directory. - Refuse when the target directory exists and is non-empty unless
overwrite=Trueis passed; open files with mode"x"by default. - Escape
\and'in every value written into Lua strings (shared helper inmanifest_common.py, also used bymanifest_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. -
namevalues that are empty, contain/,\,.., or are absolute paths are rejected and nothing is created. - Files are written under the requested
output_path(orworkspace_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_pathandmonkeypatch.chdir) cover: default Lua output files and manifest contents; each framework'sdependencyand init line;javascript(validpackage.json,node_version '22') andcsharp(csproj,Client/ClientMain.cs,Server/ServerMain.cs);game="both"andgame="RDR3 "normalisation; invalid game/language/framework creates no directory; the rejection and overwrite cases above;workspace_pathauthor pickup and fallback toYourName.
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
TMHSDigital commentedon Nov 21, 2026
Fixed in 0f1822c.
Validated resource names, added
output_path(defaultworkspace_path, thenCFX_SCAFFOLD_ROOT, then CWD) with realpath containment, refused to write into non-empty directories unlessoverwrite=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=Truereplaced it; empty,../x,a/b,C:\x,..and/absnames were rejected with nothing created; invalid framework created no directory.