This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
6.1.0
->6.1.9
GitHub Vulnerability Alerts
CVE-2021-32804
Impact
Arbitrary File Creation, Arbitrary File Overwrite, Arbitrary Code Execution
node-tar
aims to prevent extraction of absolute file paths by turning absolute paths into relative paths when thepreservePaths
flag is not set totrue
. This is achieved by stripping the absolute path root from any absolute file paths contained in a tar file. For example/home/user/.bashrc
would turn intohome/user/.bashrc
.This logic was insufficient when file paths contained repeated path roots such as
////home/user/.bashrc
.node-tar
would only strip a single path root from such paths. When given an absolute file path with repeating path roots, the resulting path (e.g.///home/user/.bashrc
) would still resolve to an absolute path, thus allowing arbitrary file creation and overwrite.Patches
3.2.2 || 4.4.14 || 5.0.6 || 6.1.1
NOTE: an adjacent issue CVE-2021-32803 affects this release level. Please ensure you update to the latest patch levels that address CVE-2021-32803 as well if this adjacent issue affects your
node-tar
use case.Workarounds
Users may work around this vulnerability without upgrading by creating a custom
onentry
method which sanitizes theentry.path
or afilter
method which removes entries with absolute paths.Users are encouraged to upgrade to the latest patch versions, rather than attempt to sanitize tar input themselves.
CVE-2021-32803
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 unnecessarystat
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 the same name as the directory. This order of operations resulted in the directory being created and added to the
node-tar
directory cache. When a directory is present in the directory cache, subsequent calls to mkdir for that directory are skipped. However, this is also wherenode-tar
checks for symlinks occur.By first creating a directory, and then replacing that directory with a symlink, 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.This issue was addressed in releases 3.2.3, 4.4.15, 5.0.7 and 6.1.2.
Patches
3.2.3 || 4.4.15 || 5.0.7 || 6.1.2
Workarounds
Users may work around this vulnerability without upgrading by creating a custom
filter
method which prevents the extraction of symbolic links.Users are encouraged to upgrade to the latest patch versions, rather than attempt to sanitize tar input themselves.
CVE-2021-37701
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 both a directory and a symlink with the same name as the directory, where the symlink and directory names in the archive entry used backslashes as a path separator on posix systems. The cache checking logic used both
\
and/
characters as path separators, however\
is a valid filename character on posix systems.By first creating a directory, and then replacing that directory with a symlink, 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.
Additionally, a similar confusion could arise on case-insensitive filesystems. If a tar archive contained a directory at
FOO
, followed by a symbolic link namedfoo
, then on case-insensitive file systems, the creation of the symbolic link would remove the directory from the filesystem, but not from the internal directory cache, as it would not be treated as a cache hit. A subsequent file entry within theFOO
directory would then be placed in the target of the symbolic link, thinking that the directory had already been created.These issues were addressed in releases 4.4.16, 5.0.8 and 6.1.7.
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 ofnode-tar
. If this is not possible, a workaround is available below.Patches
4.4.16 || 5.0.8 || 6.1.7
Workarounds
Users may work around this vulnerability without upgrading by creating a custom filter method which prevents the extraction of symbolic links.
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:
/
as a path separator, replacing\
with/
on Windows systems, and leaving\
intact in the path on posix systems. This is performed in depth, at every level of the program where paths are consumed.Caveat
Note that this means that the
entry
objects exposed in various parts of tar's API will now always use/
as a path separator, even on Windows systems. This is not expected to cause problems, as/
is a valid path separator on Windows systems, but may result in issues ifentry.path
is compared against a path string coming from some other API such asfs.realpath()
orpath.resolve()
.Users are encouraged to always normalize paths using a well-tested method such as
path.resolve()
before comparing paths to one another.CVE-2021-37712
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 ofnode-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.
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:
String.normalize('NFKD')
method is used to first normalize all unicode to its maximally compatible and multi-code-point form./
on Windows systems (on posix systems,\
is a valid filename character, and thus left intact).CVE-2021-37713
Impact
Arbitrary File Creation, Arbitrary File Overwrite, Arbitrary Code Execution
node-tar aims to guarantee that any file whose location would be outside of the extraction target directory is not extracted. This is, in part, accomplished by sanitizing absolute paths of entries within the archive, skipping archive entries that contain
..
path portions, and resolving the sanitized paths against the extraction target directory.This logic was insufficient on Windows systems when extracting tar files that contained a path that was not an absolute path, but specified a drive letter different from the extraction target, such as
C:some\path
. If the drive letter does not match the extraction target, for exampleD:\extraction\dir
, then the result ofpath.resolve(extractionDirectory, entryPath)
would resolve against the current working directory on theC:
drive, rather than the extraction target directory.Additionally, a
..
portion of the path could occur immediately after the drive letter, such asC:../foo
, and was not properly sanitized by the logic that checked for..
within the normalized and split portions of the path.This only affects users of
node-tar
on Windows systems.Patches
4.4.18 || 5.0.10 || 6.1.9
Workarounds
There is no reasonable way to work around this issue without performing the same path normalization procedures that node-tar now does.
Users are encouraged to upgrade to the latest patched versions of node-tar, rather than attempt to sanitize paths themselves.
Fix
The fixed versions strip path roots from all paths prior to being resolved against the extraction target folder, even if such paths are not "absolute".
Additionally, a path starting with a drive letter and then two dots, like
c:../
, would bypass the check for..
path portions. This is checked properly in the patched versions.Finally, a defense in depth check is added, such that if the
entry.absolute
is outside of the extraction taret, and we are not in preservePaths:true mode, a warning is raised on that entry, and it is skipped. Currently, it is believed that this check is redundant, but it did catch some oversights in development.Configuration
📅 Schedule: "" (UTC).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by WhiteSource Renovate. View repository job log here.