server-security

A security guide for server code that handles browser input and project files. It requires user-supplied paths to stay inside the configured project folder and treats uploads as untrusted.

In plain words
What is it for?
Use it when adding or changing project-file services, scene or asset routes, file uploads, content serving, or any API that receives paths from a browser.
Why use it?
It reduces the risk of path traversal, accidental access to files outside a project, unsafe uploads, leaked server paths, and endpoints that run shell commands.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/andvolodko/html5-game-editor/server-security
Clone the repo
git clone --depth 1 https://github.com/andvolodko/html5-game-editor

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 665 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00665
Opus 5 $0.00000 $0.00332
Sonnet 5 $0.00000 $0.00133
Haiku 4.5 $0.00000 $0.00067

Measured 2d ago against content hash e8347952d205, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

server-security scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

* Never expose APIs that take absolute client paths or raw shell commands. No `child_process` / “execute command” endpoints.
.cursor/rules/server-security.mdc · 36 lines

How it starts

The opening of the file, as written. The whole thing — 36 lines — stays where its author put it; the contents beside it link to each section on GitHub.

project-server security

Browser input is untrusted. All project filesystem access goes through ProjectService.resolveProjectPathProjectRootGuard.resolveSafe. Do not call path.resolve/readFile/writeFile on user-influenced paths without that guard.

Path confinement

  • Resolve only project-relative paths. Reject traversal (../, absolute inputs that escape root) via ProjectRootGuard (PATH_ESCAPE).
  • Do not reimplement root checks in each route. New file services (SceneFileService, AssetDatabaseStore, AssetImportService, content serving) must take ProjectService (or the guard) as a dependency.
  • Never expose APIs that take absolute client paths or raw shell commands. No child_process / “execute command” endpoints.
  • Do not return internal absolute server paths in JSON error payloads meant for the browser (health may report configured root for local dev only).

Uploads and assets

  • Multipart parsing (parseAssetImportMultipart) must keep size/file-count limits (MAX_ASSET_IMPORT_FILE_BYTES / MAX_ASSET_IMPORT_FILES in import-limits.ts). Reject non-multipart bodies.
  • Treat upload filename as untrusted: use path.basename, then destination helpers (normalizeAssetDestination, allocateUniqueFileName). Never overwrite on name collision; allocate name-N.ext.
  • Import only through AssetImportService + AssetImporterRegistry (e.g. TextureAssetImporter). Validate extension/MIME via shared helpers (isSupportedTextureExtension from @game-editor/assets). Unsupported files become per-file errors, not silent writes.
  • Stage → commit → single manifest save; on failure roll back written files and do not leave a partial .project/assets.json update. Keep staging under .project/import-tmp/… inside the root.
  • Serve bytes only for IDs present in the asset DB (GET /assets/:id/content), after resolving record.path through ProjectService. Do not add “read any relative path” endpoints.

HTTP and persistence

Read the full file on GitHub · 36 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 36 lines · 0 tokens per session scan A e8347952d205

Subscribe to this mod's changes

server-security is a cursor rule published in the GitHub repository andvolodko/html5-game-editor (5 stars, last pushed 7d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 665 tokens. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.