/

CVE-2026-24765

Severity:

HIGH RISK

(7.8)

Unsafe Deserialization in PHPUnit PHPT Test Execution

CVE-2026-24765

Analyzed

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution in Local/CI Environments

Severity:

HIGH RISK

(7.8)

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

PHPUnit before 12.5.8, 11.5.50, 10.5.62, 9.6.33, and 8.5.52 unsafely deserializes .coverage files during PHPT test execution without restricting allowed classes.

An attacker with local file write access to the coverage directory can plant a malicious serialized object that triggers a __wakeup() method, potentially leading to arbitrary code execution when code coverage is enabled.

Affected context

This vulnerability affects projects that use PHPUnit's PHPT test runner with code coverage instrumentation enabled.

It is relevant wherever PHPUnit is executed in automated or semi-automated contexts, such as developer workstations, CI/CD runners, or build servers that:

  • Generate code coverage data for PHPT tests, and
  • Store .coverage files in a predictable location on disk.

The risk is heightened in shared or automated environments where multiple processes or actors can write to the PHPUnit working directories used for coverage artifacts.

Exploit preconditions

  • Attack surface: Local filesystem where PHPUnit reads and writes code coverage .coverage files for PHPT tests.
  • Required access: Ability to write arbitrary files into the directory where PHPUnit expects .coverage files (e.g., via compromised CI job, poisoned dependency, or local account on the build machine).
  • Trigger point: Execution of PHPT tests with code coverage enabled, which causes the cleanupForCoverage() method to deserialize pre-existing .coverage files.
  • Why exploitation is possible: The cleanupForCoverage() method deserializes coverage data without validation or allowed_classes restrictions, allowing user-controlled object graphs with attacker-controlled __wakeup() code to be instantiated during test cleanup.

Why this happens

The core issue is an unsafe deserialization pattern inside PHPUnit's handling of coverage artifacts for PHPT tests.

The cleanupForCoverage() method assumes that .coverage files do not exist prior to a given test run and therefore treats their contents as trusted.

It directly deserializes these files without:

  • Verifying that they were produced by the current test execution, or
  • Restricting the set of allowed classes during deserialization.

This maps to CWE-502: Deserialization of Untrusted Data, where serialized input from a potentially untrusted source is converted back into objects that can execute code via magic methods like __wakeup() or destructors.

The logical trust in "internal" coverage files becomes invalid in environments where local write access can be obtained by attackers, such as compromised CI pipelines or shared build systems.

Potential impact

  • Execution of arbitrary PHP code in the context of the user or process running PHPUnit (e.g., CI runner, developer account).
  • Compromise of CI/CD infrastructure, including theft of secrets, tokens, or build artifacts.
  • Tampering with test results or build outputs, enabling supply-chain attacks on downstream deployments.
  • Lateral movement from a build environment into other internal systems, depending on available network and credential access.
  • Persistent backdoors on development or build servers via malicious test fixtures or dependencies.

General mitigation guidance

Mitigation should focus on both correct handling of serialized data and hardening of the environments that run PHPUnit:

  • Avoid unsafe deserialization patterns
  • Treat all serialized data, including internal coverage artifacts, as untrusted unless freshly produced in the same execution flow.
  • When deserialization is unavoidable, use safeguards such as allowed_classes restrictions or explicit type-checking on deserialized values.
  • Fail fast on unexpected or pre-existing artifact files instead of attempting to recover from anomalous states.
  • Enforce strict artifact lifecycle rules
  • Ensure test coverage directories are created fresh per run and not shared across branches, users, or pipelines.
  • Treat pre-existing .coverage files as an error condition and stop execution, rather than silently consuming them.
  • Use per-run, per-branch, or per-job isolation for temporary test artifacts.
  • Harden CI/CD and development environments
  • Use ephemeral CI runners or clean containers/VMs so that state is not shared between runs.
  • Restrict write access to directories where PHPUnit reads coverage data; only the test process should be able to write there.
  • Enforce code review, branch protection, and strict control over who can modify test or build-related scripts and configuration.
  • Isolate build artifacts and secrets, so that compromise of one project or pipeline does not automatically expose others.
  • Reduce privilege and blast radius
  • Run PHPUnit and CI jobs with least-privilege accounts that have minimal filesystem and network permissions.
  • Segment build networks so that a compromised test runner cannot directly reach sensitive internal services.

How teams detect issues like this

Detection can target both code patterns and operational anomalies:

  • Static analysis and code review
  • Flag use of unserialize() or equivalent deserialization calls that operate on data from disk or external sources without allowed_classes restrictions.
  • Review code paths that assume temporary or "internal" files are always trustworthy, especially for test coverage, caching, or sessions.
  • Require explicit validation or anomaly handling when deserializing artifacts that may be left over from previous runs.
  • Configuration and policy checks
  • Implement CI policies that ensure temporary directories (including coverage output) are unique per run and cleaned afterward.
  • Enforce checks that prevent build/test processes from reading pre-existing coverage files without verification.
  • Use infrastructure as code and policy-as-code tools to assert that CI runners are ephemeral and isolated.
  • Runtime monitoring and logging
  • Log and alert when PHPUnit or other tooling encounters unexpected pre-existing coverage artifacts or serialized data.
  • Monitor CI runners for unexpected file creations inside test artifact directories, especially by processes other than the primary build job.
  • Track execution of PHPUnit with coverage enabled in contexts where it should not run (e.g., production servers).
  • Automated security tooling
  • Integrate SAST tools configured to identify unsafe deserialization patterns in test infrastructure and build scripts.
  • Use supply-chain security scanners to detect malicious or unusual changes in test-related dependencies and build steps.

Sources

SourceLink
github.comgithub.com/sebastianbergmann/phpunit/commit/3141742e00620e2968d3d2e732d320de76685fda
github.comgithub.com/sebastianbergmann/phpunit/releases/tag/10.5.63
github.comgithub.com/sebastianbergmann/phpunit/releases/tag/11.5.50
github.comgithub.com/sebastianbergmann/phpunit/releases/tag/12.5.8
github.comgithub.com/sebastianbergmann/phpunit/releases/tag/8.5.52
github.comgithub.com/sebastianbergmann/phpunit/releases/tag/9.6.33
github.comgithub.com/sebastianbergmann/phpunit/security/advisories/GHSA-vvj3-c3rp-c85p
lists.debian.orglists.debian.org/debian-lts-announce/2026/02/msg00009.html

Frequently asked

questions

Not directly. Exploitation requires the ability to write malicious .coverage files to the filesystem location PHPUnit uses for PHPT coverage data. However, this access can often be achieved indirectly through compromised CI jobs, poisoned dependencies, or insider access to build infrastructure, which may originate from remote attacks.

The attacker needs local file write access to the directory where PHPUnit expects or stores .coverage files for PHPT tests. This might be obtained via a compromised CI runner, misconfigured permissions on shared build directories, malicious code in a dependency, or a local user account with access to the development or build machine.

The safest pattern is to never deserialize data from disk or external sources without treating it as untrusted. Use strong invariants: ensure artifacts are created fresh for each run, treat pre-existing files as errors, and, where deserialization is necessary, explicitly restrict allowed classes and validate the data structure before use. In many cases, replacing serialization-based formats with safer, structured formats (e.g., JSON with schema validation) is preferable.

Organizations can reduce risk by combining secure coding and operational practices: ban unsafe deserialization without explicit validation, incorporate SAST rules for serialization APIs, run tests in ephemeral and isolated CI environments, enforce branch protection and code review for build/test scripts, and tightly restrict filesystem write access to directories used for test artifacts like coverage data.

Find out what's already
exploitable in your codebase.