You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rtk init --codex writes through a symlinked AGENTS.md, so a cloned repo can redirect the write outside the project #4156
Pre-existing on develop (verified at 0924356b, rtk 0.48.0). Surfaced while reviewing #4119, which is unrelated to it — #4119 documents this case rather than guarding it, because atomic_write preserving a user-maintained symlink is intentional (#653) and pinned by tests.
Summary
git stores symlinks, so a repository can ship AGENTS.md as a relative symlink pointing outside the working tree. rtk init --codex reads through the link and writes through it: @RTK.md is appended to a file outside the project, exit 0, no warning. NamedTempFile::persist also replaces the inode, so the target's mode resets from 644 to 600.
No local setup is required by the victim — cloning the repository and running rtk init --codex is enough.
Reproduction
W=$(mktemp -d);cd"$W"
mkdir outside origin
printf'user notes\n'> outside/AGENTS.md
chmod 644 outside/AGENTS.md
cd origin
git init -q -b main .; git config user.email [email protected]; git config user.name t
ln -s ../outside/AGENTS.md AGENTS.md
git add -A; git commit -qm "ship AGENTS.md as a relative symlink"cd"$W"; git clone -q origin clone;cd clone
rtk init --codex < /dev/null
cat "$W/outside/AGENTS.md"
stat -c '%a'"$W/outside/AGENTS.md"
Observed
exit=0
$ cat $W/outside/AGENTS.md
user notes
@RTK.md
$ stat -c '%a' $W/outside/AGENTS.md
600
The file outside the clone was modified and its mode changed from 644 to 600. rtk init reported success and printed AGENTS.md: @RTK.md reference added, naming the in-project path.
Expected
rtk init --codex confines its project-mode writes to the project. A project AGENTS.md that resolves outside the working tree should at least produce a warning naming the resolved target, rather than a silent write and a silent mode change.
Mechanism
patch_agents_md (src/hooks/init.rs) reads with fs::read_to_string(path), which follows the link.
It writes with atomic_write, whose resolve_atomic_target calls fs::canonicalize specifically so the rename lands on the real file and the symlink survives.
NamedTempFile::persist renames a fresh temp file over the resolved target, so the target's previous inode (and its mode) is replaced.
RTK.md is not affected: it is written with fs::rename, which does not follow a symlink at the destination.
Impact
Bounded: one line of text appended to an attacker-chosen path writable by the user, plus a permission reset. No execution. The interesting part is that it needs nothing from the victim but a clone and rtk init --codex.
The uninstall side does the same. rtk init --codex --uninstall edits a symlinked project AGENTS.md through the link: the @RTK.md line is removed from the file outside the working tree, exit 0. This is the same on develop (5ab6291) and on #4463's head. #4463's containment guard covers .codex/hooks.json and its .bak, not AGENTS.md.
Activity
feat(init): route every init write through one guarded path
feat(init): route every init write through one guarded path
feat(init): route every init write through one guarded path
feat(init): route every init write through one guarded path
feat(init): route every init write through one guarded path
feat(init): route every init write through one guarded path
feat(init): route every init write through one guarded path
KuSh commentedon Oct 30, 2026
The uninstall side does the same.
rtk init --codex --uninstalledits a symlinked projectAGENTS.mdthrough the link: the@RTK.mdline is removed from the file outside the working tree, exit 0. This is the same ondevelop(5ab6291) and on #4463's head. #4463's containment guard covers.codex/hooks.jsonand its.bak, notAGENTS.md.feat(init): route every init write through one guarded path