Q34: What are the security pitfalls of implementing 'Login with Google/GitHub' and how do you resolve them?

Difficulty:MediumTopic:OAuth Security

Common pitfalls when implementing Social Login via OAuth 2.0:

  1. Account Takeover via Unverified Email: Trusting unverified emails from social providers. Fix: Verify the email_verified claim from OIDC providers before linking social accounts to local profile records.
  2. CSRF in Social Callback: Omitting state parameter validation during OAuth redirects. Fix: Enforce strict state checks.
  3. Token Misuse: Accepting an ID token intended for a different application client ID. Fix: Always validate that aud (Audience) claim matches your application's client ID.
Key Takeaways
  • Always verify email_verified: true assertions before linking third-party social accounts to local profiles.

  • Validate the aud (Audience) claim to prevent using tokens issued for different applications.