The vulnerability is a CPU exhaustion issue in Mattermost caused by inefficient processing of user-provided content, specifically posts containing a large number of space-separated tokens that are parsed as hashtags. The root cause is the use of inefficient string concatenation (+=) inside loops in several functions responsible for parsing and rendering markdown content. When a malicious user sends a post with thousands of such tokens, these functions consume excessive CPU resources, leading to a denial of service.
The primary vulnerable function is model.ParseHashtags, which is directly responsible for parsing hashtags from a post. The provided patches show that this function was modified to use the more performant strings.Builder for string construction and to add a size limit to the generated hashtag string. This directly addresses the vulnerability as described.
In addition to ParseHashtags, the same security patch also fixes similar performance issues in other markdown processing and rendering functions, such as markdown.renderBlockHTML, markdown.RenderInlineHTML, markdown.(*FencedCode).Code, and markdown.(*IndentedCode).Code. These functions also used inefficient string concatenation and were patched to use strings.Builder. While the vulnerability description specifically calls out hashtags, these other functions would also be triggered when processing a post and would contribute to the overall CPU exhaustion. Therefore, they are included as part of the vulnerable functions set.