Symlink-Following Attack
A sandbox-escape pattern where an attacker places a symbolic link inside a sandboxed directory, pointing to a target outside the directory; subsequent operations through the link transparently resolve to the target, bypassing application-layer boundary checks that inspected only the source path.
A Symlink-Following Attack is a sandbox-escape pattern where an attacker places a symbolic link (or hardlink) inside a sandboxed directory, pointing to a target outside the directory. Subsequent operations against the link's source path resolve transparently to the link's target, bypassing application-layer boundary checks that inspected only the source path string. The pattern is decades old in classical security and was re-instantiated in agentic AI by CVE-2025-53109 ("EscapeRoute") in Anthropic's official Filesystem MCP server, analysed in detail in the EscapeRoute writeup.
The attack works because the validation code in the application checks the source path string, while the kernel resolves the path through whatever the symlink points at. An application that says "this path starts with my configured root, so it's safe" approves the operation; the kernel then operates on the link's target, which can be anywhere on the filesystem the application's process has UID-level access to. The two checks diverge whenever a symlink is involved, and the application has no way to make the kernel honour its application-layer boundary unless it explicitly resolves the path before the check.
Why Symlink-Following Is Hard to Defend at Application Layer
Three properties make symlink-following bypass hard to defend in application code. Symlink semantics are OS-defined, not application-defined. The kernel chooses how to resolve symlinks; the application has no override mechanism beyond explicit realpath calls. Symlink chains can be long. A → B → C → D where only D is outside the root may not be visible to a single-step check. TOCTOU races compound the problem. Even if the application calls realpath and validates the result, an attacker who can write to the directory between the check and the operation can swap the symlink to a new target before the operation happens.
Defensive Patterns
The structurally sound defence is to operate at the kernel layer rather than re-implementing path resolution in application code. On Linux, openat2 with RESOLVE_BENEATH and/or RESOLVE_NO_SYMLINKS flags causes the kernel to reject any path resolution that crosses the configured root or follows a symlink — without the application needing to inspect the result. Mount namespaces, chroot, and container-level path constraints achieve similar guarantees by restricting which paths the kernel can resolve at all.
For application code that cannot use kernel-level constraints, the conservative defence is to refuse all symlinks: resolve the requested path, walk every component, and reject if any component is a symlink whose target is outside the configured root. This is more expensive than a naive prefix check and still vulnerable to TOCTOU, but closes the most common exploit primitives.
For deeper guidance on filesystem-MCP-specific defence, see the EscapeRoute case study and the MCP Security Audit service description.
Articles Using This Term
Learn more about Symlink-Following Attack in these articles:
Related Terms
Sandbox Escape (Agentic)
An attack where code or commands intended to run inside a constrained sandbox (container, seccomp profile, restricted directory) reach execution outside the constraint — exfiltrating credentials, modifying host files, or pivoting to privileged subsystems.
Path-Prefix Bypass
A sandbox-escape pattern where a sandbox boundary check uses string-prefix comparison to enforce a directory boundary, allowing paths whose strings start with the root path but whose actual filesystem location does not. The CVE-2025-53110 mechanism.
TOCTOU (Filesystem)
Time-of-check / time-of-use race condition class where a security check and the subsequent filesystem operation are not atomic, allowing an attacker to swap the resolution target between the two steps and bypass the check.
Exec Primitive
Any path inside an AI agent's tool surface that reaches a shell call, subprocess spawn, or interpreted-code execution — including paths the operator did not explicitly model as exec.
Need expert guidance on Symlink-Following Attack?
Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.
Get a Quote