Skip to content

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

Merged

Conversation

miketheman
Copy link
Member

@miketheman miketheman commented Jul 13, 2023

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]

@miketheman miketheman force-pushed the miketheman/require-verified-email-to-manage branch from 24f43b0 to 1fe699c Compare July 14, 2023 16:16
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]>
@miketheman miketheman force-pushed the miketheman/require-verified-email-to-manage branch from 1fe699c to 16369e8 Compare July 18, 2023 14:21
@miketheman miketheman marked this pull request as ready for review July 18, 2023 23:14
@miketheman miketheman requested a review from a team as a code owner July 18, 2023 23:14
@miketheman miketheman changed the title feat: disallow management actions without a verified email feat: disallow management actions without a verified primary email Jul 18, 2023
@miketheman miketheman requested a review from di July 18, 2023 23:15
@@ -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":
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@di di left a 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

@miketheman miketheman merged commit d188608 into pypi:main Jul 19, 2023
@miketheman miketheman deleted the miketheman/require-verified-email-to-manage branch July 19, 2023 17:18
miketheman added a commit to miketheman/warehouse that referenced this pull request Aug 7, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants