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
fix(cache-memory): reject symlinks in agent memory to prevent Stage 3 credential theft (#524)
* Initial plan
* fix(cache-memory): reject symlinks in agent memory to prevent Stage 3 credential theft
Three-part defense against the symlink-following attack described in the
security audit:
1. collect_files: use entry.file_type() (does NOT follow symlinks) instead
of path.is_dir() when deciding whether to recurse. Both file symlinks
and directory symlinks are now skipped with a warning, so they are
never added to the file list at all.
2. process_agent_memory: canonicalize the memory source base directory
once before the per-file loop, then canonicalize each source file path
and verify it starts_with the canonical base. This TOCTOU guard catches
any symlink that slips through the collection phase (e.g., via a race
condition) before any read or copy takes place.
3. Tests (Unix-only): added four new #[cfg(unix)] async tests that create
real symlinks on disk and confirm:
- collect_files skips file symlinks
- collect_files skips directory symlinks (no recursion)
- process_agent_memory skips file symlinks pointing outside the base
- process_agent_memory skips directory symlinks pointing outside the base
Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/efdc2afe-1050-4068-8433-cd9a60762981
Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
* fix(cache-memory): address code review feedback on symlink fix
- Add clarifying comment on else-if branch in collect_files explaining it
is only reached for real (non-symlink) directories
- Improve canonicalize error message to explain the security purpose
- Add test_collect_files_skips_relative_symlinks covering the relative
symlink attack vector (e.g. ../secret.txt)
- Fix assertion style: 'must NOT' -> 'must not'
Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/efdc2afe-1050-4068-8433-cd9a60762981
Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
* fix(cache-memory): reject symlink at agent_memory base directory level
The existing fix guarded against symlinks *inside* agent_memory, but
if the agent_memory entry itself is a directory symlink the old
`is_dir()` check follows it (returning true), and canonicalize()
resolves relative to the symlink target — so every collected file
passes the starts_with guard and sensitive files are copied.
Fix: replace `exists()/is_dir()` with `symlink_metadata()` (lstat) on
memory_source and explicitly reject the symlink case before any further
processing.
Also adds test_process_memory_rejects_base_directory_symlink which
plants a `agent_memory -> /sensitive/dir` symlink and asserts nothing
is copied to the output.
Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/971a1892-4711-4142-98ad-d85574576689
Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
0 commit comments