You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lock the local API to the Modly app (CORS + per-launch token) #458
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