fix(config): a symlinked ~/.kigi/config.toml survives a save
Every config.toml writer wrote a tmp beside the path and renamed it over the path. With config.toml symlinked into a dotfiles repo, the rename replaced the link with a regular file: the repo copy went stale and the link was gone. `config_write_dest` resolves the destination before a writer names its tmp. For the user's own config path a symlink resolves to its referent, so the tmp sits on the referent's filesystem and the rename stays atomic. A dangling link is an error, not a clobber. All eight writers call it: `save_config`, the four MCP writers, and the three import writers. Only the user's config path is followed, and only while `user_kigi_home()` resolves. `kigi mcp add --scope project` and the Claude project import write `.kigi/config.toml` inside the repo; a hostile repo could ship that file as a symlink to any file the user owns. With no home, `kigi_home()` falls back to `./.kigi`, which is that same project tree, so nothing is followed then. Untrusted paths come back unchanged and the link itself is replaced, as before. AGENTS.md records the rule. Tests (unix; run on Linux under WSL): helper cases including the no-home case, a project-scope save that spares the link's target, and an end-to-end save under KIGI_SHARE_DIR. The end-to-end test fails with following disabled. Windows symlinks were not exercised: the host lacks the privilege. Ported from upstream (grok-build config/fs_atomic.rs LeafSymlink::Follow, 1.0.35): the rule, not the 1375-line module.
This commit is contained in:
8 files changed
+164
No files matched your search
@@ -64,6 +64,15 @@ The cure is rmcp 3.x (upstream runs 3.2), a major bump not yet taken.
|
||||
switch that never stuck). Plain rename stays correct only for true moves
|
||||
whose destination doesn't pre-exist (worktree-pool markers, corrupt-file
|
||||
backups). Write failures must at least `warn!` — never `let _ =`.
|
||||
- **config.toml writers resolve their destination through
|
||||
`util::config::config_write_dest` before they name the tmp file.** A
|
||||
symlinked `~/.kigi/config.toml` (dotfiles) keeps its link: the tmp sits
|
||||
beside the referent and replaces it. Only that one path is followed, and
|
||||
only while `user_kigi_home()` resolves (with no home, `kigi_home()` is the
|
||||
project's own `./.kigi`). A project `.kigi/config.toml` is
|
||||
repo-controlled, and following its symlink would overwrite whatever file
|
||||
a hostile repo points it at; there the link itself is replaced.
|
||||
Credential and managed stores never follow symlinks.
|
||||
- The root `Cargo.toml` is hand-maintained (upstream's generator is not in
|
||||
this repo). Members sorted; versions inherited from
|
||||
`workspace.package.version` — the single source of truth for the release
|
||||
|
||||
Reference in new issue
Block a user