The vulnerability exists because user-provided nicknames were not properly sanitized before being included in notification emails, allowing for two types of link injection. The analysis of the patch commit 4dde99729abdce8f6e2a7437c86e38735fdcca28 reveals two key areas of modification that directly address the vulnerability.
-
Output Sanitization (NicknameDriver.php): The primary vulnerable function is Flarum\Nicknames\NicknameDriver::displayName. Before the patch, this function directly returned the stored nickname. This function is called when Flarum needs to display a user's name, including when constructing emails. An attacker could set their nickname to a value like [Click Me](https://evil.com) or malicious.com. When an email notification involving this user was sent, the displayName function would return this malicious string, which would then be rendered as a clickable link by the recipient's email client. The patch fixes this by adding sanitization directly within the displayName function to strip markdown characters and break domain auto-linking.
-
Input Validation (AddNicknameValidation.php): The second function, Flarum\Nicknames\AddNicknameValidation::__invoke, contributes to the vulnerability by failing to prevent malicious nicknames from being saved in the first place. The patch adds a validation rule to this function to reject nicknames containing characters like []()<>, providing a defense-in-depth mechanism by blocking malicious input before it is stored.
Therefore, during exploitation, the Flarum\Nicknames\NicknameDriver::displayName function would be the one appearing in a runtime profile as it processes the malicious nickname to be included in the email. The AddNicknameValidation::__invoke function is involved when the attacker sets their nickname.