Repository navigation
feat(security): lock the local API to the Modly app - #459
Closed
lightningpixel wants to merge 2 commits into
Closed
lightningpixel wants to merge 2 commits into
lightningpixel wants to merge 2 commits into
Conversation
While Modly ran, any web page open in the user's browser could call the whole local API (allow_origins="*"): read workspace files, start generations, install packages, delete models. - Electron generates a token per launch and passes it to the backend (MODLY_API_TOKEN) with the renderer's origins (MODLY_ALLOWED_ORIGINS). - A webRequest hook adds X-Modly-Token to every renderer request to the API, so axios, fetch, SSE, three.js loaders and downloads need no change and the renderer never sees the token. Main-process calls go through a shared axios client that sends it. - The backend rejects any request without the token (401), except GET /health, OPTIONS and the OrcaSlicer route; CORS only allows the app's origins. - OrcaSlicer (an external app) gets a URL signed with an HMAC of the source path from GET /export/slicer-link; links expire with the launch. - The app window can no longer navigate away from its own pages (links open in the browser), so no other page can receive the token. - The token is written to api-token next to api-port (0600, removed at quit) for the MCP server and modly-cli; modly-cli only sends it to loopback hosts. The agent and extension subprocesses get it by env. - Without MODLY_API_TOKEN (standalone uvicorn, Jetson, modly-cli serve) the API stays open, with a warning at startup. Closes #458
The webRequest hook keyed on the destination alone; it now also requires the request to come from the main window's webContents.
5 of 6 tasks
Owner
Author
|
Replaced by #463: web pages are kept off the API by origin (MODLY_ORIGINS) instead of a token. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #458
While Modly ran, any web page open in the user's browser could call the whole local API (
allow_origins=["*"]): read workspace files, start generations, install packages, delete models.How it works
MODLY_API_TOKENandMODLY_ALLOWED_ORIGINS(dev renderer origin,file://,null). Never put on the main process env.session.webRequest.onBeforeSendHeadershook addsX-Modly-Tokento requests from the main window to the API origin (port tracked across restarts). axios, fetch, SSE, three.js loaders and downloads need no change, and the renderer never sees the token.apiClient(axios) that sends the header;net.fetchcalls add it explicitly.api/services/api_auth.py): pure ASGI middleware, 401 without the right token (constant-time compare). Exempt:GET /health,OPTIONS, and the OrcaSlicer route. CORS only allows the app's origins; a 401 still carries CORS headers.GET /export/slicer-linkfor a URL whose path carries an HMAC of the source path; links expire with the launch.will-navigate/will-redirectkeep the window on its own pages (links open in the browser), so no other page can receive the token.api-tokennext toapi-port(0600, removed at quit).mcp_server.pyandmodly-cliread it (modly-cli only sends it to loopback hosts); the agent's calls back into the API and extension subprocesses get it by env.MODLY_API_TOKEN(standaloneuvicorn main:app, Jetson,modly-cli serve) the API stays open as before, with a startup warning. Docs updated.Follow-ups outside this repo
modly-cli-mcp(recommended in Settings > Agent) must readapi-tokentoo, or it will get 401s.Testing
npm testpasses (Python 489, JS 343 + 237, 0 failures); lint clean;tscunchanged fromdevapi/tests/test_api_auth.py, slicer signature + extension env cases,electron/main/api-auth.test.ts(token, origins, API request match, navigation guard, token file),orcaSlicerLink.test.ts, modly-cli token file + loopback-only headerfile://pages send (bothfile://andnullare allowed)