CVE-2021-37712: Arbitrary File Creation/Overwrite via insufficient symlink protection due to directory cache poisoning using symbolic links

Published Aug 31, 2021
·
Updated

Impact Arbitrary File Creation, Arbitrary File Overwrite, Arbitrary Code Execution

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 two directories 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 directories with two forms of the path that resolve to the same file system entity, followed by a symbolic link with a name in the first form, lastly followed by a file using the second form. It led to bypassing 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.

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 below.

Patches

6.1.9 || 5.0.10 || 4.4.18

Workarounds

Users may work around this vulnerability without upgrading by creating a custom filter method which prevents the extraction of symbolic links.

js const tar = require('tar')

tar.x({ file: 'archive.tgz', filter: (file, entry) => { if (entry.type === 'SymbolicLink') { return false } else { return true } } })

Users are encouraged to upgrade to the latest patched versions, rather than attempt to sanitize tar input themselves.

Fix

The problem is addressed in the following ways, when comparing paths in the directory cache and path reservation systems:

1. The String.normalize('NFKD') method is used to first normalize all unicode to its maximally compatible and multi-code-point form. 2. All slashes are normalized to / on Windows systems (on posix systems, \ is a valid filename character, and thus left intact). 3. When a symbolic link is encountered on Windows systems, the entire directory cache is cleared. Collisions related to use of 8.3 short names to replace directories with other (non-symlink) types of entries may make archives fail to extract properly, but will not result in arbitrary file writes.

Other sources

A flaw was found in the npm package "tar" (aka node-tar). Extracting tar files that contain two directories and a symlink with names containing Unicode values that normalize to the same value on Windows systems made it possible to bypass node-tar symlink checks on directories. This allows an untrusted tar file to extract and overwrite files into an arbitrary location. The highest threat from this vulnerability is to integrity and system availability.

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 two directories 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 directories with two forms of the path that resolve to the same file system entity, followed by a symbolic link with a name in the first form, lastly followed by a file using the second form. It led to bypassing 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.

Reference: https://github.com/npm/node-tar/security/advisories/GHSA-qq89-hq3f-393p

Red Hat

Node.js tar module could allow a local attacker to execute arbitrary code on the system, caused by an arbitrary file creation/overwrite vulnerability. By 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, an attacker could use an untrusted tar file to symlink into an arbitrary location and extract arbitrary files into that location to create or overwrite arbitrary files and execute arbitrary code on the system.

IBM

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.

Affected Software

23 affected componentsFixes available
redhat/rh-nodejs14-nodejs<0:14.18.2-1.el7
0:14.18.2-1.el7
redhat/rh-nodejs14-nodejs-nodemon<0:2.0.3-6.el7
0:2.0.3-6.el7
redhat/rh-nodejs12-nodejs<0:12.22.12-2.el7
0:12.22.12-2.el7
debian/node-tar<=4.4.6+ds1-3+deb10u1
4.4.6+ds1-3+deb10u26.0.5+ds1+~cs11.3.9-1+deb11u26.1.13+~cs7.0.5-1
redhat/nodejs-tar<4.4.18
4.4.18
redhat/nodejs-tar<5.0.10
5.0.10
redhat/nodejs-tar<6.1.9
6.1.9
npm/tar>=3.0.0<4.4.18
4.4.18
npm/tar>=6.0.0<6.1.9
6.1.9
npm/tar>=5.0.0<5.0.10
5.0.10
All of the following
Any of the following
npmjs Tar Node.js<=4.4.17
npmjs Tar Node.js>=5.0.0<=5.0.9
npmjs Tar Node.js>=6.0.0<=6.1.8
Microsoft Windows
Debian Debian Linux=10.0
Debian Debian Linux=11.0
Oracle GraalVM=20.3.3
Oracle GraalVM=21.2.0
Siemens Sinec Infrastructure Network Services<1.0.1.1
npmjs Tar Node.js<=4.4.17
npmjs Tar Node.js>=5.0.0<=5.0.9
npmjs Tar Node.js>=6.0.0<=6.1.8
Microsoft Windows

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade redhat/rh-nodejs14-nodejs to a version that resolves this vulnerability.

    Fixed in 0:14.18.2-1.el7
  2. Upgrade

    Upgrade redhat/rh-nodejs14-nodejs-nodemon to a version that resolves this vulnerability.

    Fixed in 0:2.0.3-6.el7
  3. Upgrade

    Upgrade redhat/rh-nodejs12-nodejs to a version that resolves this vulnerability.

    Fixed in 0:12.22.12-2.el7
  4. Upgrade

    Upgrade debian/node-tar to a version that resolves this vulnerability.

    Fixed in 4.4.6+ds1-3+deb10u2Fixed in 6.0.5+ds1+~cs11.3.9-1+deb11u2Fixed in 6.1.13+~cs7.0.5-1
  5. Upgrade

    Upgrade redhat/nodejs-tar to a version that resolves this vulnerability.

    Fixed in 4.4.18
  6. Upgrade

    Upgrade redhat/nodejs-tar to a version that resolves this vulnerability.

    Fixed in 5.0.10
  7. Upgrade

    Upgrade redhat/nodejs-tar to a version that resolves this vulnerability.

    Fixed in 6.1.9
  8. Upgrade

    Upgrade npm/tar to a version that resolves this vulnerability.

    Fixed in 4.4.18
  9. Upgrade

    Upgrade npm/tar to a version that resolves this vulnerability.

    Fixed in 6.1.9
  10. Upgrade

    Upgrade npm/tar to a version that resolves this vulnerability.

    Fixed in 5.0.10
  11. Upgrade

    Upgrade npm/tar (node-tar) to a version that resolves this vulnerability.

    Fixed in 4.4.18
  12. Upgrade

    Upgrade npm/tar (node-tar) to a version that resolves this vulnerability.

    Fixed in 5.0.10
  13. Upgrade

    Upgrade npm/tar (node-tar) to a version that resolves this vulnerability.

    Fixed in 6.1.9
  14. Configuration

    If upgrading is not possible, configure node-tar to prevent extraction of symbolic links by using a custom filter: when entry.type is 'SymbolicLink', return false; otherwise return true.

    node-tar (tar.x options filter) filter (entry.type) = Return false for entry.type === 'SymbolicLink'

Event History

Aug 31, 2021
CVE Published
via MITRE·12:00 AM
Data Sourced
via MITRE·12:00 AM
DescriptionSeverityWeakness
Advisory Published
via GitHub·04:05 PM
Data Sourced
via NVD·05:15 PM
RemedyDescriptionSeverityWeaknessAffected Software
Nov 23, 2021
Data Sourced
via IBM·12:00 AM
DescriptionSeverityAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the vulnerability ID of this flaw in the npm package tar?

The vulnerability ID is CVE-2021-37712.

2

What is the impact of CVE-2021-37712?

The impact includes Arbitrary File Creation, Arbitrary File Overwrite, and Arbitrary Code Execution.

3

Which versions of the npm package tar are affected by CVE-2021-37712?

Versions between 4.4.18 and 6.1.9 of the npm package tar are affected.

4

How can I fix the vulnerability CVE-2021-37712?

To fix the vulnerability, update the npm package tar to version 6.1.9 or higher.

5

Where can I find more information about CVE-2021-37712?

You can find more information about CVE-2021-37712 on the NVD website.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203
CVE-2021-37712 - Arbitrary File Creation/Overwrite via insufficient symlink protection due to directory cache poisoning using symbolic links - SecAlerts