The vulnerability is a Time-of-check Time-of-use (TOCTOU) race condition within the ZIP extraction process of the 'openclaw' package. The root cause lies in the separation of path validation and file system write operations. The extractZip function would first validate the destination path for a file entry from the archive. Subsequently, it would call writeZipFileEntry, which in turn called openZipOutputFile to open and truncate the file at that path. An attacker could win a race by replacing a directory component in the validated path with a symbolic link pointing outside the intended extraction root. When openZipOutputFile was then called, it would follow the symlink and open/truncate a file outside the destination directory.
The patch addresses this by fundamentally changing how files are opened and written. The new openZipOutputFile implementation no longer trusts the path after the initial check. Instead, it opens a file handle and then uses mechanisms like fs.realpath on the file descriptor (e.g., via /proc/self/fd/ on Linux) to verify the true, final path of the opened file. It ensures this real path is within the destination directory and that the opened entity is a regular file, not a symlink. Only after these rigorous, post-open checks are passed is the file content written. This binds the security check to the identity of the file handle itself, eliminating the race condition window.