Repository navigation
Refuse MCP registry writes through a planted path.tmp symlink - #364
Merged
Merged
Conversation
save_server_registry opened <path>.tmp with O_CREAT|O_TRUNC, so a symlink at that staging name redirected the write (including registry env secrets) into the link target before rename replaced only the symlink. unlink first (does not follow), then open with O_NOFOLLOW|O_EXCL. Dest-symlink rename already replaced the link. Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
…nofollow # Conflicts: # CHANGELOG.md
tylerreckart
marked this pull request as ready for review
September 21, 2026 12:58
tylerreckart
enabled auto-merge (squash)
September 21, 2026 12:58
Keep both Unreleased fixes after #366 landed: MCP registry tmp-symlink nofollow and remote --connect base URL query/userinfo. Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
…nofollow # Conflicts: # CHANGELOG.md
…nofollow # Conflicts: # CHANGELOG.md
Keep the MCP registry tmp-symlink Unreleased note alongside #363's atomic_write_file staging-name fix after that PR landed on main. Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
Keep the MCP registry tmp-symlink note under Unreleased after the v0.13.7 changelog cut moved sibling fixes into that release section. Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
…nofollow # Conflicts: # CHANGELOG.md
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.
Problem
save_server_registrystaged throughopen(<path>.tmp, O_WRONLY|O_CREAT|O_TRUNC). That follows a symlink at the staging name.--setup-toolspersists~/.arbiter/mcp_servers.jsonthis way, and registryenvblocks may hold secrets. A planted<path>.tmp→ elsewhere link was truncated with the registry JSON;renamethen replaced only the symlink, so the victim file stayed clobbered. Reproduced:mcp_servers.json.tmp→secret.txtleft the victim assession-body-with-TOKEN=super-secret.renameover a dest symlink already replaced the link (not its target). The hole was the staging name.Fix
unlinkthe staging name (does not follow), thenopenwithO_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXECand keep the existingfchmod(0600)/ destchmod(0600). Short writes retry onEINTR. Isolatedsrc/mcp/manager.cpp(same helper header comment + tests).Tests
unit_mcpsave_server_registry*— existing round-trip and empty-argv cases, leftover regular.tmp, planted.tmpsymlink does not clobber the target (victim staysdo-not-clobber, dest is 0600 and loadsTOKEN=super-secret), dest symlink is replaced rather than written through. 5/5 locally (33 assertions, + ASan ×3, + UBSan, + TSan).Independently mergeable against
main(0456350). Does not overlap #344 (subprocess/env) or #363 (atomic_file).git merge-tree --write-treevs main, #337, #343, #344, #360, #362, #363 CLEAN. CHANGELOG[Unreleased]is the usual sibling note.Note
Medium Risk
Changes secret-bearing MCP registry persistence on disk; behavior is safer but could fail writes if a hostile
.tmpcannot be unlinked, and symlink edge cases deserve regression coverage.Overview
Hardens atomic writes for
~/.arbiter/mcp_servers.jsonso a planted<path>.tmpsymlink cannot redirect registry JSON (includingenvsecrets) into an attacker-chosen file.save_server_registrynowunlinks the staging name first, then opens it withO_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC(same pattern asatomic_write_file), keepsfchmod(0600)/ finalchmod, and retrieswriteonEINTR.Documents the guarantee in
include/mcp/manager.h, adds an [Unreleased] CHANGELOG entry, andunit_mcptests for planted.tmpsymlinks, stale regular.tmpfiles, and destination symlinks replaced byrenamewithout clobbering link targets.Reviewed by Cursor Bugbot for commit e0a37e1. Bugbot is set up for automated code reviews on this repo. Configure here.