fix(file): anchor device symlink guard to task cwd (dropped commit from #34466) - #50334
Merged
Conversation
The read_file device guard now walks symlink hops before the file operation layer, but that hop walk still interpreted relative paths against the Python process cwd. In sessions where TERMINAL_CWD points at the task workspace, a relative workspace symlink to a blocked alias such as /dev/../dev/stdin could therefore miss the intermediate device target before later task-cwd resolution. Anchor relative device checks to the task base before symlink-hop inspection so the pre-I/O guard sees the same workspace path that read_file would otherwise read. Absolute device paths and the existing final realpath fallback remain unchanged. Refs #10141 Refs #29158
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:2984: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
Unchanged: 5932 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Picks up the second commit of PR #34466 that was dropped during the #50221 salvage. The
read_filedevice guard now anchors relative device-path checks to the task cwd before the symlink-hop walk, closing a residual bypass that the first commit (already on main) left open.Root cause
#50221 cherry-picked only commit 1 (
harden read_file device alias blocking). The author force-pushed a follow-up commit (acee75a8, announced in a PR comment, not the body) that I missed. That follow-up fixes the case where the symlink-hop walk interpreted a relative workspace symlink against the Python process cwd instead of the task cwd — so a relative symlink to/dev/../dev/stdinin a session whereTERMINAL_CWDis the workspace would miss the blocked device target beforeread_file's own task-cwd resolution.Changes
tools/file_tools.py:_is_blocked_device(filepath, base_dir=None)joins relative paths tobase_dirbefore normpath;read_file_toolpasses_resolve_base_dir(task_id)for non-absolute inputs. Absolute paths and the final realpath fallback unchanged.tests/tools/test_file_read_guards.py: regression test for a task-cwd-relative device-alias symlink with process cwd != task cwd.Validation
/dev/../dev/stdinsymlink,TERMINAL_CWD=workspace, process cwd elsewheretests/tools/test_file_read_guards.pyE2E: built the exact bypass (workspace symlink →
/dev/../dev/stdin, chdir to a different process cwd,TERMINAL_CWDset) and confirmedread_file_toolreturns "device file" and never reaches the read sink.Picks up the dropped commit from PR #34466 by @egilewski. Refs #10141, #29158.
Infographic