/product REST surface is unauthenticated by default; user_id is client-supplied (cross-user IDOR) and doc_path reads arbitrary server files
What
On the self-hosted MemOS server (src/memos/api/server_api.py), the /product router (src/memos/api/routers/server_router.py:68) exposes memory read/write, cube, scheduler, and chat endpoints with no authentication dependency, while auth is off by default.
- Every
/producthandler is a plaindef f(req)with noDepends(verify_api_key)— e.g.search_memories(server_router.py:112),add_memories(:128),create_cube(:143),chat_complete(:271),scheduler_status(:208). Compare the admin router, which gates every route withauth: dict = Depends(verify_api_key)(admin_router.py:81,128,158,190). The/productrouter is included with nodependencies=[...]either (server_api.py:50). AUTH_ENABLEDdefaults tofalse(src/memos/api/middleware/auth.py:26), and even when enabled,verify_api_keyreturns an all-scopes context whenAUTH_ENABLEDis false (auth.py:173), so the admin routes are open by default too.user_idis taken from the request (e.g.scheduler_status(user_id: str = Query(...))atserver_router.py:209), never authenticated — a caller picks any user id.doc_pathon add/search flows to_get_all_documents(src/memos/mem_os/core.py:233), which doesPath(path).rglob("*")over the caller-supplied path and returns every.txt/.pdf/.json/.md/.ppt(x)file under it for the server to read and process.
Net effect: by default, an unauthenticated caller can read/write any user's memories (pick user_id), enumerate/read arbitrary server-side documents (doc_path=/etc, a home dir, etc.), and drive the chat/scheduler surface.
There is a related secondary bypass: is_internal_request (auth.py:147) returns True when the X-Internal-Service header equals os.getenv("INTERNAL_SERVICE_SECRET"); if that env var is unset (default) and the header is absent, the comparison is None == None → the request is treated as internal/full-scope even when AUTH_ENABLED=true.
How to reproduce
Default config (no AUTH_ENABLED, no INTERNAL_SERVICE_SECRET), server running on 127.0.0.1:5050 (or wherever it binds):
# 1. unauthenticated access — no API key, no header
curl -s http://127.0.0.1:5050/product/scheduler/allstatus | head
# 2. cross-user IDOR — pick another user's id
curl -s -X POST http://127.0.0.1:5050/product/search \
-H 'Content-Type: application/json' \
-d '{"user_id":"victim","query":"*","cube_id":"default"}' | head
# 3. arbitrary server-side file read via doc_path (rglob under any path)
curl -s -X POST http://127.0.0.1:5050/product/add \
-H 'Content-Type: application/json' \
-d '{"user_id":"attacker","cube_id":"default","doc_path":"/etc"}' | head
All three return 200 with data and no 401/403. The handler signatures in server_router.py confirm there is no auth dependency to trigger a 401.
Checked at 93e4082 (main HEAD).
Impact / scope
- This is about the default configuration of the self-hosted REST server. If the server is reachable beyond a single trusted loopback (container with a published port, a shared host, a reverse proxy), the above is unauthenticated and remote.
- Even on loopback, the
user_id-from-request design is a cross-user IDOR (one local principal reads/writes another's memories), anddoc_pathis an arbitrary server-side file read limited only by the process's filesystem permissions and the extension allowlist. - A
SECURITY.md/ documented trust model would help set expectations; right now there is none in the core service, so I'm reporting the default-unauth + IDOR + file-read posture as-is.
Suggested change
- Put a
Depends(verify_api_key)(or an equivalent) on the/productrouter, or gate it atinclude_router(..., dependencies=[Depends(verify_api_key)]). - Default
AUTH_ENABLEDtotrue(or require an explicit opt-in to the unauthenticated mode), and document the deployment boundary. - Derive
user_idfrom the authenticated principal instead of a client-supplied query/body field. - Clamp
doc_pathto an allowlisted documents root rather thanrglob-ing an arbitrary caller path; and fix theNone == Noneinternal-service check (require the secret to be set, and compare securely).
Happy to open a PR for the Depends(verify_api_key) + user_id parts.
Correction on the doc_path point: I over-stated it for the REST surface. On /product/add, APIADDRequest.doc_path is deprecated and converted into a file-message (product_models.py:806-817 -> {"file":{"path": doc_path}}); the file parser does not fetch local paths, so the REST endpoint does not read arbitrary server files via doc_path. The _get_all_documents rglob sink (mem_os/core.py:233) is reachable from the MCP server's add_memory(doc_path=…) (mcp_serve.py:333), not from this REST route. The unauthenticated-REST and client-supplied-user_id (IDOR) parts of this report stand as written; only the REST doc_path file-read line is withdrawn (it belongs to the MCP surface).
Additional unauthenticated destructive endpoints on the same /product surface: delete_memory_by_record_id and recover_memory_by_record_id (server_router.py, ~:460-500) take a client-supplied mem_cube_id and operate directly on the graph db with no auth — so an unauthenticated caller can delete/recover any cube's memory nodes by record id. Same root cause (no Depends(verify_api_key) on the /product router, mem_cube_id/user_id client-supplied).
This issue has been automatically marked as stale due to inactivity.
This issue has been automatically closed due to inactivity.