CVE-2022-31140: Cuyz/valinor Valinor Error Messages Leading To Vulnerability

HIGH
Advisory Identifier: GHSA-5pgm-3j3g-2rc7
CVSS 7.5
CWE-209 CWE-200
Published
Advisory Summary

CVE-2022-31140 is a HIGH (CVSS 7.5) valinor error messages leading to vulnerability (CWE-209: Generation of Error Message Containing Sensitive Information) affecting Cuyz/valinor libraries in the Packagist ecosystem. The issue involves valinor error messages leading to potential data exfiltration before v0.12.0. Remediation is available by upgrading affected packages to version 0.12.0.

CVE-2022-31140 at a Glance

CVE Identifier CVE-2022-31140
GHSA Identifier GHSA-5pgm-3j3g-2rc7
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-209: Generation of Error Message Containing Sensitive Information
Affected Product Cuyz/valinor
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 7.5

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:N/A:N).

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 None (I:N)
Availability None (A:N)

How to Fix CVE-2022-31140

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

cuyz/valinor fixed: 0.12.0
Upgrade cuyz/valinor to 0.12.0
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 cuyz/valinor

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-31140, inspect your project dependencies for Cuyz/valinor:

inspect dependencies for cuyz/valinor

Analyze the terminal output to locate any version of Cuyz/valinor in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.12.0), 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-209: Generation of Error Message Containing Sensitive Information, where the product generates an error message that includes sensitive information about its environment, users, or associated data. In Cuyz/valinor, 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

```php <?php namespace My\App; use CuyZ\Valinor\Mapper\MappingError; use CuyZ\Valinor\Mapper\Tree\Node; use CuyZ\Valinor\Mapper\Tree\NodeTraverser; use CuyZ\Valinor\MapperBuilder; require_once __DIR__ . '/Valinor/vendor/autoload.php'; final class Money { private function __construct(public readonly string $amount) { } public static function fromString(string $money): self { if (1 !== \preg_match('/^\d+ [A-Z]{3}$/', $money)) { throw new \InvalidArgumentException(\sprintf('Given "%s" is not a recognized monetary amount', $money)); } return new self($money); } } class Foo { public function __construct( private readonly Money $a, private readonly Money $b, private readonly Money $c, ) {} } $mapper = (new MapperBuilder()) ->registerConstructor([Money::class, 'fromString']) ->mapper(); try { var_dump($mapper->map(Foo::class, [ 'a' => 'HAHA', 'b' => '100 EUR', 'c' => 'USD 100' ])); } catch (MappingError $e) { $messages = (new NodeTraverser(function (Node $node) { foreach ($node->messages() as $message) { var_dump([ '$message', $message->path(), $message->body() ]); } return ''; }))->traverse($e->node()); iterator_to_array($messages); } ``` Now, this is quite innocent: it produces following output: ``` ❯ php value-object-conversion.php array(3) { [0]=> string(8) "$message" [1]=> string(1) "a" [2]=> string(48) "Given "HAHA" is not a recognized monetary amount" } array(3) { [0]=> string(8) "$message" [1]=> string(1) "c" [2]=> string(51) "Given "USD 100" is not a recognized monetary amount" } ``` The problem is that nowhere I told valinor that it could use `Throwable#getMessage()`. This is a problem with cases where you get: * an SQL exception showing an SQL snippet * a DB connection exception showing DB ip address/username/password * a timeout detail / out of memory detail (exploring DDoS possibilities) This allows for potential data exfiltration, DDoS, enumeration attacks, etc.

CVE-2022-31140 Affected Cuyz/valinor Versions

1 component(s)
Fixed Versions:
0.12.0
Product / Package Ecosystem Affected Versions Fixed Version
cuyz/valinor
Packagist
< 0.12.0
0.12.0

References

Frequently Asked Questions

What is CVE-2022-31140?
CVE-2022-31140 is a security vulnerability in Cuyz/valinor involving Valinor error messages leading to potential data exfiltration before v0.12.0 under CWE-209: Generation of Error Message Containing Sensitive Information.
Which Cuyz/valinor versions are affected?
Affected versions include releases prior to 0.12.0 across affected packages: cuyz/valinor.
What version fixes CVE-2022-31140?
Upgrading to 0.12.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is cuyz/valinor affected?
Yes, cuyz/valinor is affected in releases prior to 0.12.0. Upgrade your dependency to 0.12.0 or later.
What is the CVSS score of CVE-2022-31140?
CVE-2022-31140 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2022-31140?
CVE-2022-31140 is classified under CWE-209: Generation of Error Message Containing Sensitive Information (The product generates an error message that includes sensitive information about its environment, users, or associated data.).
How can I check Packagist dependencies for CVE-2022-31140?
Run the dependency tree command: 'inspect dependencies for cuyz/valinor'. 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-5pgm-3j3g-2rc7",
  "modified" : "2022-07-19T22:31:41Z",
  "published" : "2022-07-12T22:15:29Z",
  "aliases" : [ "CVE-2022-31140" ],
  "summary" : "Valinor error messages leading to potential data exfiltration before v0.12.0",
  "details" : "```php\n<?php\n\nnamespace My\\App;\n\nuse CuyZ\\Valinor\\Mapper\\MappingError;\nuse CuyZ\\Valinor\\Mapper\\Tree\\Node;\nuse CuyZ\\Valinor\\Mapper\\Tree\\NodeTraverser;\nuse CuyZ\\Valinor\\MapperBuilder;\n\nrequire_once __DIR__ . '/Valinor/vendor/autoload.php';\n\nfinal class Money\n{\n    private function __construct(public readonly string $amount)\n    {\n    }\n\n    public static function fromString(string $money): self\n    {\n        if (1 !== \\preg_match('/^\\d+ [A-Z]{3}$/', $money)) {\n            throw new \\InvalidArgumentException(\\sprintf('Given \"%s\" is not a recognized monetary amount', $money));\n        }\n        \n        return new self($money);\n    }\n}\n\nclass Foo\n{\n    public function __construct(\n        private readonly Money $a,\n        private readonly Money $b,\n        private readonly Money $c,\n    ) {}\n}\n\n$mapper = (new MapperBuilder())\n    ->registerConstructor([Money::class, 'fromString'])\n    ->mapper();\n\ntry {\n    var_dump($mapper->map(Foo::class, [\n        'a' => 'HAHA',\n        'b' => '100 EUR',\n        'c' => 'USD 100'\n    ]));\n} catch (MappingError $e) {\n    $messages = (new NodeTraverser(function (Node $node) {\n        foreach ($node->messages() as $message) {\n            var_dump([\n                '$message',\n                $message->path(),\n                $message->body()\n            ]);\n        }\n        return '';\n    }))->traverse($e->node());\n\n    iterator_to_array($messages);\n}\n```\n\nNow, this is quite innocent: it produces following output:\n\n```\n❯ php value-object-conversion.php\narray(3) {\n  [0]=>\n  string(8) \"$message\"\n  [1]=>\n  string(1) \"a\"\n  [2]=>\n  string(48) \"Given \"HAHA\" is not a recognized monetary amount\"\n}\narray(3) {\n  [0]=>\n  string(8) \"$message\"\n  [1]=>\n  string(1) \"c\"\n  [2]=>\n  string(51) \"Given \"USD 100\" is not a recognized monetary amount\"\n}\n```\n\nThe problem is that nowhere I told valinor that it could use `Throwable#getMessage()`.\n\nThis is a problem with cases where you get:\n\n * an SQL exception showing an SQL snippet\n * a DB connection exception showing DB ip address/username/password\n * a timeout detail / out of memory detail (exploring DDoS possibilities)\n\nThis allows for potential data exfiltration, DDoS, enumeration attacks, etc.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "cuyz/valinor"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.12.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/CuyZ/Valinor/security/advisories/GHSA-5pgm-3j3g-2rc7"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-31140"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/CuyZ/Valinor"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/CuyZ/Valinor/releases/tag/0.12.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200", "CWE-209" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-07-12T22:15:29Z",
    "nvd_published_at" : "2022-07-11T20:15:00Z"
  }
}