The vulnerability lies in the improper sanitization of CSS style definitions provided through classDef in Mermaid diagrams. The analysis of the patches reveals two key functions involved in this vulnerability.
The function createUserStyles is identified as the entry point for the malicious input. The test cases added in the patches explicitly use this function to demonstrate the CSS injection vector by passing a crafted style string. This function is responsible for orchestrating the creation of styles from user-provided classDef values.
The lower-level function cssImportantStyles is where the actual insecure string concatenation occurs. In the vulnerable versions, this function takes style classes and directly embeds them into a CSS rule string. The patch applies the sanitizeCss function to the user-controllable input within cssImportantStyles, thus mitigating the vulnerability by preventing the injection of unbalanced braces and additional CSS rules.
Therefore, during exploitation, a runtime profile would likely show createUserStyles initiating the style generation process, which in turn calls cssImportantStyles where the unsanitized user input is processed, leading to the CSS injection.