The vulnerability is a classic path traversal issue located in the storage layer of the esm.sh server. The legacyRouter component constructs a storage key from the URL path without proper sanitization. This malicious key, containing ../ sequences, is then passed to the fsStorage methods.
The core of the vulnerability lies within the fsStorage methods in internal/storage/storage_fs.go. Functions like Put, Get, Stat, Delete, List, and DeleteAll were using filepath.Join to concatenate the storage root directory with the user-provided key. filepath.Join does not inherently prevent path traversal, so a crafted key could navigate outside the intended storage directory.
The most critical of these is fsStorage.Put, which allowed an attacker to write a file to an arbitrary location on the server's filesystem, leading to potential remote code execution by overwriting system files or application scripts.
The patch addresses this by introducing a new function, joinRootSafe, which validates the key using filepath.IsLocal before joining it with the root path. This ensures that the key does not contain any path traversal elements, effectively mitigating the vulnerability across all storage operations.