fix(tools): remove shell-based ranged file reads#5558
Open
failuresmith wants to merge 2 commits intogoogle:mainfrom
Open
fix(tools): remove shell-based ranged file reads#5558failuresmith wants to merge 2 commits intogoogle:mainfrom
failuresmith wants to merge 2 commits intogoogle:mainfrom
Conversation
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.
Problem:
ReadFileTooluses a shell-basedcat -n ... | sed -n ...path for ranged reads whenstart_line > 1orend_lineis provided. PR #5537 improves the original report by quotingpath, but the ranged-read path still shells out and still interpolatesend_lineinto thesedcommand.Because tool arguments are not enforced as runtime-validated integers in this path, that leaves a remaining command-injection surface. The shell path also masks missing-file errors for ranged reads by returning
okwith empty content.Solution:
Remove the shell-based ranged-read branch entirely and route all reads through
self._environment.read_file(path)plus the existing Python line-slicing logic.This fixes the issue by eliminating shell interpretation from
ReadFileToolrather than trying to quote individual inputs. It also preserves correct missing-file behavior for ranged reads and adds regression coverage for:end_lineinputTesting Plan
Verified with targeted unit tests for ranged reads and with a manual PoC that previously triggered command execution via
end_line.Unit Tests:
Manual End-to-End (E2E) Tests:
Observed after the fix:
{'status': 'error', 'error': '`end_line` must be an integer if provided.'} marker exists: FalseChecklist
Additional context
This is intended as a complete fix for the ranged-read injection surface, rather than a partial mitigation limited to quoting
path.