/

CVE-2026-59948

Severity:

HIGH RISK

(7.0)

Path Traversal (CWE-22) in PHP Composer Package Install

CVE-2026-59948

Deferred

Vulnerability type

Category:

Path Traversal / Arbitrary File Write

CWE:

CWE-22, CWE-787

Impact:

Arbitrary File Write Outside Application Directory

Severity:

HIGH RISK

(7.0)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A path traversal vulnerability in PHP's Composer allows a maliciously crafted package from an untrusted repository to write attacker-controlled files outside the vendor directory and project root during install or update.

If developers rely on untrusted repositories and Composer fails to correctly validate invalid package names, this flaw can be abused to plant arbitrary files on the filesystem, enabling further compromise.

Affected context

This vulnerability occurs in environments where Composer is used to install or update dependencies from repositories other than Packagist.org or Private Packagist.

It particularly affects workflows that incorporate custom or third-party repositories whose package metadata and naming conventions are not tightly controlled.

Under these conditions, a crafted package with an invalid or malicious package name can cause Composer to place files outside the intended vendor directory or even outside the project path, depending on filesystem layout and permissions.

Exploit preconditions

  • Attack surface: Composer dependency installation and update process (CLI usage in developer machines, CI systems, or build servers).
  • Required access: Ability to publish or control a package on an untrusted repository consumed by Composer, or to influence repository configuration in a project.
  • Trigger point: Running composer install or composer update when the malicious package is part of the resolved dependency graph.
  • Why exploitation is possible: Composer does not correctly validate or sanitize certain invalid package names before using them in dependency-resolution and path computation, allowing traversal sequences or unexpected paths to be written to the filesystem.

Why this happens

The underlying issue maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory and is related to unsafe use of path components derived from untrusted package metadata.

Composer uses package names and associated data to construct filesystem paths for dependency installation. When invalid or specially crafted names are not rigorously validated, normalized, and constrained to a known safe base directory, they can influence where files are written.

Abstractly, this represents an insecure pattern where input that should be purely descriptive (package name) is implicitly treated as part of a path, without enforcing a strict canonicalization and containment check against a trusted root.

Potential impact

  • Attacker-controlled files may be written outside the vendor directory.
  • Files can be created or overwritten elsewhere in the project structure.
  • Critical configuration or script files could be modified, enabling code execution.
  • Build or deployment artifacts may be poisoned, leading to downstream compromise.
  • Local developer environments or CI agents can be destabilized or backdoored.

General mitigation guidance

Effective mitigation focuses on constraining where Composer can write files and reducing trust in external package metadata.

Recommended defensive patterns include:

  • Enforcing strict validation and normalization of all path components derived from package metadata, ensuring they cannot escape the intended base directory.
  • Applying canonicalization and "stay inside base directory" checks before writing any files, regardless of repository source.
  • Treating non-Packagist repositories as untrusted by default, with explicit approval and governance over what packages they can serve.
  • Running dependency installation under accounts with minimal filesystem privileges so that, even if a write escapes the project directory, its impact is limited.
  • Using layered controls (such as filesystem permissions, sandboxing, or containerization) to restrict Composer's write capabilities to designated directories.

How teams detect issues like this

Detection commonly involves both code-centric and operational techniques:

  • Static analysis of dependency management code paths to flag any use of untrusted metadata for path construction without containment checks.
  • Security-focused code reviews of Composer-related scripts, custom installers, and repository configuration to identify unvalidated or abnormal package naming assumptions.
  • Policy-based enforcement in CI/CD pipelines requiring dependencies to originate from vetted repositories and scanning for unexpected path traversal sequences in package metadata.
  • Runtime monitoring or audit logging of Composer operations to detect writes outside expected directories (e.g., vendor or project root), which may indicate exploitation attempts.
  • Periodic inspection of build and deployment environments for anomalous files or directories created during dependency installation.

Sources

SourceLink
github.comgithub.com/composer/composer/commit/502c6c4f699802d9cf464728b3e8a95674f919a0
github.comgithub.com/composer/composer/commit/c50b1efd13ebd73f6dca19b31424c5a02bf93cc1
github.comgithub.com/composer/composer/releases/tag/2.10.2
github.comgithub.com/composer/composer/releases/tag/2.2.29
github.comgithub.com/composer/composer/security/advisories/GHSA-499r-g7pc-vmp9

Frequently asked

questions

Indirectly. The exploit occurs when a developer or CI system runs Composer against a malicious package from an untrusted repository. An attacker typically must first get their package accepted or referenced in that environment.

The attacker needs control over a repository or package that the project consumes, or influence over the repository configuration used by Composer. They do not need shell access to the victim machine if the dependency is automatically fetched and installed.

The safest pattern is to strictly validate and sanitize all paths derived from package metadata, ensuring they cannot escape the vendor directory or project root. Combine this with strong repository trust policies so that only vetted sources can supply dependencies.

Establish secure-by-default dependency management practices: restrict repositories to trusted sources, enforce path containment checks for all file operations, run build tooling with least privilege, and integrate automated checks that flag suspicious package names or path manipulations during code review and CI.

Find out what's already
exploitable in your codebase.