Skip to content

Commit 3e97e29

Browse files
committed
disable basic auth for uploads if 2fa enabled
1 parent 8d03a21 commit 3e97e29

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

warehouse/accounts/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
database_login_factory,
3333
)
3434
from warehouse.email import send_password_compromised_email_hibp
35-
from warehouse.errors import BasicAuthBreachedPassword
35+
from warehouse.errors import BasicAuthBreachedPassword, BasicAuthTwoFactorEnabled
3636
from warehouse.macaroons.auth_policy import (
3737
MacaroonAuthenticationPolicy,
3838
MacaroonAuthorizationPolicy,
@@ -73,6 +73,14 @@ def _basic_auth_login(username, password, request):
7373
raise _format_exc_status(
7474
BasicAuthBreachedPassword(), breach_service.failure_message_plain
7575
)
76+
elif login_service.has_two_factor(user.id):
77+
raise _format_exc_status(
78+
BasicAuthTwoFactorEnabled(),
79+
(
80+
f"User {user.username} has two factor auth enabled, "
81+
"an API Token must be used to upload in place of password."
82+
)
83+
)
7684
elif login_service.check_password(
7785
user.id, password, tags=["method:auth", "auth_method:basic"]
7886
):

warehouse/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class BasicAuthBreachedPassword(HTTPUnauthorized):
1818
pass
1919

2020

21+
class BasicAuthTwoFactorEnabled(HTTPUnauthorized):
22+
pass
23+
24+
2125
class WarehouseDenied(Denied):
2226
def __new__(cls, s, *args, reason=None, **kwargs):
2327
inner = super().__new__(cls, s, *args, **kwargs)

0 commit comments

Comments
 (0)