Invalidate the security policy cache on login/logout #13856
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()
andforget()
, but I don't feel comfortable doing that without sitting down and thinking through the implications.Fixes #13855