The vulnerability consists of two main issues that, when combined, lead to account takeover. The first is a type coercion bypass in the handling of the email_verified OIDC claim within the userOIDC function in coderd/userauth.go. The code was expecting a boolean value but failed to handle cases where an Identity Provider (IdP) would send a string (e.g., 'false') or other non-boolean types. This resulted in the email being treated as verified, even when it wasn't.
The second issue was an unconditional email-based account fallback in the findLinkedUser function, also in coderd/userauth.go. This function is called by both userOIDC and userOAuth2Github. If a user was not found by their unique linked ID, the system would fall back to searching for the user by their email address. An attacker could exploit this by registering an account with a vulnerable IdP using a victim's email address. Then, by logging into Coder via OIDC, the attacker's session would be linked to the victim's Coder account due to the email fallback, resulting in a full account takeover.
The patches address these issues by:
- Introducing a
coerceEmailVerified function to properly handle various data types for the email_verified claim, ensuring that the check is fail-closed.
- Modifying
findLinkedUser to restrict the email fallback mechanism. The fallback is now only allowed for first-time account linking, preventing an attacker from taking over an existing account that is already linked to a different IdP subject.