Skip to content

Commit 04dd0e6

Browse files
authored
Merge commit from fork
* Allauth: don't extract secondary emails from GitHub Ref GHSA-h73w-m588-h9r6 * Use custom adapter instead * Update
1 parent 97bbb9e commit 04dd0e6

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

readthedocs/core/adapters.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import structlog
44
from allauth.account.adapter import DefaultAccountAdapter
5+
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
56
from django.utils.encoding import force_str
67

78
from readthedocs.core.utils import send_email_from_object
@@ -11,7 +12,6 @@
1112

1213

1314
class AccountAdapter(DefaultAccountAdapter):
14-
1515
"""Customize Allauth emails to match our current patterns."""
1616

1717
def format_email_subject(self, subject):
@@ -50,3 +50,18 @@ def save_user(self, request, user, form, commit=True):
5050
invitation.delete()
5151
else:
5252
log.info("Invitation not found", invitation_pk=invitation_pk)
53+
54+
55+
class SocialAccountAdapter(DefaultSocialAccountAdapter):
56+
def pre_social_login(self, request, sociallogin):
57+
"""
58+
Remove all email addresses except the primary one.
59+
60+
We don't want to populate all email addresses from the social account,
61+
it also makes it easy to mark only the primary email address as verified
62+
for providers that don't return information about email verification
63+
even if the email is verified (like GitLab).
64+
"""
65+
sociallogin.email_addresses = [
66+
email for email in sociallogin.email_addresses if email.primary
67+
]

readthedocs/settings/base.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
import os
44
import re
5-
import subprocess
65
import socket
6+
import subprocess
77

88
import structlog
9-
109
from celery.schedules import crontab
10+
from corsheaders.defaults import default_headers
11+
from django.conf.global_settings import PASSWORD_HASHERS
1112

13+
from readthedocs.builds import constants_docker
1214
from readthedocs.core.logs import shared_processors
13-
from corsheaders.defaults import default_headers
1415
from readthedocs.core.settings import Settings
15-
from readthedocs.builds import constants_docker
16-
17-
from django.conf.global_settings import PASSWORD_HASHERS
1816

1917
try:
2018
import readthedocsext.cdn # noqa
@@ -36,7 +34,6 @@
3634

3735

3836
class CommunityBaseSettings(Settings):
39-
4037
"""Community base settings, don't use this directly."""
4138

4239
# Django settings
@@ -76,7 +73,7 @@ def _show_debug_toolbar(request):
7673
# It's a "known issue/bug" and there is no solution as far as we can tell.
7774
"debug_toolbar.panels.sql.SQLPanel",
7875
"debug_toolbar.panels.templates.TemplatesPanel",
79-
]
76+
],
8077
}
8178

8279
@property
@@ -682,6 +679,7 @@ def DOCKER_LIMITS(self):
682679

683680
# Allauth
684681
ACCOUNT_ADAPTER = "readthedocs.core.adapters.AccountAdapter"
682+
SOCIALACCOUNT_ADAPTER = 'readthedocs.core.adapters.SocialAccountAdapter'
685683
ACCOUNT_EMAIL_REQUIRED = True
686684
# By preventing enumeration, we will always send an email,
687685
# even if the email is not registered, that's hurting
@@ -704,7 +702,6 @@ def DOCKER_LIMITS(self):
704702
"APPS": [
705703
{"client_id": "123", "secret": "456", "key": ""},
706704
],
707-
"VERIFIED_EMAIL": True,
708705
"SCOPE": [
709706
"user:email",
710707
"read:org",
@@ -716,6 +713,7 @@ def DOCKER_LIMITS(self):
716713
"APPS": [
717714
{"client_id": "123", "secret": "456", "key": ""},
718715
],
716+
# GitLab returns the primary email only, we can trust it's verified.
719717
"VERIFIED_EMAIL": True,
720718
"SCOPE": [
721719
"api",

0 commit comments

Comments
 (0)