The vulnerability is a cross-site scripting (XSS) issue within Contao's templating system and various components that render user-controllable data. The analysis of the patches between versions 4.13.56 and 4.13.57 reveals multiple instances where data was being rendered in HTML templates without proper escaping for the specific context (e.g., HTML attributes vs. HTML text).
The root causes are:
- Improper Escaping: Several components, such as
ContentAccordion, ModuleSearch, and PageRegular, were directly embedding variables into HTML attributes or content without using the correct escaping functions. For example, values for style, content, title, and placeholder attributes were not sanitized, allowing attackers to break out of the attribute and inject malicious code.
- Incorrect Templating Logic: The
Template::once() helper method had a logical flaw. It would store the result of a callback and return it on subsequent calls. However, it replaced the callback with its result. If the result was a string (e.g., user input), the next call would return the raw string, bypassing the intended logic and potentially rendering unescaped data.
The patches consistently apply context-aware escaping using StringUtil::specialcharsAttribute() for HTML attributes and StringUtil::specialchars() for HTML content, and fix the logic in the Template::once() method. These changes prevent the injection and execution of arbitrary scripts in the browser.