CVE-2021-37712 in node-tar
Summary
by MITRE • 08/31/2021
The npm package "tar" (aka node-tar) before versions 4.4.18, 5.0.10, and 6.1.9 has an arbitrary file creation/overwrite and arbitrary code execution vulnerability. node-tar aims to guarantee that any file whose location would be modified by a symbolic link is not extracted. This is, in part, achieved by ensuring that extracted directories are not symlinks. Additionally, in order to prevent unnecessary stat calls to determine whether a given path is a directory, paths are cached when directories are created. This logic was insufficient when extracting tar files that contained both a directory and a symlink with names containing unicode values that normalized to the same value. Additionally, on Windows systems, long path portions would resolve to the same file system entities as their 8.3 "short path" counterparts. A specially crafted tar archive could thus include a directory with one form of the path, followed by a symbolic link with a different string that resolves to the same file system entity, followed by a file using the first form. By first creating a directory, and then replacing that directory with a symlink that had a different apparent name that resolved to the same entry in the filesystem, it was thus possible to bypass node-tar symlink checks on directories, essentially allowing an untrusted tar file to symlink into an arbitrary location and subsequently extracting arbitrary files into that location, thus allowing arbitrary file creation and overwrite. These issues were addressed in releases 4.4.18, 5.0.10 and 6.1.9. The v3 branch of node-tar has been deprecated and did not receive patches for these issues. If you are still using a v3 release we recommend you update to a more recent version of node-tar. If this is not possible, a workaround is available in the referenced GHSA-qq89-hq3f-393p.
If you want to get best quality of vulnerability data, you may have to visit VulDB.
Analysis
by VulDB Data Team • 02/15/2025
The vulnerability identified as CVE-2021-37712 affects the node-tar npm package, which is widely used for handling tar archive operations in node.js applications. This security flaw represents a critical arbitrary file creation and execution vulnerability that stems from insufficient symlink handling logic within the package's directory extraction mechanisms. The vulnerability specifically impacts versions prior to 4.4.18, 5.0.10, and 6.1.9, creating a significant risk for applications that process untrusted tar archives. The core issue lies in the package's attempt to prevent malicious symlink attacks by ensuring that extracted directories are not symlinks, a protective measure that fails when dealing with unicode normalization scenarios.
The technical root cause of this vulnerability involves the package's path caching mechanism and its handling of unicode character sequences that normalize to identical values. When tar archives contain both directories and symbolic links with names that have different unicode representations but normalize to the same value, the existing protection logic becomes ineffective. This occurs because the system creates a directory first, then replaces it with a symlink that appears to have a different name but resolves to the same filesystem entity. Additionally, Windows systems introduce complexity through their long path and 8.3 filename resolution behavior, where long paths can resolve to the same filesystem entities as their short path counterparts. This creates an exploitable condition where attackers can craft malicious tar files that bypass the symlink checks, effectively allowing arbitrary file creation and overwrites in arbitrary locations.
The operational impact of this vulnerability extends beyond simple file manipulation to encompass full arbitrary code execution capabilities. Attackers can exploit this weakness by creating tar archives that first establish directories, then replace them with symlinks pointing to sensitive system locations, and finally extract malicious files into those locations. This technique essentially allows attackers to bypass the intended security boundaries of the tar extraction process, potentially enabling privilege escalation, data exfiltration, or system compromise. The vulnerability affects any application that relies on node-tar for processing untrusted archive content, making it particularly dangerous in environments where tar files are downloaded from external sources or processed without proper validation.
Security mitigations for CVE-2021-37712 include immediate updates to node-tar versions 4.4.18, 5.0.10, or 6.1.9, which contain the necessary patches to address the symlink handling logic. Organizations using deprecated v3 branch versions should urgently migrate to supported releases, as these older versions will not receive security updates. The vulnerability aligns with CWE-59, which describes improper handling of symbolic links, and maps to ATT&CK technique T1059.007 for execution through scripting languages. Additional protective measures include implementing proper input validation for tar archives, restricting tar file processing to trusted sources, and employing sandboxed environments when handling untrusted archive content. The workaround referenced in GHSA-qq89-hq3f-393p provides temporary relief for organizations unable to immediately update their node-tar installations, though it does not constitute a permanent solution to the underlying security flaw.