Skip to content

Mobile MCP: let AI agents drive your iOS and Android apps. MCP server for simulators, emulators and real devices. Works with Claude Code, Codex, Cursor and any MCP client.

fix: shell escaping through android launchApp (#279)

Gil Megidishcd200fb2aae7
diff --git a/src/android.ts b/src/android.ts
index bc9c794..3e01ff0 100644
--- a/src/android.ts
+++ b/src/android.ts
@@ -5,6 +5,7 @@ import { existsSync } from "node:fs";
import * as xml from "fast-xml-parser";
import { ActionableError, Button, InstalledApp, Robot, ScreenElement, ScreenElementRect, ScreenSize, SwipeDirection, Orientation } from "./robot";
+import { validatePackageName } from "./utils";
export interface AndroidDevice {
deviceId: string;
@@ -140,6 +141,7 @@ export class AndroidRobot implements Robot {
}
public async launchApp(packageName: string): Promise<void> {
+ validatePackageName(packageName);
try {
this.silentAdb("shell", "monkey", "-p", packageName, "-c", "android.intent.category.LAUNCHER", "1");
} catch (error) {
@@ -356,6 +358,7 @@ export class AndroidRobot implements Robot {
}
public async terminateApp(packageName: string): Promise<void> {
+ validatePackageName(packageName);
this.adb("shell", "am", "force-stop", packageName);
}
diff --git a/src/ios.ts b/src/ios.ts
index 07b5f54..77bb8e0 100644
--- a/src/ios.ts
+++ b/src/ios.ts
@@ -3,6 +3,7 @@ import { execFileSync } from "node:child_process";
import { WebDriverAgent } from "./webdriver-agent";
import { ActionableError, Button, InstalledApp, Robot, ScreenSize, SwipeDirection, ScreenElement, Orientation } from "./robot";
+import { validatePackageName } from "./utils";
const WDA_PORT = 8100;
const IOS_TUNNEL_PORT = 60105;
@@ -138,11 +139,13 @@ export class IosRobot implements Robot {
}
public async launchApp(packageName: string): Promise<void> {
+ validatePackageName(packageName);
await this.assertTunnelRunning();
await this.ios("launch", packageName);
}
public async terminateApp(packageName: string): Promise<void> {
+ validatePackageName(packageName);
await this.assertTunnelRunning();
await this.ios("kill", packageName);
}
diff --git a/src/iphone-simulator.ts b/src/iphone-simulator.ts
index d4a15a4..901677e 100644
--- a/src/iphone-simulator.ts
+++ b/src/iphone-simulator.ts
@@ -6,6 +6,7 @@ import { join, basename, extname } from "node:path";
import { trace } from "./logger";
import { WebDriverAgent } from "./webdriver-agent";
import { ActionableError, Button, InstalledApp, Robot, ScreenElement, ScreenSize, SwipeDirection, Orientation } from "./robot";
+import { validatePackageName } from "./utils";
export interface Simulator {
name: string;
@@ -102,10 +103,12 @@ export class Simctl implements Robot {
}
public async launchApp(packageName: string) {
+ validatePackageName(packageName);
this.simctl("launch", this.simulatorUuid, packageName);
}
public async terminateApp(packageName: string) {
+ validatePackageName(packageName);
this.simctl("terminate", this.simulatorUuid, packageName);
}
diff --git a/src/robot.ts b/src/robot.ts
index 173d812..e88821b 100644
--- a/src/robot.ts
+++ b/src/robot.ts
@@ -42,6 +42,7 @@ export class ActionableError extends Error {
}
}
+
export type Orientation = "portrait" | "landscape";
export interface Robot {
diff --git a/src/utils.ts b/src/utils.ts
new file mode 100644
index 0000000..a93e270
--- /dev/null
+++ b/src/utils.ts
@@ -0,0 +1,7 @@
+import { ActionableError } from "./robot";
+
+export function validatePackageName(packageName: string): void {
+ if (!/^[a-zA-Z0-9._]+$/.test(packageName)) {
+ throw new ActionableError(`Invalid package name: "${packageName}"`);
+ }
+}