The vulnerability lies in the smartquotes rule of markdown-it, specifically within the lib/rules_core/smartquotes.mjs file. The analysis of the patch between the vulnerable version (14.1.1) and the patched version (14.2.0) confirms the details provided in the advisory. The commit 9ce2087562c45d1e5ddd9f76b990f4b3fbe040e5 directly addresses the performance issue.
The root cause is the replaceAt function, which performs string replacement inefficiently through slicing and concatenation. This function has a time complexity of O(n) for a single operation. The process_inlines function iterates over quote characters in a given text token and calls replaceAt for each one. When an attacker provides a long string of quote characters (e.g., 160,000 quotes), this results in the O(n) replaceAt function being called O(n) times, leading to an overall quadratic complexity of O(n^2).
The patch completely removes the replaceAt function and replaces the logic in process_inlines. Instead of modifying the string in-place, the new implementation collects all the required replacements in an array and then builds the new string in a single pass using the applyReplacements helper. This changes the algorithm's complexity to O(n), effectively mitigating the Denial of Service vulnerability.