-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: disallow management actions without a verified primary email #14126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: disallow management actions without a verified primary email #14126
Conversation
24f43b0
to
1fe699c
Compare
As a way to continue on the path of making user accounts more secured, require a user to have verified an email address prior to performing any other management actions. Preserves their ability to manage their own account. Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
1fe699c
to
16369e8
Compare
@@ -134,6 +134,22 @@ def forbidden(exc, request): | |||
|
|||
# Check if the error has a "result" attribute and if it is a WarehouseDenied | |||
if hasattr(exc, "result") and isinstance(exc.result, WarehouseDenied): | |||
# If the forbidden error is because the user does not have a verified | |||
# email address, redirect them to their account page for email verification. | |||
if exc.result.reason == "unverified_email": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize you're just following the pattern already established here, but I'm wondering if these should be subclasses of WarehouseDenied
that we check with isinstance
instead of comparing the reason here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good thought - I tinkered around with that, but didn't understand exactly what I was doing, since these aren't exceptions, rather subclasses of pyramid.security.Denied
. I'll leave this as is for now, especially since there's other work in play about restructuring the ACLs and separating authentication from authorization a little better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with or without the change
Introduced in pypi#14126, check was only applied for the SessionSecurityPolicy. Migrating it into the common helper applies to both Session and BasicAuth policies. It was implicitly being checked before with BasicAuth via `_check_mfa` which, if enabled and mandated, would have required a verified email anyhow. Moving it into the helper allows us to have a consistent requirement across both policies. Signed-off-by: Mike Fiedler <[email protected]>
As a way to continue on the path of making user accounts more secured,
require a user to have verified the primary email address prior to performing any
other management actions.
Preserves their ability to manage their own account.
Signed-off-by: Mike Fiedler [email protected]