The vulnerability analysis identified a reflected Cross-Site Scripting (XSS) issue within the Slim framework's HtmlErrorRenderer. The root cause was the direct rendering of exception titles and descriptions into an HTML error page without proper output escaping. An attacker could exploit this by crafting a request that causes an error where the error's title or description, set via HttpException::setTitle() or HttpException::setDescription(), contains malicious JavaScript.
The investigation started by examining the provided patch information for version 4.15.2. By comparing the git tags for versions 4.15.1 and 4.15.2 of the slimphp/Slim repository, I located the specific commit that addressed the security issue. The commit message, "Escape error title and description in HtmlErrorRenderer", clearly indicated its purpose.
Analysis of the commit's diff revealed changes in Slim/Error/Renderers/HtmlErrorRenderer.php. Two methods were modified:
-
__invoke(): The code was changed to wrap the output of $this->getErrorDescription($exception) with htmlspecialchars(). This prevents raw HTML in the error description from being rendered by the browser.
-
renderHtmlBody(): A line was added to escape the $title parameter using htmlspecialchars(). This mitigates the XSS vector from the error title.
Based on these changes, the functions Slim\Error\Renderers\HtmlErrorRenderer::__invoke and Slim\Error\Renderers\HtmlErrorRenderer::renderHtmlBody were identified as the vulnerable functions. During an exploit, these functions would appear in a runtime profile as they are directly involved in processing the tainted data (title and description) and generating the vulnerable HTML output.