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.
TypeScript agentandroidandroid-automationappium-alternativeclaude-codecodexcursoremulatoriosios-automationmcpmcp-servermobilemobile-automationmobile-testingreal-devicesimulatorskills
fix: reject output paths with too many levels of symbolic links (#507)
Gil Megidish2f75dc0579ed
diff --git a/src/utils.ts b/src/utils.tsindex 17b2459..7ae6141 100644--- a/src/utils.ts+++ b/src/utils.ts@@ -79,6 +79,10 @@ export function validateFileExtension(filePath: string, allowedExtensions: strin}}+// windows follows up to 63 reparse points per path, linux 40 and macos 32;+// anything longer is rejected rather than handed to the write+const MAX_SYMLINK_HOPS = 64;+// Walk `filePath` to the real location a write would land on, following a// symlink in EVERY component - not just the parent directory. Resolving only the// parent let a symlink at, or before, the final component redirect the write@@ -90,9 +94,8 @@ export function validateFileExtension(filePath: string, allowedExtensions: strinfunction resolveWithSymlinks(filePath: string): string {let current = path.resolve(filePath);- // bound the walk so a symlink cycle cannot spin forever; a cycle makes the- // eventual write fail with ELOOP, so it is not an escape- for (let hops = 0; hops < 40; hops++) {+ // bound the walk so a symlink cycle cannot spin forever+ for (let hops = 0; hops < MAX_SYMLINK_HOPS; hops++) {const dir = path.dirname(current);const filename = path.basename(current);@@ -124,7 +127,7 @@ function resolveWithSymlinks(filePath: string): string {current = path.resolve(realDir, fs.readlinkSync(candidate));}- return current;+ throw new ActionableError(`"${filePath}" has too many levels of symbolic links.`);}export function validateOutputPath(filePath: string): void {diff --git a/test/utils.ts b/test/utils.tsindex 085993f..2d95f2d 100644--- a/test/utils.ts+++ b/test/utils.ts@@ -186,5 +186,18 @@ test.describe("utils", () => {fs.rmSync(first, { force: true });}});++ test("should reject a symlink cycle", () => {+ const first = createSymlink(path.join(process.cwd(), "mobile-mcp-cycle-placeholder.png"));+ const second = createSymlink(path.basename(first));+ fs.rmSync(first);+ fs.symlinkSync(path.basename(second), first);+ try {+ expect(() => validateOutputPath(first)).toThrow(/too many levels of symbolic links/);+ } finally {+ fs.rmSync(second, { force: true });+ fs.rmSync(first, { force: true });+ }+ });});});