In this article, we present a critical vulnerability found in Moodle that allows attackers to leverage a self-XSS vulnerability to an impactful Account Takeover. The vulnerability was identified through an audit of the open-source project and is tracked as CVE-2023-40320. It affects Moodle versions before 4.2.2, 4.1.5, 4.0.10, 3.11.16, and 3.9.23, where an attacker can exploit a self-XSS vulnerability in the WYSIWYG editor to gain access to a victim's account through OAuth authentication. The vulnerability was patched by removing the call to the complete_user_login function, which caused the confirm-linkedlogin.php endpoint to not automatically login the user by clicking the link. This highlights the importance of clean code practices and regular security audits in reducing the risk of introducing security flaws that could be exploited by attackers.