fix(security): prevent shell injection in ADB operator#1883
Open
JasonOA888 wants to merge 1 commit into
Open
Conversation
The ADB operator was vulnerable to shell injection through multiple
attack vectors:
1. exec() with string concatenation: 'adb devices' used exec() instead
of execFile(), setting an unsafe pattern.
2. handleType(): User-controlled text was interpolated directly into
shell commands: `-keyboard "${text}"` - an attacker could
inject arbitrary shell commands via crafted text content.
3. handleClick()/handleSwipe(): While coordinates are typed as numbers,
no validation ensured they were actually finite numbers.
4. executeWithYadb(): Accepted raw string subCommands that were directly
concatenated into shell commands.
Fix:
- Replace exec() with execFile() using argument arrays
- Add shellEscape() utility for proper single-quote escaping
- Change executeWithYadb() to accept string arrays with proper escaping
- Add Number.isFinite() validation for all numeric parameters
- Use Math.round() to ensure clean integer output in shell commands
✅ Deploy Preview for tarko ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for agent-tars-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Security Vulnerability: Shell Injection in ADB Operator
Problem
The ADB operator (
multimodal/gui-agent/operator-adb/src/AdbOperator.ts) contains multiple shell injection vulnerabilities:exec()with string command —getConnectedDevices()usesexec('adb devices')with Node.jsexec(), which spawns a shell. While this specific call has no user input, it sets an unsafe pattern.handleType()text injection (Critical) — User-controlled text content is directly interpolated into a shell command:An attacker controlling the agent's type action could inject arbitrary commands by crafting text like:
foo"; rm -rf /; echo "handleClick()/handleSwipe()coordinate injection — While coordinates are typed asnumber, no validation ensures they are actually finite numbers. A value likeNaNorInfinitycould produce unexpected shell behavior.executeWithYadb()raw string subCommands — The method accepts raw string arguments that are directly concatenated into shell commands without escaping.Impact
handleType()path allows arbitrary command execution on the Android device through shell injection when processing non-ASCII text input (Chinese characters, etc.).Fix
Replace
exec()withexecFile()— Uses argument arrays instead of shell string commands for theadb devicescall.Add
shellEscape()utility — Properly escapes strings for safe inclusion in shell commands by wrapping in single quotes and escaping existing single quotes.Refactor
executeWithYadb()to acceptstring[]— Arguments are now passed as an array and each is individually shell-escaped before being joined into the command string.Add
Number.isFinite()validation — All numeric parameters (coordinates, duration) are validated before being interpolated into commands.Use
Math.round()for numeric values — Ensures clean integer output in generated shell commands.Files Changed
multimodal/gui-agent/operator-adb/src/AdbOperator.tsTesting