PHPUnit Vulnerable to Unsafe Deserialization in PHPT Code Coverage Handling
Description
PHPUnit is a testing framework for PHP. A vulnerability has been discovered in versions prior to 12.5.8, 11.5.50, 10.5.62, 9.6.33, and 8.5.52 involving unsafe deserialization of code coverage data in PHPT test execution. The vulnerability exists in the cleanupForCoverage() method, which deserializes code coverage files without validation, potentially allowing remote code execution if malicious .coverage files are present prior to the execution of the PHPT test. The vulnerability occurs when a .coverage file, which should not exist before test execution, is deserialized without the allowed_classes parameter restriction. An attacker with local file write access can place a malicious serialized object with a __wakeup() method into the file system, leading to arbitrary code execution during test runs with code coverage instrumentation enabled. This vulnerability requires local file write access to the location where PHPUnit stores or expects code coverage files for PHPT tests. This can occur through CI/CD pipeline attacks, the local development environment, and/or compromised dependencies. Rather than just silently sanitizing the input via ['allowed_classes' => false], the maintainer has chosen to make the anomalous state explicit by treating pre-existing .coverage files for PHPT tests as an error condition. Starting in versions in versions 12.5.8, 11.5.50, 10.5.62, 9.6.33, when a .coverage file is detected for a PHPT test prior to execution, PHPUnit will emit a clear error message identifying the anomalous state. Organizations can reduce the effective risk of this vulnerability through proper CI/CD configuration, including ephemeral runners, code review enforcement, branch protection, artifact isolation, and access control.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
phpunit/phpunitPackagist | < 8.5.52 | 8.5.52 |
phpunit/phpunitPackagist | >= 9.0.0, < 9.6.33 | 9.6.33 |
phpunit/phpunitPackagist | >= 10.0.0, < 10.5.62 | 10.5.62 |
phpunit/phpunitPackagist | >= 11.0.0, < 11.5.50 | 11.5.50 |
phpunit/phpunitPackagist | >= 12.0.0, < 12.5.8 | 12.5.8 |
Affected products
1- Range: 10.0.0, 10.1.0, 10.4.0, …
Patches
2613d142f5a84Merge branch '11.5' into 12.5
1 file changed · +8 −1
src/Runner/Phpt/TestCase.php+8 −1 modified@@ -471,7 +471,14 @@ private function cleanupForCoverage(): RawCodeCoverageData } if ($buffer !== false) { - $coverage = @unserialize($buffer, ['allowed_classes' => false]); + $coverage = @unserialize( + $buffer, + [ + 'allowed_classes' => [ + RawCodeCoverageData::class, + ], + ], + ); if ($coverage === false) { /**
3141742e0062Do not run PHPT test when its temporary file for code coverage information exists
5 files changed · +49 −1
ChangeLog-8.5.md+7 −0 modified@@ -2,6 +2,12 @@ All notable changes of the PHPUnit 8.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [8.5.52] - 2026-MM-DD + +### Changed + +* To prevent Poisoned Pipeline Execution (PPE) attacks using prepared `.coverage` files in pull requests, a PHPT test will no longer be run if the temporary file for writing code coverage information already exists before the test runs + ## [8.5.51] - 2026-01-24 ### Changed @@ -374,6 +380,7 @@ All notable changes of the PHPUnit 8.5 release series are documented in this fil * [#3967](https://github.com/sebastianbergmann/phpunit/issues/3967): Cannot double interface that extends interface that extends `\Throwable` * [#3968](https://github.com/sebastianbergmann/phpunit/pull/3968): Test class run in a separate PHP process are passing when `exit` called inside +[8.5.52]: https://github.com/sebastianbergmann/phpunit/compare/8.5.51...8.5 [8.5.51]: https://github.com/sebastianbergmann/phpunit/compare/8.5.50...8.5.51 [8.5.50]: https://github.com/sebastianbergmann/phpunit/compare/8.5.49...8.5.50 [8.5.49]: https://github.com/sebastianbergmann/phpunit/compare/8.5.48...8.5.49
src/Runner/PhptTestCase.php+22 −1 modified@@ -93,7 +93,10 @@ public function __construct(string $filename, ?AbstractPhpProcess $phpUtil = nul $this->ensureFileExists($filename); $this->filename = $filename; - $this->phpUtil = $phpUtil ?: AbstractPhpProcess::factory(); + + $this->ensureCoverageFileDoesNotExist(); + + $this->phpUtil = $phpUtil ?: AbstractPhpProcess::factory(); } /** @@ -829,4 +832,22 @@ private function ensureFileExists(string $filename): void ); } } + + /** + * @throws Exception + */ + private function ensureCoverageFileDoesNotExist(): void + { + $files = $this->getCoverageFiles(); + + if (file_exists($files['coverage'])) { + throw new Exception( + sprintf( + 'File %s exists, PHPT test %s will not be executed', + $files['coverage'], + $this->filename + ) + ); + } + } }
tests/end-to-end/_files/phpt-coverage-file-exists/test.coverage+0 −0 addedtests/end-to-end/_files/phpt-coverage-file-exists/test.phpt+7 −0 added@@ -0,0 +1,7 @@ +--TEST-- +test +--FILE-- +<?php declare(strict_types=1); +print 'test'; +--EXPECT-- +test
tests/end-to-end/phpt/phpt-coverage-file-exists.phpt+13 −0 added@@ -0,0 +1,13 @@ +--TEST-- +Error when code coverage file exists +--FILE-- +<?php declare(strict_types=1); +$_SERVER['argv'][] = '--do-not-cache-result'; +$_SERVER['argv'][] = '--no-configuration'; +$_SERVER['argv'][] = \realpath(__DIR__ . '/../_files/phpt-coverage-file-exists/test.phpt'); + +require_once __DIR__ . '/../../bootstrap.php'; + +PHPUnit\TextUI\Command::main(); +--EXPECTF-- +Fatal error: Uncaught PHPUnit\Runner\Exception: File %stest.coverage exists, PHPT test %stest.phpt will not be executed%A
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
13- github.com/advisories/GHSA-vvj3-c3rp-c85pghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2026-24765ghsaADVISORY
- github.com/FriendsOfPHP/security-advisories/blob/master/phpunit/phpunit/CVE-2026-24765.yamlghsaWEB
- github.com/sebastianbergmann/phpunit/commit/3141742e00620e2968d3d2e732d320de76685fdaghsax_refsource_MISCWEB
- github.com/sebastianbergmann/phpunit/commit/613d142f5a8471ca71623ce5ca2795f79248329eghsaWEB
- github.com/sebastianbergmann/phpunit/releases/tag/10.5.63ghsax_refsource_MISCWEB
- github.com/sebastianbergmann/phpunit/releases/tag/11.5.50ghsax_refsource_MISCWEB
- github.com/sebastianbergmann/phpunit/releases/tag/12.5.8ghsax_refsource_MISCWEB
- github.com/sebastianbergmann/phpunit/releases/tag/8.5.52ghsax_refsource_MISCWEB
- github.com/sebastianbergmann/phpunit/releases/tag/9.6.33ghsax_refsource_MISCWEB
- github.com/sebastianbergmann/phpunit/security/advisories/GHSA-vvj3-c3rp-c85pghsax_refsource_CONFIRMWEB
- lists.debian.org/debian-lts-announce/2026/02/msg00009.htmlghsaWEB
- owasp.org/www-project-top-10-ci-cd-security-risks/CICD-SEC-04-Poisoned-Pipeline-ExecutionghsaWEB
News mentions
0No linked articles in our index yet.