Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update dependency tar [security] #1875

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Jul 19, 2022

Mend Renovate

This PR contains the following updates:

Package Change
tar 2.2.2 -> 4.4.18
tar 4.4.13 -> 4.4.15

GitHub Vulnerability Alerts

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 named foo, 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 the FOO 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 of node-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.

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:

  1. All paths are normalized to use / 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.
  2. Directory cache pruning is performed case-insensitively. This may result in undue cache misses on case-sensitive file systems, but the performance impact is negligible.

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 if entry.path is compared against a path string coming from some other API such as fs.realpath() or path.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 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.

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.

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 example D:\extraction\dir, then the result of path.resolve(extractionDirectory, entryPath) would resolve against the current working directory on the C: drive, rather than the extraction target directory.

Additionally, a .. portion of the path could occur immediately after the drive letter, such as C:../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.

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 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. 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 where node-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.

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 patch versions, rather than attempt to sanitize tar input themselves.

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 the preservePaths flag is not set to true. 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 into home/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 the entry.path or a filter method which removes entries with absolute paths.

const path = require('path')
const tar = require('tar')

tar.x({
  file: 'archive.tgz',
  // either add this function...
  onentry: (entry) => {
    if (path.isAbsolute(entry.path)) {
      entry.path = sanitizeAbsolutePathSomehow(entry.path)
      entry.absolute = path.resolve(entry.path)
    }
  },

  // or this one
  filter: (file, entry) => {
    if (path.isAbsolute(entry.path)) {
      return false
    } else {
      return true
    }
  }
})

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


Configuration

📅 Schedule: Branch creation - "" in timezone America/Vancouver, Automerge - At any time (no schedule defined).

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

👻 Immortal: This PR will be recreated if closed unmerged. Get config help if that's undesired.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot added the security label Jul 19, 2022
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from caecd33 to cb4f047 Compare July 19, 2022 19:59
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from cb4f047 to ce9c574 Compare July 19, 2022 22:12
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from ce9c574 to 6d38dee Compare July 21, 2022 02:21
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 6d38dee to ee0d6f5 Compare July 21, 2022 07:24
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from ee0d6f5 to 8f724ab Compare July 21, 2022 14:56
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 8f724ab to 8a3047d Compare August 2, 2022 08:09
@github-actions
Copy link

github-actions bot commented Aug 2, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 8a3047d to 86d03a7 Compare August 3, 2022 01:09
@github-actions
Copy link

github-actions bot commented Aug 3, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 86d03a7 to f8d513c Compare August 3, 2022 05:23
@github-actions
Copy link

github-actions bot commented Aug 3, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from f8d513c to fc08a55 Compare August 4, 2022 03:09
@github-actions
Copy link

github-actions bot commented Aug 4, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from fc08a55 to 6e4862e Compare August 4, 2022 11:04
@github-actions
Copy link

github-actions bot commented Aug 4, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 6e4862e to f5ee161 Compare August 9, 2022 02:50
@github-actions
Copy link

github-actions bot commented Aug 9, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from f5ee161 to 13609c0 Compare August 10, 2022 00:19
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 13609c0 to 9ea8b71 Compare August 10, 2022 14:28
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 9ea8b71 to 8712c5a Compare August 10, 2022 23:08
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 6ffd36e to 1c3b74a Compare October 14, 2022 23:09
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 1c3b74a to 54ed4f3 Compare October 15, 2022 23:10
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 54ed4f3 to bc7bced Compare October 17, 2022 23:05
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from bc7bced to 1299d72 Compare October 18, 2022 07:50
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 1299d72 to 9df6de2 Compare October 19, 2022 06:14
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 9df6de2 to 2d9b566 Compare October 21, 2022 08:30
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 2d9b566 to 83695c3 Compare October 24, 2022 20:56
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 83695c3 to 3b7c57b Compare October 26, 2022 01:25
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 3b7c57b to bd1a426 Compare October 27, 2022 15:51
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from bd1a426 to bceabb9 Compare October 30, 2022 03:06
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from bceabb9 to 1224a12 Compare November 1, 2022 07:06
@github-actions
Copy link

github-actions bot commented Nov 1, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from 1224a12 to d7b9c36 Compare November 4, 2022 06:42
@github-actions
Copy link

github-actions bot commented Nov 4, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from d7b9c36 to f161df6 Compare November 7, 2022 07:35
@github-actions
Copy link

github-actions bot commented Nov 7, 2022

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

@renovate renovate bot force-pushed the renovate/npm-tar-vulnerability branch from f161df6 to e6ae065 Compare November 20, 2022 11:16
@github-actions
Copy link

Links:

Packages pending updates:


If this is not what you expected, ensure that your commit messages follow the TDS commit types guide on this page: https://tds.telus.com/contributing/developer-guide.html and try again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants