fix : ReadFileTool shells out on ranged reads and interpolates untrusted path#5537
Open
hamdi-sakly wants to merge 1 commit intogoogle:mainfrom
Open
fix : ReadFileTool shells out on ranged reads and interpolates untrusted path#5537hamdi-sakly wants to merge 1 commit intogoogle:mainfrom
hamdi-sakly wants to merge 1 commit intogoogle:mainfrom
Conversation
sasha-gitg
requested changes
Apr 30, 2026
| else: | ||
| sed_range = f'{start},$' | ||
| cmd = f"cat -n '{path}' | sed -n '{sed_range}p'" | ||
| safe_path = shlex.quote(path) |
Collaborator
There was a problem hiding this comment.
This is great, thanks! Can you add a few unit tests?
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Description of change:
Problem:
ReadFileToolshells out for ranged reads (start_line > 1orend_lineis set)instead of reading the file directly:
The user-supplied
pathis interpolated directly into the shell command withoutany sanitization. A path containing shell-sensitive characters (e.g. single quotes,
semicolons) is interpreted as shell syntax, allowing unintended commands to be
executed as a side effect of a file-read operation.
Solution:
Used Python's built-in
shlex.quote()to safely escape the path before embeddingit in the shell command.
shlex.quote()ensures the shell always treats the entirepath as a single string argument regardless of its content.
shlexis a Python standard library module — no new dependencies are required.Testing Plan
Unit Tests:
The
marker.txtfile is no longer created, confirming the injected shellcommand is no longer executed.