Harden sandbox file access against symlink TOCTOU (CWE-367) with symlink-safe open #105
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 project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
Depends on
#77 Epic: LLM Agent Runtime Stabilization — reliability, resource enforcement & correctness hardening
cleveragents/cleveractors-core
#120 feat(agents): symlink-safe sandbox file access closing TOCTOU window
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core#105
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 sandbox file access closing TOCTOU windowfeature/m1-symlink-safe-file-access(provisional — align the milestone number with the milestone assigned at triage)Background and context
ADR-2035 gave inline code the sandbox-confined
read_file/write_filehelpers,backed by the shared cores in
cleveractors.agents.file_access(
SandboxRootPolicy,FileAccessCore) introduced in PR #103. Containment isenforced by
SandboxRootPolicy.resolve, which computes the fully resolved realpath (
os.path.realpath, symlinks followed) and checks it is within the sandboxroot at validation time. The helper/tool then opens that resolved path via
FileAccessCore.read_window/FileAccessCore.write(plainopen(...)).Because validation and the subsequent
open()are two separate steps operatingon a path string, a time-of-check/time-of-use (TOCTOU) race (CWE-367)
remains: an attacker who can write into a directory inside the sandbox root
can, between
resolve()andopen(), replace a path component with a symlinkpointing outside the root.
open()re-traverses the path components at opentime and follows the swapped-in symlink, so the read or write can land outside
the sandbox root even though the pre-checked real path was inside it.
This window is inherited unchanged from the pre-existing
file_writetool — itis not introduced by ADR-2035 — and it is explicitly recorded as a residual
limitation in the ADR-2035 Consequences. Exploitation requires an attacker who
already holds write access to a parent directory within the sandbox and can win
a race against the operation, so the practical bar is high; this issue is
defence-in-depth hardening rather than a reported failure.
Current behavior
SandboxRootPolicy.resolve(path)validatesos.path.realpath(path)againstthe root, then returns the resolved path string.
FileAccessCore.read_window/FileAccessCore.writeopen that string with aplain
open(...), which re-resolves symlinks in every path component at opentime.
after the check but before the open is followed, allowing access
outside the sandbox root. There is no
O_NOFOLLOW,openat/dir_fd, orpost-open inode re-verification.
Expected behavior
File opens are confined so that no path component can be a symlink that escapes
the sandbox root at open time, closing the TOCTOU window. Candidate
approaches (to be decided in an ADR if the chosen mechanism is architecturally
significant):
os.open(..., dir_fd=...)walked component-by-component withO_NOFOLLOW(and
O_DIRECTORYfor intermediates), so no symlink is ever followed out ofthe root; or
(
os.fstatdevice/inode compared against a root the descriptor is confinedto) before any read/write, rejecting on mismatch.
Legitimate in-root reads and writes (including the existing
w/a/insertmodes) MUST continue to behave exactly as today.
Acceptance criteria
the sandbox root fails without reading or writing, even when the symlink
is created after
SandboxRootPolicy.resolvehas validated the path.out-of-root symlink after validation likewise fails without reading or
writing.
results, including all
file_writemodes (w,a,insert).file_read/file_writetools and the inlineread_file/write_filehelpers are protected (no divergence).
code; the §13.2.1 built-in table remains unchanged.
nox -s coverage_report.Supporting information
following).
src/cleveractors/agents/file_access.py(
SandboxRootPolicy.resolve,FileAccessCore.read_window,FileAccessCore.write), with the tool adapters incleveractors.agents.tool(ToolAgent._file_read_tool,ToolAgent._file_write_tool).docs/adr/ADR-2035-inline-code-sandboxed-file-access.md(Consequencessection records this residual TOCTOU window); shipped in PR #103 for issue #93.
§13.3, an ADR + a spec revision (see §21 of
docs/index.md) is requiredbefore implementation.
Subtasks
openat/dir_fd+O_NOFOLLOWwalk vs. open-then-fstat re-verification); write an ADR if the mechanism
is architecturally significant.
FileAccessCorefor reads and for allwrite modes (
w/a/insert), keeping a single confinement mechanismshared by tools and helpers.
components is refused; legitimate in-root access still succeeds.
refused end to end.
docs/index.md§13.3 (via ADR + revision bump) if boundarysemantics change.
nox -s coverage_report.nox(all default sessions), fix any errors.Definition of Done
This issue is complete when:
Metadata exactly.
master, reviewed, and merged.