The vulnerability lies in the improper handling of user-provided input within the mistune library, specifically the lack of HTML escaping for certain parameters before they are rendered into the final HTML output. The analysis of the patch between versions 3.2.0 and 3.2.1 revealed that the commit a3cb6e5655308797e8be021d6c7b5bab13cbace2 addresses this issue by applying an escape function to the vulnerable parameters.
The primary vulnerable function, as highlighted in the advisory, is render_figure in src/mistune/directives/image.py. The figclass and figwidth parameters were concatenated directly into the HTML string. The patch confirms this by adding escape_text() to these parameters.
Furthermore, the same commit fixed similar vulnerabilities in two other functions:
render_admonition in src/mistune/directives/admonition.py, where the class attribute was not escaped.
block_error in src/mistune/renderers/html.py, where the error text was not escaped.
All three functions are considered vulnerable as they would process potentially malicious input and would appear in a runtime profile during exploitation. The root cause is the failure to sanitize user-controlled input that is used to construct HTML, leading to Cross-Site Scripting (XSS).