cortex-mem
- Type
- MCP server
- Scanned
- Nov 17, 2026
- Version
- 82a1c83c4b1c
- Files read
- 211
Cortex Memory is a persistent memory system for AI coding agents that saves conversations as local Markdown files and indexes them in a Qdrant vector database for semantic search across sessions. Its biggest risk is missing path confinement on cortex:// URIs and HTTP file endpoints, which lets a tricked AI agent—or any website or local network user if the optional REST service is started—read, overwrite, or delete arbitrary files anywhere on the computer.
What it can reach
- Files
- Reads, writes, lists, and deletes Markdown and JSON memory files under the configured data directory and optional log files, though missing path checks let URIs reach outside that folder.
- Network
- Sends conversation text and search queries to the configured LLM API, Embedding API, and Qdrant vector database, and opens HTTP ports 8085 and 8159 if the optional REST API or Insights dashboard server is run.
- Secrets
- Reads LLM, Embedding, and Qdrant API keys from config.toml or environment variables such as LLM_API_KEY, EMBEDDING_API_KEY, and QDRANT_API_KEY.
- Browser
- The optional Insights standalone server opens http://127.0.0.1:8159 in the default web browser on startup unless --no-browser is passed.
- System
- The optional cortex-mem-tars example TUI can capture microphone audio for local Whisper transcription and read or write the system clipboard when triggered by the user.
Findings
-
HighPath traversal in cortex:// URIs allows reading, writing, and deleting arbitrary host files
cortex-mem-core/src/filesystem/uri.rs:102
UriParser::parse splits cortex:// paths on '/' without rejecting '..' segments, backslashes, or Windows drive prefixes, and CortexUri::to_file_path pushes those segments directly onto the storage root. If an AI agent is tricked by prompt injection in a webpage, issue, or document, it can call default-enabled MCP tools with '..' in uri or thread_id (for example cortex://session/../../../../../../etc/passwd) to read arbitrary files such as SSH keys or config.toml via content, list any folder via ls, write session files outside the data directory via store, or recursively wipe entire host directories via delete (which calls fs::remove_dir_all).
Fix: Reject '.', '..', backslashes, and colon/drive prefixes in every URI path segment and session/user/agent identifier, and verify that the canonicalized target path stays within the configured tenant or data root before performing any filesystem operation.
-
HighUnvalidated file paths in cortex-mem-service allow arbitrary host file read and write
cortex-mem-service/src/handlers/filesystem.rs:172
The HTTP filesystem handlers (such as POST /api/v2/filesystem/write, GET /api/v2/filesystem/read/*path, GET /api/v2/filesystem/content, and GET /api/v2/filesystem/list) and POST /api/v2/tenants/switch strip 'cortex://' and pass the caller-supplied string directly to Path::join without checking for '..' or leading slashes. In Rust, joining an absolute path replaces the base path completely, and '..' escapes above data_dir. When cortex-mem-service is running, an unauthenticated network caller or a malicious website in the user's browser can read credentials from disk or overwrite files like ~/.ssh/authorized_keys or shell startup scripts to run code on the machine.
Fix: Route all HTTP filesystem handlers through a path-validated CortexFilesystem, reject '..' and absolute paths in both file URIs and tenant_id values, and verify canonical path containment inside data_dir.
-
Mediumcortex-mem-service silently binds to 0.0.0.0 by default due to broken localhost parsing
cortex-mem-service/src/main.rs:142
The CLI defines --host with a default value of 'localhost', then parses it with IpAddr::from_str and falls back to 0.0.0.0 on failure. Because Rust's IpAddr parser only accepts numeric IP literals and never resolves hostnames, 'localhost'.parse() always fails, silently binding the unauthenticated HTTP server to 0.0.0.0:8085 on all network interfaces while also ignoring [server].host in config.toml. Not started by cortex-mem-mcp, but active by default whenever cortex-mem-service is launched without --host 127.0.0.1.
Fix: Change the default --host value to '127.0.0.1', resolve 'localhost' via ToSocketAddrs or fail startup on invalid host strings instead of falling back to 0.0.0.0, and honor [server].host from config.toml.
-
MediumPermissive CORS on unauthenticated HTTP API lets any website access local memories and file endpoints
cortex-mem-service/src/main.rs:137
cortex-mem-service attaches CorsLayer::permissive() to all routes with no authentication and ignores [server].cors_origins in config.toml (the Insights Bun proxy in server.ts likewise sets Access-Control-Allow-Origin: *). Even if the user binds cortex-mem-service to 127.0.0.1 as shown in the README, any website visited in the user's browser can make cross-origin fetch requests to http://127.0.0.1:8085/api/v2/* to read all stored memories, abuse configured LLM API keys, or invoke filesystem write endpoints.
Fix: Require an authentication token on /api/v2/* and replace CorsLayer::permissive() with an explicit Origin allowlist read from config.server.cors_origins, defaulting to local dashboard origins only.
-
LowStored XSS via unescaped Markdown links in Insights memory browser
cortex-mem-insights/src/lib/pages/Memories.svelte:128
Memories.svelte renders memory file previews with Svelte's {@html renderMarkdown(fileContent)}. While renderMarkdown escapes '&', '<', and '>', it does not escape double quotes or validate URL schemes before converting [text](url) into <a href="$2">$1</a>. Untrusted text stored in a memory file containing a javascript: link or quote-breaking attributes (such as autofocus and onfocus handlers) will execute arbitrary JavaScript in the browser when a user views that memory in the optional Insights dashboard.
Fix: Escape double and single quotes before Markdown substitution, restrict link href values to http:// and https:// URLs, or sanitize the HTML output with DOMPurify before passing it to {@html}.
-
LowExample configuration contains a hardcoded third-party API key
examples/cortex-mem-tars/config.example.toml:29
The example TUI configuration includes a commented-out ModelScope API key. Although never used unless a user copies the example file and uncomments the alternative LLM block, uncommenting it would send conversation data to an external account owned by a third party.
Fix: Replace the hardcoded ModelScope token in config.example.toml with a placeholder string and rotate or revoke the exposed key.
