Skip to content

fix(mcp): write ~/.cursor/mcp.json owner-only (0600) - #182

Merged
vsn411 merged 2 commits into
secfoo-com:mainfrom
nabeelbaghoor:fix/171-security-write-cursor-mcp-json-with
Nov 21, 2026
Merged

vsn411 merged 2 commits into
secfoo-com:mainfrom
nabeelbaghoor:fix/171-security-write-cursor-mcp-json-with

Conversation

@nabeelbaghoor

Copy link
Copy Markdown
Contributor

Closes #171

What does this change, and why?

secfoo mcp sync --agent agent wrote ~/.cursor/mcp.json with Path.write_text, so a new file got the process umask (usually 0644) and an existing 0644 file stayed world-readable. The file carries each server's env and headers, which usually hold secrets (the secfoo-memory bearer key, Jira or Confluence tokens).

sync_cursor now writes the file with config.write_private_text, the same helper write_claude_mcp_config uses. It creates the file as 0600 and tightens an existing file with fchmod before writing, so there is no window where the secrets are readable by others. On Windows, where fchmod does not exist, the helper skips that step, so the sync does not fail there.

Testing

  • pytest tests passes (see below: no new failures)

  • ruff check . passes (see below: clean on the changed files)

  • Added/updated tests for the behavior change

  • New test_sync_cursor_writes_config_owner_only (POSIX only, skipped on Windows), parametrized for a new file and for an existing file at 0644: both fail on main (mode 0644) and pass with this change.

  • pytest tests/test_mcp.py tests/test_store_privacy.py: 26 passed.

  • pytest tests: 1920 passed, 12 failed. The same 12 tests fail on an untouched checkout of main in my environment (mermaid vendoring and CLI environment tests such as test_architecture_dashboard.py and test_cli_assessment.py), none of them touch MCP sync.

  • ruff check src/secfoo/mcp.py tests/test_mcp.py: clean. ruff check . with ruff 0.17.6 reports 143 findings in files this PR does not touch, the same count as on main.

… added

The file is only rewritten when a new server is added, so a user whose
older secfoo left it at 0644 kept a world-readable file on every re-run
where all servers were already configured -- the usual upgrade path.
chmod it to 0600 in that case too (POSIX only; an OSError never fails
the sync).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411

vsn411 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, and for the clear write-up and the parametrized test for both the new-file and existing-0644 cases. Using write_private_text is exactly right.

I pushed one small follow-up commit (ec2166b) to your branch rather than asking for another round. The file is only rewritten when a new server is added. A user whose older secfoo already left ~/.cursor/mcp.json at 0644 would usually re-run sync with every server already configured, so nothing got written and the file stayed world-readable. The commit chmods it to 0600 in that case too (POSIX only, and an OSError never fails the sync), and adds a test for it.

Once CI is green this is ready to merge. Thanks again, and we'd be glad to see more from you.

@vsn411
vsn411 merged commit dc3e101 into secfoo-com:main Nov 21, 2026
7 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

nabeelbaghoor now has 3 points (rank #12). 22 more to reach Bronze.

Full leaderboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: write ~/.cursor/mcp.json with 0600 permissions (it holds MCP auth headers)

2 participants