Skip to content

Commit e21f943

Browse files
committed
Merge remote-tracking branch 'fixes/oauth_relink'
2 parents 4bb553f + 387678a commit e21f943

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

cps/oauth_bb.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ def bind_oauth_or_register(provider_id, provider_user_id, redirect_url, provider
134134
oauth_entry = query.first()
135135
# already bind with user, just login
136136
if oauth_entry.user:
137+
# If a user is already logged in and it's a different account, reject the link
138+
# to prevent account takeover via shared OAuth identities
139+
if current_user and current_user.is_authenticated and oauth_entry.user_id != current_user.id:
140+
flash(_("This %(oauth)s account is already linked to a different user",
141+
oauth=provider_name), category="error")
142+
log.warning("User %s tried to link OAuth account already bound to user %s",
143+
current_user.id, oauth_entry.user_id)
144+
return redirect(url_for('web.profile'))
137145
login_user(oauth_entry.user)
138146
log.debug("You are now logged in as: '%s'", oauth_entry.user.name)
139147
flash(_("Success! You are now logged in as: %(nickname)s", nickname=oauth_entry.user.name),

0 commit comments

Comments
 (0)