The vulnerability in node-tar allows for arbitrary file overwrite and symlink poisoning. The root cause is the insufficient sanitization of the linkpath field for hardlink and symlink entries in a TAR archive. The analysis of the provided patch 340eb285b6d986e91969a1170d7fe9b0face405e confirms this. The patch introduces a new sanitization method, [STRIPABSOLUTEPATH], and applies it to both the path and linkpath properties of an entry within the [CHECKPATH] method. Before this fix, only the path property was being sanitized.
This lack of validation on the linkpath made the following functions vulnerable:
-
Unpack[HARDLINK]: This method would use the unsanitized linkpath to create a hardlink. A malicious actor could provide an absolute path, causing the hardlink to point to a sensitive file outside of the intended extraction directory. Subsequent writes would then modify the targeted system file.
-
Unpack[SYMLINK]: This method would use the unsanitized linkpath as the target for a symbolic link. This could be an absolute path or contain directory traversal characters (../), allowing an attacker to create a symlink pointing anywhere on the filesystem.
The function Unpack[CHECKPATH] is also identified as vulnerable because its pre-patch implementation contained the flaw (the omission of linkpath sanitization) that enabled the exploit. The exploit itself, however, would be triggered within the [HARDLINK] and [SYMLINK] methods, which perform the file system operations.