Skip to content

Invalidate the security policy cache on login/logout #13856

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
merged 2 commits into from
Jun 4, 2023

Conversation

dstufft
Copy link
Member

@dstufft dstufft commented Jun 4, 2023

Part of the changes in #13849 was that we would cache the result of trying to get the identity from our ISecurityPolicy, since the identity should not generally change mid-request, which allowed us to ensure that the same policy that fetched the identity was also the same policy that checks permissions on the identity.

Unfortunately there is a case where the identity does change mid request, when the user is being logged out or logged in, which we didn't handle.

This caused errors whenever, within the same request, we expected request.identity to return the now logged in or now logged out user.

To fix this, we add an extension to the ISecurityPolicy class where the login and logout functions can reset the cache for a given request, similar to how it invalidates sessions when crossing the authentication boundaries.

It's possible that rather than an extension, we could piggyback off of remember() and forget(), but I don't feel comfortable doing that without sitting down and thinking through the implications.

Fixes #13855

@dstufft dstufft requested a review from a team as a code owner June 4, 2023 19:07
@dstufft
Copy link
Member Author

dstufft commented Jun 4, 2023

I guess the ultimate question is whether we think that the assumption in #13849 was generally correct, that the request.identity for a request does not change mid-request, and thus can be cached, and is still valid.

This PR assumes that it was, but with one edge case where it wasn't and fixes that one edge case.

If we think that assumption was wrong, then we would want to fix this a different way.

@ewdurbin
Copy link
Member

ewdurbin commented Jun 4, 2023

Within the lifetime of a request, this is the only case I can think where it makes sense for the identity to change... yeah.

@dstufft dstufft merged commit 636dc2d into pypi:main Jun 4, 2023
@dstufft dstufft deleted the fix-auth branch June 4, 2023 19:18
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.

WebAuthn currently broken
2 participants