The vulnerability lies within the render_toc_ul function in src/mistune/toc.py. This function generates an HTML table of contents from a list of heading items. The core of the vulnerability is in the line item = '<a href="#{}">{}</a>'.format(k, text), where k is the ID derived from the heading text and text is the visible label. The k variable was directly embedded into the href attribute without any HTML escaping. An attacker could craft a markdown heading where the text, when converted to an ID, contains malicious HTML. For example, a heading like ## x"><script>alert(1)</script> would result in the ID x"><script>alert(1)</script>. When render_toc_ul processes this, it generates a malformed <a> tag: <a href="#x"><script>alert(1)</script>">...</a>, which injects and executes the script in the browser. The patch 04880a0 addresses this by applying an escape() function to the k variable before it's inserted into the format string, ensuring that any special HTML characters are properly neutralized.