Skip to content

Lock the local API to the Modly app (CORS + per-launch token) #458

Closed

Description

@lightningpixel

Context

The FastAPI backend listens on localhost:8765 and allows every origin (api/main.py:53: allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]). While Modly runs, any web page open in the user's browser can call the whole local API: list and read workspace files, start generations, install extensions, start downloads, delete models.

Restricting CORS alone is not enough: "simple" requests (GET, form POST) reach the server without a preflight, so the side effect happens even if the browser hides the response.

Scope

  • Allow only the renderer's origins: the Vite dev server URL in dev, and the packaged app's origin (loadFile → file://, sent as Origin: null) in prod. Check what Electron actually sends before relying on it.
  • A per-launch secret: Electron generates a random token, passes it to the Python process (env), and every renderer → API call sends it in a header (preload / axios defaults / consumeSse / <img>-style /workspace URLs need a plan). The API rejects requests without it, except GET /health.
  • Non-browser callers keep working: the agent tools, api/mcp_server.py, tools/modly-cli (they would read the token from the same place).
  • Tests for the middleware (missing / wrong / right token, allowed and refused origins).

Acceptance criteria

A page served from another origin (e.g. http://example.test) cannot trigger any API action or read any response while Modly is running, and the app, the agent and the CLI work as before.

Notes

Raised during the review of #457 (background-removal setup route); not specific to it.

Activity

  1. moved this from Backlog to Ready to review in Modly Boardon Nov 16, 2026
  2. moved this from Backlog to Ready to review in Modly Boardon Nov 16, 2026
  3. moved this from Ready to review to Done in Modly Boardon Nov 18, 2026
  4. closed this as completedby moving to Done in Modly Boardon Nov 18, 2026
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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions