Harden built-in file_read directory listing against symlink TOCTOU (CWE-367) #126
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
#77 Epic: LLM Agent Runtime Stabilization — reliability, resource enforcement & correctness hardening
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core#126
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Metadata
feat(agents): symlink-safe directory listing in file_read toolfeature/mN-symlink-safe-directory-listing(provisional — align the milestone number with the milestone assigned at triage)Background and context
ADR-2035 D-9 (#105, PR !120) closed a time-of-check/time-of-use race (CWE-367) in
FileAccessCore.read_window/writeby routing every file open through a newSymlinkSafeOpener, which walks the resolved path one component at a time withO_NOFOLLOWset, so a symlink swapped into any component after path validation but before the open is refused instead of silently followed.That hardening covers file opens only.
ToolAgent._file_read_tool's directory-listing branch (cleveractors.agents.tool) — used whenfile_readis pointed at a directory instead of a file — enumerates the directory with plainos.listdir/os.path.isdir/os.path.getsize, a call chain that never reachesFileAccessCoreand therefore never reachesSymlinkSafeOpener. This gap was flagged during PR !120's review (minor issue #3) and deliberately left out of that PR: it is pre-existing (not introduced by D-9), and closing it means extending the component-wise hardening to a structurally different filesystem primitive (directory enumeration, notopen()) — a distinct unit of work from #105's file-open scope.Current behavior
_file_read_toolperforms its own safe-mode /../ absolute-path / symlink-escape checks onfilepath(existingSandboxRootPolicy().is_within(os.path.realpath(filepath))check).os.path.isdir(filepath)is true, it lists the directory directly:os.listdir(filepath), then per entryos.path.isdir(entry_path)andos.path.getsize(entry_path)— all plain, symlink-following calls.os.listdir/os.path.isdir/os.path.getsizecalls re-resolve symlinks in every component and will silently follow the swap, leaking the outside directory's entry names and sizes (not file content) back to the caller.Expected behavior
Directory listing is confined so that no path component can be a symlink that escapes the sandbox root at enumeration time, closing the same class of race D-9 closed for file opens. Candidate approach: extend
SymlinkSafeOpener(or add a sibling helper) to open the target directory itself via a component-wiseO_NOFOLLOW/O_DIRECTORYwalk, yielding a verifieddir_fd, then enumerate via that descriptor (e.g.os.listdir(dir_fd),os.stat(entry, dir_fd=dir_fd)) instead of by path string.Legitimate in-root directory listings MUST continue to behave exactly as today (same output format, same entries, same reported sizes).
Acceptance criteria
[FILE_READ_SUCCESS]📁 Directory: ...format, entry names, markers, and reported sizes).file_read's normal (non-directory) read behavior.nox -s coverage_report.Supporting information
src/cleveractors/agents/tool.py(ToolAgent._file_read_tool, theos.path.isdir(filepath)branch),src/cleveractors/agents/file_access.py(SymlinkSafeOpener, the collaborator to extend or pair with a sibling).docs/adr/ADR-2035-inline-code-sandboxed-file-access.md(D-9) for the file-open hardening this issue extends the same technique to.docs/index.md§13.3/§4.5.4, an ADR + a spec revision (§21 ofdocs/index.md) is required before implementation; the current expectation is that it will not, since — like D-9 — this only hardens enforcement of an already-existing boundary, not the set of paths admitted or rejected.Subtasks
SymlinkSafeOpenervs. a sibling helper), documenting it as an ADR-2035 revision if the mechanism is architecturally significant.ToolAgent._file_read_tool, replacing the plainos.listdir/os.path.isdir/os.path.getsizecalls on the directory branch.nox -s coverage_report.nox(all default sessions), fix any errors.Definition of Done
This issue is complete when:
master, reviewed, and merged.