fat-catTW commented on code in PR #77138:
URL: https://github.com/apache/airflow/pull/77138#discussion_r4587320704
##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -310,23 +337,37 @@ def get_user(self) -> User:
def session(self):
return self.appbuilder.session
- @cachedmethod(lambda self: self.cache, key=lambda _, token:
int(token["sub"]))
def deserialize_user(self, token: dict[str, Any]) -> User:
user_id = int(token["sub"])
+ fingerprint = token.get(PASSWORD_FINGERPRINT_CLAIM)
+ user = self._get_active_user(user_id)
+ if not _is_password_fingerprint_matching(fingerprint, user):
+ # The cached user may predate a password change. Re-read it so a
token issued after the
+ # change is accepted without waiting for the cache entry to expire.
+ user = self._fetch_active_user(user_id)
+ self.cache[user_id] = user
+ if not _is_password_fingerprint_matching(fingerprint, user):
+ raise ValueError(f"Token of user with id {user_id} was not
issued for their current password")
+ return user
+
+ @cachedmethod(lambda self: self.cache, key=lambda _, user_id: user_id)
Review Comment:
I think this cache leaves a revocation window.
If the user is cached before a password change, an old token still matches
the cached password hash, so we do not re-fetch from DB until the TTL expires.
Could we add a test for this ordering and avoid using the cached password
hash for this check?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]