The vulnerability is a classic timing side-channel attack in the authentication process. The root cause is the non-constant time execution of the auth.JSONAuth.Auth function. In the vulnerable version, the code first fetches the user from the database. If the user is not found, it returns an error right away. If the user is found, it then proceeds to call users.CheckPwd to compare the provided password with the stored hash using bcrypt, which is an intentionally slow operation. This difference in execution paths—an immediate return for an invalid user versus a delayed return for a valid user (even with a wrong password)—allows an attacker to measure the server's response time to distinguish between valid and invalid usernames.
The patch addresses this by refactoring the logic to ensure the execution time is consistent regardless of whether the username exists. It achieves this by always performing a password check. If the user does not exist, it compares the provided password against a pre-generated invalid password hash. This ensures that the expensive bcrypt comparison is performed in both scenarios, making the response times for valid and invalid usernames statistically indistinguishable and thus mitigating the timing attack.