The vulnerability lies in the CssSelector class within the chrome-php/chrome package. Specifically, the __construct method was accepting a CSS selector expression as a string and storing it without any sanitization or encoding. This raw expression was then used by the expressionCount and expressionFindOne methods to construct JavaScript code that would be executed in a browser context (likely via a WebDriver or similar interface).
The lack of encoding meant that if a user-supplied CSS selector contained malicious characters (e.g., "-alert(1)-"), these characters would be directly embedded into the JavaScript string, leading to a cross-site scripting (XSS) vulnerability. An attacker could potentially craft a CSS selector that, when processed by these methods, would execute arbitrary JavaScript in the context of the page being interacted with.
The patch addresses this by using json_encode with appropriate flags (JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, JSON_THROW_ON_ERROR) in the __construct method to ensure the selector is safely encoded before being used in JavaScript contexts. The expressionCount and expressionFindOne methods were updated to use this new encoded property (expressionEncoded) instead of the raw input.