CVE-2021-32803: Arbitrary File Creation/Overwrite in tar
Summary
CVE-2021-32803: Arbitrary File Creation/Overwrite via insufficient symlink protection due to directory cache poisoning. Affects tar across 4 version ranges.
>= 3.0.0, < 3.2.3
>= 4.0.0, < 4.4.15
>= 5.0.0, < 5.0.7
>= 6.0.0, < 6.1.2
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tar · Alpine:v3.16
The same CVE-2021-32803 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The 'tar' package is an npm module used for creating and extracting tar archives in Node.js applications. It provides functionality to compress and decompress files and directories. The vulnerability identified as CVE-2021-32803 allows an attacker to create or overwrite arbitrary files on the system by exploiting insufficient symlink protection in the 'node-tar' module, which is used by 'tar'. This vulnerability can lead to arbitrary code execution and poses a high risk to affected systems.
Vulnerability Detail
The vulnerability arises from a flaw in the logic of 'node-tar' when extracting tar files that contain both a directory and a symlink with the same name as the directory. Due to the order of operations, the directory is created and added to the 'node-tar' directory cache before symlink checks are performed. This allows an attacker to first create a directory and then replace it with a symlink, bypassing symlink checks on directories. As a result, an untrusted tar file can symlink into an arbitrary location and extract arbitrary files, leading to arbitrary file creation and overwrite. The impact of this vulnerability includes arbitrary file creation, arbitrary file overwrite, and potential arbitrary code execution.
How To Fix
Latest published version: 7.5.22 as of 22 Oct 2026
npm install tar@7.5.22
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
>= 3.0.0, < 3.2.33.2.3npm install tar@3.2.3 -
>= 4.0.0, < 4.4.154.4.15npm install tar@4.4.15 -
>= 5.0.0, < 5.0.75.0.7npm install tar@5.0.7 -
>= 6.0.0, < 6.1.26.1.2npm install tar@6.1.2
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If upgrading is not immediately possible, users can implement a custom 'filter' method to prevent the extraction of symbolic links. The following code snippet demonstrates how to create a custom filter method:
const tar = require('tar')
tar.x({
file: 'archive.tgz',
filter: (file, entry) => {
if (entry.type === 'SymbolicLink') {
return false
} else {
return true
}
}
})
Conclusion
The vulnerability CVE-2021-32803 in the 'tar' package allows for arbitrary file creation and overwrite, potentially leading to arbitrary code execution. It is crucial to upgrade to the latest patch version (3.2.3, 4.4.15, 5.0.7, or 6.1.2) or implement the provided workaround to mitigate the risk. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tar →
FAQ
The impact includes arbitrary file creation, arbitrary file overwrite, and potential arbitrary code execution.
The vulnerability affects versions 0.0.0 to 3.2.2, 4.0.0 to 4.4.14, 5.0.0 to 5.0.6, and 6.0.0 to 6.1.1 of the 'tar' package.
Upgrade to the latest patch version of the 'tar' package (3.2.3, 4.4.15, 5.0.7, or 6.1.2) to fix this vulnerability.
Yes, users can implement a custom 'filter' method to prevent the extraction of symbolic links. Refer to the 'workaround' section for more details.
You can find more information about this vulnerability in the GitHub Advisory Database: https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2021/08/GHSA-r628-mhmh-qjhw/GHSA-r628-mhmh-qjhw.json
References
Related vulnerabilities
Recent vulnerabilities recorded for tar.