CVE-2017-9841: Phpunit/phpunit Code Injection Vulnerability

CRITICAL
Advisory Identifier: GHSA-r7c9-c69m-rph8
CVSS 9.8
CWE-94
Published
Advisory Summary

CVE-2017-9841 is a CRITICAL (CVSS 9.8) code injection vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Phpunit/phpunit libraries in the Packagist ecosystem. The issue involves code injection in phpunit. Remediation is available by upgrading affected packages to version 4.8.28, 5.6.3.

CVE-2017-9841 at a Glance

CVE Identifier CVE-2017-9841
GHSA Identifier GHSA-r7c9-c69m-rph8
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Phpunit/phpunit
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/E:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2017-9841

To remediate this vulnerability, upgrade all affected Phpunit/phpunit dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

phpunit/phpunit fixed: 4.8.28
Upgrade phpunit/phpunit to 4.8.28
phpunit/phpunit fixed: 5.6.3
Upgrade phpunit/phpunit to 5.6.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for phpunit/phpunit

How to Check if You Are Affected

To determine whether your application is affected by CVE-2017-9841, inspect your project dependencies for Phpunit/phpunit:

inspect dependencies for phpunit/phpunit

Analyze the terminal output to locate any version of Phpunit/phpunit in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.8.28), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Phpunit/phpunit, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

Util/PHP/eval-stdin.php in PHPUnit starting with 4.8.19 and before 4.8.28, as well as 5.x before 5.6.3, allows remote attackers to execute arbitrary PHP code via HTTP POST data beginning with a `<?php ` substring, as demonstrated by an attack on a site with an exposed /vendor folder, i.e., external access to the /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php URI.

CVE-2017-9841 Affected Phpunit/phpunit Versions

2 component(s)
Fixed Versions:
4.8.285.6.3
Product / Package Ecosystem Affected Versions Fixed Version
phpunit/phpunit
Packagist
≥ 4.8.19
< 4.8.28
4.8.28
phpunit/phpunit
Packagist
≥ 5.0.10
< 5.6.3
5.6.3

References

Frequently Asked Questions

What is CVE-2017-9841?
CVE-2017-9841 is a security vulnerability in Phpunit/phpunit involving Code Injection in PHPUnit under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Phpunit/phpunit versions are affected?
Affected versions include releases prior to 4.8.28, 5.6.3 across affected packages: phpunit/phpunit.
What version fixes CVE-2017-9841?
Upgrading to 4.8.28, 5.6.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is phpunit/phpunit affected?
Yes, phpunit/phpunit is affected in releases prior to 4.8.28, 5.6.3. Upgrade your dependency to 4.8.28, 5.6.3 or later.
What is the CVSS score of CVE-2017-9841?
CVE-2017-9841 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/E:H.
What CWE is associated with CVE-2017-9841?
CVE-2017-9841 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check Packagist dependencies for CVE-2017-9841?
Run the dependency tree command: 'inspect dependencies for phpunit/phpunit'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-r7c9-c69m-rph8",
  "modified" : "2025-10-22T17:32:06Z",
  "published" : "2022-03-26T00:19:30Z",
  "aliases" : [ "CVE-2017-9841" ],
  "summary" : "Code Injection in PHPUnit",
  "details" : "Util/PHP/eval-stdin.php in PHPUnit starting with 4.8.19 and before 4.8.28, as well as 5.x before 5.6.3, allows remote attackers to execute arbitrary PHP code via HTTP POST data beginning with a `<?php ` substring, as demonstrated by an attack on a site with an exposed /vendor folder, i.e., external access to the /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php URI.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/E:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phpunit/phpunit"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.8.19"
      }, {
        "fixed" : "4.8.28"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phpunit/phpunit"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.10"
      }, {
        "fixed" : "5.6.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2017-9841"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sebastianbergmann/phpunit/pull/1955"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sebastianbergmann/phpunit/pull/1956"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sebastianbergmann/phpunit/commit/284a69fb88a2d0845d23f42974a583d8f59bf5a5"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sebastianbergmann/phpunit/commit/3aaddb1c5bd9b9b8d070b4cf120e71c36fd08412"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/phpunit/phpunit/CVE-2017-9841.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sebastianbergmann/phpunit"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/201711-15"
  }, {
    "type" : "WEB",
    "url" : "https://www.cisa.gov/known-exploited-vulnerabilities-catalog?field_cve=CVE-2017-9841"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuoct2021.html"
  }, {
    "type" : "WEB",
    "url" : "http://web.archive.org/web/20170701212357/http://phpunit.vulnbusters.com"
  }, {
    "type" : "WEB",
    "url" : "http://www.securityfocus.com/bid/101798"
  }, {
    "type" : "WEB",
    "url" : "http://www.securitytracker.com/id/1039812"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-03-26T00:19:30Z",
    "nvd_published_at" : "2017-06-27T17:29:00Z"
  }
}