CVE-2026-24765 Overview
CVE-2026-24765 is an insecure deserialization vulnerability affecting PHPUnit, a widely-used testing framework for PHP. The vulnerability exists in the cleanupForCoverage() method, which deserializes code coverage files without proper validation. This flaw potentially allows remote code execution if malicious .coverage files are present prior to the execution of PHPT tests.
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 containing a __wakeup() method into the file system, leading to arbitrary code execution during test runs with code coverage instrumentation enabled.
Critical Impact
Arbitrary code execution through malicious deserialization during PHPUnit test execution with code coverage enabled, potentially compromising CI/CD pipelines and development environments.
Affected Products
- PHPUnit versions prior to 12.5.8
- PHPUnit versions prior to 11.5.50
- PHPUnit versions prior to 10.5.62
- PHPUnit versions prior to 9.6.33
- PHPUnit versions prior to 8.5.52
Discovery Timeline
- 2026-01-27 - CVE CVE-2026-24765 published to NVD
- 2026-01-29 - Last updated in NVD database
Technical Details for CVE-2026-24765
Vulnerability Analysis
This insecure deserialization vulnerability (CWE-502) resides in PHPUnit's code coverage handling for PHPT tests. The cleanupForCoverage() method processes .coverage files using PHP's native unserialize() function without specifying the allowed_classes parameter. This omission allows arbitrary PHP objects to be instantiated during deserialization.
PHP object deserialization is particularly dangerous because certain magic methods—such as __wakeup(), __destruct(), and __toString()—are automatically invoked during or after deserialization. Attackers can craft serialized payloads containing objects with malicious code in these magic methods, creating a "POP chain" (Property Oriented Programming) that executes arbitrary code when the object is deserialized.
The vulnerability requires local file write access to the location where PHPUnit stores or expects code coverage files for PHPT tests. This prerequisite can be satisfied through several attack vectors including CI/CD pipeline attacks, compromised local development environments, and/or malicious or compromised dependencies.
Root Cause
The root cause is the unsafe use of PHP's unserialize() function without the allowed_classes parameter restriction in the cleanupForCoverage() method. When processing .coverage files, the code assumes these files are trusted and contain only expected data structures. However, if an attacker can write a malicious serialized payload to this location before test execution, the deserialization will instantiate arbitrary objects, triggering their magic methods and enabling code execution.
Attack Vector
The attack requires local access to write files to the directory where PHPUnit expects .coverage files for PHPT tests. Attack scenarios include:
CI/CD Pipeline Compromise: An attacker with access to the CI/CD environment can inject malicious .coverage files before test execution, potentially through compromised build artifacts or pipeline configuration manipulation.
Compromised Dependencies: A malicious or compromised package dependency could write serialized payloads to the expected location during installation or build processes.
Local Development Environment: In shared or compromised development environments, an attacker could place malicious files targeting developers running tests with code coverage enabled.
The attacker constructs a serialized PHP object with a __wakeup() or __destruct() method containing malicious code. When PHPUnit processes the .coverage file during test execution with code coverage instrumentation, the object is deserialized and the malicious code executes with the privileges of the test runner.
Detection Methods for CVE-2026-24765
Indicators of Compromise
- Unexpected .coverage files present in PHPUnit test directories prior to test execution
- Anomalous file creation activity in test artifact directories within CI/CD pipelines
- Unusual PHP process behavior or network connections during test execution
- Serialized PHP object signatures in .coverage files containing unexpected class names
Detection Strategies
- Monitor file system activity for unexpected .coverage file creation in PHPUnit test directories before test execution begins
- Implement file integrity monitoring on CI/CD build directories to detect unauthorized file modifications
- Analyze PHPUnit execution logs for error messages related to pre-existing .coverage files (available in patched versions)
- Audit dependencies for known malicious packages that could inject files during build processes
Monitoring Recommendations
- Enable verbose logging for CI/CD pipeline execution to capture file system changes
- Implement runtime monitoring for PHP process spawning and network connections during test execution
- Deploy SentinelOne agents on CI/CD runners and development workstations to detect suspicious deserialization activity
- Configure alerts for unexpected file modifications in test artifact directories
How to Mitigate CVE-2026-24765
Immediate Actions Required
- Upgrade PHPUnit to a patched version (12.5.8, 11.5.50, 10.5.63, 9.6.33, or 8.5.52 depending on your version branch)
- Audit existing .coverage files in your codebase and CI/CD artifacts for unexpected content
- Implement ephemeral CI/CD runners that start from a clean state for each build
- Enable branch protection and mandatory code review to prevent unauthorized pipeline modifications
Patch Information
The PHPUnit maintainer has addressed this vulnerability by treating pre-existing .coverage files for PHPT tests as an error condition rather than silently sanitizing the input. Starting in patched versions, when a .coverage file is detected for a PHPT test prior to execution, PHPUnit will emit a clear error message identifying the anomalous state.
Patched versions are available:
For technical details, see the GitHub Security Advisory and the commit implementing the fix.
Workarounds
- Use ephemeral CI/CD runners that provide a clean environment for each build, eliminating the possibility of persistent malicious files
- Implement strict access controls on directories where PHPUnit stores code coverage files
- Add pre-test hooks to verify no .coverage files exist before test execution begins
- Isolate test artifacts and enforce directory cleanup between test runs
# Pre-test cleanup script to remove any existing .coverage files
#!/bin/bash
# Run before PHPUnit execution to ensure clean state
find ./tests -name "*.coverage" -type f -delete
find ./vendor -name "*.coverage" -type f -delete
echo "Cleaned up pre-existing .coverage files"
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

