GHSA-5r98-f33j-g8h7

Suggest an improvement
Source
https://github.com/advisories/GHSA-5r98-f33j-g8h7
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2023/08/GHSA-5r98-f33j-g8h7/GHSA-5r98-f33j-g8h7.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-5r98-f33j-g8h7
Aliases
Related
Published
2023-08-01T17:00:55Z
Modified
2023-11-08T04:13:02.473298Z
Severity
  • 7.5 (High) CVSS_V3 - CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H CVSS Calculator
Summary
pnpm incorrectly parses tar archives relative to specification
Details

Summary

It is possible to construct a tarball that, when installed via npm or parsed by the registry is safe, but when installed via pnpm is malicious, due to how pnpm parses tar archives.

Details

The TAR format is an append-only archive format, and as such, the specification for how to update a file is to add a new record to the end with the updated version of the file. This means that it is completely valid for an archive to contain multiple copies of, say, package.json, and the expected behavior when extracting is that all versions other than the last get ignored.

This is further complicated by that during tarball extraction, all package managers are configured to drop the first path component, so collisions can be created simply by using multiple root folders in the archive, even without performing updates.

When pnpm extracts a tar archive via tar-stream, it appears to extract only the first file of a given name and discards all subsequent files with the same name.

PoC

Create a root folder with the following layout: - a/package.json - package/package.json - z/package.json

File contents:

a/package.json

{
    "name": "test-package",
    "version": "0.1.0",
    "description": "This is a bad version of a test package",
    "dependencies": {
        "react": "^15"
    }
}

package/package.json

{
    "name": "test-package",
    "version": "0.1.0",
    "description": "This is a bad version of a test package",
    "dependencies": {
        "react": "^16"
    }
}

z/package.json

{
    "name": "test-package",
    "version": "0.1.0",
    "description": "This is the good version of a test package",
    "dependencies": {
        "react": "^17"
    }
}

Then use the tar binary to produce a tarball (working directory is the root folder): tar -c -z --format ustar -f package.tgz a package z The order of the folders at the end matters; whichever one is last will end up being the package.json that wins when extracted by npm; the one that is first will be the one that wins when extracted by pnpm.

Install the tarball via the file: protocol.

Observe that with npm, the lockfile has react@17, while with pnpm it has react@15.

Impact

This can result in a package that appears safe on the npm registry or when installed via npm being replaced with a compromised or malicious version when installed via pnpm.

Database specific
{
    "nvd_published_at": "2023-08-01T12:15:09Z",
    "cwe_ids": [
        "CWE-284"
    ],
    "severity": "HIGH",
    "github_reviewed": true,
    "github_reviewed_at": "2023-08-01T17:00:55Z"
}
References

Affected packages

npm / pnpm

Package

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/exe

Package

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/linux-arm64

Package

Name
@pnpm/linux-arm64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/linux-arm64

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/linux-x64

Package

Name
@pnpm/linux-x64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/linux-x64

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/linuxstatic-arm64

Package

Name
@pnpm/linuxstatic-arm64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/linuxstatic-arm64

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/macos-arm64

Package

Name
@pnpm/macos-arm64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/macos-arm64

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/macos-x64

Package

Name
@pnpm/macos-x64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/macos-x64

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/win-x64

Package

Name
@pnpm/win-x64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/win-x64

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.33.4

npm / @pnpm/cafs

Package

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
7.0.5

npm / pnpm

Package

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8

npm / @pnpm/exe

Package

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8

npm / @pnpm/linux-arm64

Package

Name
@pnpm/linux-arm64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/linux-arm64

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8

npm / @pnpm/linux-x64

Package

Name
@pnpm/linux-x64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/linux-x64

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8

npm / @pnpm/linuxstatic-arm64

Package

Name
@pnpm/linuxstatic-arm64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/linuxstatic-arm64

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8

npm / @pnpm/macos-arm64

Package

Name
@pnpm/macos-arm64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/macos-arm64

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8

npm / @pnpm/macos-x64

Package

Name
@pnpm/macos-x64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/macos-x64

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8

npm / @pnpm/win-x64

Package

Name
@pnpm/win-x64
View open source insights on deps.dev
Purl
pkg:npm/%40pnpm/win-x64

Affected ranges

Type
SEMVER
Events
Introduced
8.0.0
Fixed
8.6.8