Require CORTEX_API_KEY for MCP server in production#52
Merged
Conversation
When CORTEX_API_KEY is unset, mcp/server.js falls back to sending the legacy X-Cortex-Roles header, which api/deps.py trusts whenever CORTEX_API_KEYS is not configured server-side. Any process with MCP env access could therefore claim admin/gdpr_officer without a real key and invoke GDPR-adjacent tools. Refuse all MCP tool calls when ENVIRONMENT=production and CORTEX_API_KEY is missing, log a warning at startup, and document the requirement in .env.example and mcp/Dockerfile. Auth resolution is extracted into mcp/auth.js so it can be unit tested independently of the MCP SDK. Fixes #51 Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
mcp/server.jsfalls back to the legacyX-Cortex-Rolesheader whenCORTEX_API_KEYis unset, whichapi/deps.pytrusts wheneverCORTEX_API_KEYSis not configured server-side. Any process with MCP env access could escalate toadmin/gdpr_officerand invoke GDPR-adjacent tools without a real key.ENVIRONMENT=productionandCORTEX_API_KEYis missing, and logs a warning at startup..env.exampleandmcp/Dockerfile(which now defaultsENVIRONMENT=production).mcp/auth.jsso it's unit-testable independently of the MCP SDK; addedmcp/server.test.js(npm testvia Node's built-in test runner).Test plan
npm testinmcp/— 5 passing tests covering production+missing key (blocked), production+key (allowed), dev without key (allowed), default/unset environment, and case-insensitivity.postJsonthrows an explicit auth error for all three tools (cortex_query,cortex_remember,cortex_inject) when blocked.Fixes #51
Made with Cursor