fix: escape file path in read_file fallback to prevent shell injection#209
Open
haosenwang1018 wants to merge 1 commit intoConway-Research:mainfrom
Open
Conversation
The read_file tool's fallback path interpolated the file path directly
into a shell command (`cat ${filePath}`) without escaping. When the
Conway readFile API fails and the fallback triggers, a crafted path
containing shell metacharacters (e.g., `; cat wallet.json` or
`$(whoami)`) could execute arbitrary commands and bypass the sensitive
file read protection.
The fix uses the existing `escapeShellArg()` function (already defined
in the same file) to properly single-quote the path, neutralizing
semicolons, subshell syntax, and other shell metacharacters.
Added 4 regression tests covering spaces, semicolons, single quotes,
and $() subshell syntax in file paths.
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
Problem: The
read_filetool's fallback path constructs a shell command by interpolating the file path directly without escaping:When the primary Conway
readFileAPI fails and this fallback triggers, a file path containing shell metacharacters (;,$(), backticks, etc.) can execute arbitrary commands. This bypasses the sensitive file read protection — for example, a path likenonexistent; cat ~/.automaton/wallet.jsonwould pass the basename check but executecat nonexistent; cat ~/.automaton/wallet.jsonin the shell.Why it matters: This is a defense-in-depth gap. Although the automaton's own model generates the path, a prompt injection attack could cause the model to construct a malicious path that exploits the unescaped shell interpolation to exfiltrate secrets (wallet keys,
.env,automaton.json).What changed: Used the existing
escapeShellArg()function (already defined at line 2523 of the same file, used bycreateInstalledToolExecutor) to properly single-quote the file path in the fallbackcatcommand. Inside single quotes, all shell metacharacters (;,$(),`,|,&&, etc.) are treated as literal characters.What did NOT change: The primary
readFileAPI path, the sensitive file basename check, or theescapeShellArgfunction itself.Change Type
Security Impact
Verification
Added 4 regression tests to
tools-security.test.ts:'\''technique$()subshell syntax is treated as literal textAll 68 tests pass (64 existing + 4 new).