fix(install): validate path in mobile_install_app to prevent path traversal#332
fix(install): validate path in mobile_install_app to prevent path traversal#332sebastiondev wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
The
mobile_install_apptool accepts apathparameter from the AI agent without any validation, unlike thesave_screenshotandstart_screen_recordingtools which already usevalidateFileExtensionandvalidateOutputPath. This means a prompt-injected agent could be directed to read or install files from arbitrary filesystem locations (CWE-22: Path Traversal).This fix adds the same validation that already protects
save_screenshotandstart_screen_recordingtomobile_install_app, making the security posture consistent across all file-accepting tools.Vulnerability Details
CWE-22 (Improper Limitation of a Pathname to a Restricted Directory)
mobile_install_apphandler insrc/server.tspathparameter from the MCP tool call flows directly intorobot.installApp(path)with no path or extension validation.mobile_install_appwith a traversal path like../../../tmp/malicious.apkor an absolute path outside the working directory.Proof of Concept
With the MCP server running, an AI agent could be prompted (via injection) to execute:
{ "tool": "mobile_install_app", "arguments": { "device": "emulator-5554", "path": "/etc/sensitive-data/payload.apk" } }Or with directory traversal:
{ "tool": "mobile_install_app", "arguments": { "device": "emulator-5554", "path": "../../../../tmp/attacker-controlled.apk" } }Before the fix, both calls pass through to
robot.installApp()without any checks. After the fix,validateOutputPathrejects paths outside the current working directory and temp directory, andvalidateFileExtensionrejects anything that isn't.apk,.ipa,.zip, or.app.Fix Description
The fix adds two lines to the
mobile_install_apphandler, calling the existing utility functions:validateFileExtension(path, ALLOWED_INSTALL_EXTENSIONS, "mobile_install_app")— restricts accepted files to.apk,.ipa,.zip, and.app, preventing the tool from being used to access arbitrary file types.validateOutputPath(path)— resolves the path (following symlinks) and checks it falls within allowed root directories (cwd or temp), preventing directory traversal.A new constant
ALLOWED_INSTALL_EXTENSIONSis added alongside the existingALLOWED_SCREENSHOT_EXTENSIONSandALLOWED_RECORDING_EXTENSIONS.Testing
validateOutputPathresolves symlinks and checks against allowed roots (cwd, tmpdir) — paths like../../../../etc/passwdand absolute paths outside these roots are rejected withActionableError.validateFileExtensionchecks the lowercased extension against the allowlist — files likepayload.shordata.txtare rejected.save_screenshot(line ~380) andstart_screen_recording(line ~395), ensuring consistency.Adversarial Review
Before submitting, we considered whether this finding is practically exploitable. The MCP server runs locally and the attacker needs prompt injection to control the agent's tool calls. However, prompt injection is a well-documented and practical attack vector against AI agents, and the existing codebase already treats it as a threat — that's why
save_screenshotandstart_screen_recordinghave these exact validations. Themobile_install_apptool was simply missed. This fix closes the gap and makes the security model consistent.Submitted by Sebastion — autonomous open-source security research from Foundation Machines. Free for public repos via the Sebastion AI GitHub App.