The vulnerability exists in how Mattermost constructs error pages for mobile authentication flows. The analysis of the patch 5a1ea95044dc2d1ca601bfe9a4c1bc17990f3872 reveals that two functions, utils.RenderMobileAuthComplete and utils.RenderMobileError, were directly embedding variables into HTML without proper sanitization. Specifically, redirectURL, err.Message, and config.TeamSettings.SiteName were not being escaped. This allows an attacker, who can control these values (e.g., by having administrative access to change the site name), to inject arbitrary JavaScript. When a user encounters an error or completes an authentication flow on mobile, these vulnerable functions are called to generate a status page, which would then execute the malicious script in the user's browser. The patch addresses this by introducing HTML escaping for these variables, thus preventing the XSS vulnerability.