GHSA-4v5g-8pq2-32m2: Typo3/phar stream wrapper Remote Code Execution Vulnerability

MODERATE
CWE-502
Published
Advisory Summary

GHSA-4v5g-8pq2-32m2 is a MODERATE remote code execution vulnerability (CWE-502: Deserialization of Untrusted Data) affecting Typo3/phar stream wrapper libraries in the Packagist ecosystem. The issue involves by-passing protection of pharstreamwrapper interceptor. Remediation is available by upgrading affected packages to version 2.0.1, 3.0.1.

GHSA-4v5g-8pq2-32m2 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-4v5g-8pq2-32m2
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product Typo3/phar stream wrapper
Package Ecosystem Packagist
Published Date
Last Updated

How to Fix GHSA-4v5g-8pq2-32m2

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

typo3/phar-stream-wrapper fixed: 2.0.1
Upgrade typo3/phar-stream-wrapper to 2.0.1
typo3/phar-stream-wrapper fixed: 3.0.1
Upgrade typo3/phar-stream-wrapper to 3.0.1
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 typo3/phar-stream-wrapper

How to Check if You Are Affected

To determine whether your application is affected by GHSA-4v5g-8pq2-32m2, inspect your project dependencies for Typo3/phar stream wrapper:

inspect dependencies for typo3/phar-stream-wrapper

Analyze the terminal output to locate any version of Typo3/phar stream wrapper in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.1), 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-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In Typo3/phar stream wrapper, 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

Insecure deserialization is a vulnerability which occurs when untrusted data is used to abuse the logic of an application. In July 2018, the vulnerability of insecure deserialization when executing Phar archives was addressed by removing the known attack vector in the TYPO3 core. For more details read the corresponding TYPO3 advisory. In addition, a new interceptor was introduced to protect possible (but unknown) vulnerabilities in 3rd party components like TYPO3 extensions. Basically, the PharStreamWrapper intercepts direct invocations of Phar archives and allows or denies further processing based on individual rules. Recently, the PharStreamWrapper was extracted from the TYPO3 core and released as standalone package under the MIT license. It is now available for any PHP driven project. The stream wrapper overwrites the existing Phar handling of PHP, applies its own assertions and then restores the native PHP Phar handling for the corresponding commands (e.g. file_exists, include, fopen) to continue processing. After that, the native PHP Phar handling gets disabled and is overwritten by the logic of the PharStreamWrapper again. This is the only way to control invocations of Phar archives as PHP only allows a single handler for each corresponding stream. We were informed that exception and error handlers in custom applications (e.g. TYPO3 extensions) sometimes didn't return to the original operating sequence of the PharStreamWrapper. A possible consequence was that the unprotected native PHP Phar handling remained active and therefore became vulnerable for the basic issue of insecure deserialization again. Examples Take a look at the following examples showing how the handling is by-passed in custom application code. Scenario A: Exception thrown from code organized in a Phar archive ``` try { include('phar://path-to-archive/good-archive.phar'); } catch (\Throwable $throwable) { // not doing much here, continue execution } // the insecure value can be anything that is or was user-submitted // and cannot be trusted in terms of security, $_GET is just used as example $insecureValue = $_GET['path']; // the value might be 'phar://path-to-archive/malicious-archive.phar' file_exists($insecureValue); ``` Scenario B: Errors converted to exceptions and thrown when interacting with archive contents ``` // set error handler in order to convert errors to exceptions set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); }); // interacting with Phar archive try { $resource = opendir('phar://path-to-archive/good-archive.phar/non-existing-path/'); closedir($resource); } catch (\Throwable $throwable) { // not doing much here, continue execution } // the insecure value can be anything that is or was user-submitted // and cannot be trusted in terms of security, $_GET is just used as example $insecureValue = $_GET['path']; // the value might be 'phar://path-to-archive/malicious-archive.phar' file_exists($insecureValue); ```

GHSA-4v5g-8pq2-32m2 Affected Typo3/phar stream wrapper Versions

2 component(s)
Fixed Versions:
2.0.13.0.1
Product / Package Ecosystem Affected Versions Fixed Version
typo3/phar-stream-wrapper
Packagist
≥ 1.0.0
< 2.0.1
2.0.1
typo3/phar-stream-wrapper
Packagist
≥ 3.0.0
< 3.0.1
3.0.1

References

Frequently Asked Questions

What is GHSA-4v5g-8pq2-32m2?
GHSA-4v5g-8pq2-32m2 is a security vulnerability in Typo3/phar stream wrapper involving By-passing Protection of PharStreamWrapper Interceptor under CWE-502: Deserialization of Untrusted Data.
Which Typo3/phar stream wrapper versions are affected?
Affected versions include releases prior to 2.0.1, 3.0.1 across affected packages: typo3/phar-stream-wrapper.
What version fixes GHSA-4v5g-8pq2-32m2?
Upgrading to 2.0.1, 3.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is typo3/phar-stream-wrapper affected?
Yes, typo3/phar-stream-wrapper is affected in releases prior to 2.0.1, 3.0.1. Upgrade your dependency to 2.0.1, 3.0.1 or later.
What CWE is associated with GHSA-4v5g-8pq2-32m2?
GHSA-4v5g-8pq2-32m2 is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check Packagist dependencies for GHSA-4v5g-8pq2-32m2?
Run the dependency tree command: 'inspect dependencies for typo3/phar-stream-wrapper'. 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-4v5g-8pq2-32m2",
  "modified" : "2024-06-05T17:30:00Z",
  "published" : "2024-06-05T17:30:00Z",
  "aliases" : [ ],
  "summary" : "By-passing Protection of PharStreamWrapper Interceptor",
  "details" : "Insecure deserialization is a vulnerability which occurs when untrusted data is used to abuse the logic of an application. In July 2018, the vulnerability of insecure deserialization when executing Phar archives was addressed by removing the known attack vector in the TYPO3 core. For more details read the corresponding TYPO3 advisory.\n\nIn addition, a new interceptor was introduced to protect possible (but unknown) vulnerabilities in 3rd party components like TYPO3 extensions. Basically, the PharStreamWrapper intercepts direct invocations of Phar archives and allows or denies further processing based on individual rules.\n\nRecently, the PharStreamWrapper was extracted from the TYPO3 core and released as standalone package under the MIT license. It is now available for any PHP driven project.\n\nThe stream wrapper overwrites the existing Phar handling of PHP, applies its own assertions and then restores the native PHP Phar handling for the corresponding commands (e.g. file_exists, include, fopen) to continue processing. After that, the native PHP Phar handling gets disabled and is overwritten by the logic of the PharStreamWrapper again. This is the only way to control invocations of Phar archives as PHP only allows a single handler for each corresponding stream.\n\nWe were informed that exception and error handlers in custom applications (e.g. TYPO3 extensions) sometimes didn't return to the original operating sequence of the PharStreamWrapper. A possible consequence was that the unprotected native PHP Phar handling remained active and therefore became vulnerable for the basic issue of insecure deserialization again.\n\nExamples\nTake a look at the following examples showing how the handling is by-passed in custom application code.\n\nScenario A: Exception thrown from code organized in a Phar archive\n```\ntry {\n    include('phar://path-to-archive/good-archive.phar');\n} catch (\\Throwable $throwable) {\n    // not doing much here, continue execution\n}\n// the insecure value can be anything that is or was user-submitted\n// and cannot be trusted in terms of security, $_GET is just used as example\n$insecureValue = $_GET['path'];\n// the value might be 'phar://path-to-archive/malicious-archive.phar'\nfile_exists($insecureValue);\n```\nScenario B: Errors converted to exceptions and thrown when interacting with archive contents\n```\n// set error handler in order to convert errors to exceptions\nset_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {\n   throw new ErrorException($errstr, 0, $errno, $errfile, $errline);\n});\n// interacting with Phar archive\ntry {\n   $resource = opendir('phar://path-to-archive/good-archive.phar/non-existing-path/');\n   closedir($resource);\n} catch (\\Throwable $throwable) {\n   // not doing much here, continue execution\n}\n// the insecure value can be anything that is or was user-submitted\n// and cannot be trusted in terms of security, $_GET is just used as example\n$insecureValue = $_GET['path'];\n// the value might be 'phar://path-to-archive/malicious-archive.phar'\nfile_exists($insecureValue);\n```",
  "severity" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "typo3/phar-stream-wrapper"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.0.0"
      }, {
        "fixed" : "2.0.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "typo3/phar-stream-wrapper"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "3.0.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/typo3/phar-stream-wrapper/2018-10-18-1.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://typo3.org/security/advisory/typo3-psa-2018-001"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-06-05T17:30:00Z",
    "nvd_published_at" : null
  }
}