-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
fix: Prevent cached bootstrap data from leaking between users w/ same first/last name #26023
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,7 +380,9 @@ def menu_data(user: User) -> dict[str, Any]: | |
|
||
|
||
@cache_manager.cache.memoize(timeout=60) | ||
def cached_common_bootstrap_data(user: User, locale: str) -> dict[str, Any]: | ||
def cached_common_bootstrap_data( # pylint: disable=unused-argument | ||
user: User, user_id: int | None, locale: str | ||
) -> dict[str, Any]: | ||
"""Common data always sent to the client | ||
|
||
The function is memoized as the return value only changes when user permissions | ||
|
@@ -424,8 +426,9 @@ def cached_common_bootstrap_data(user: User, locale: str) -> dict[str, Any]: | |
|
||
|
||
def common_bootstrap_payload(user: User) -> dict[str, Any]: | ||
user_id = user.id if hasattr(user, "id") else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the FAB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grokking through the code it seems like this is always from superset.utils.core import get_user_id
def common_bootstrap_payload() -> dict[str, Any]:
return {
**cached_common_bootstrap_data(get_user_id(), get_locale()),
"flash_messages": get_flashed_messages(with_categories=True),
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh great point it is always
The type hint was a bit of a lie since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jfrag1 I think my comment is somewhat of a moot point given that it seems like we're going down the |
||
return { | ||
**cached_common_bootstrap_data(user, get_locale()), | ||
**cached_common_bootstrap_data(user, user_id, get_locale()), | ||
"flash_messages": get_flashed_messages(with_categories=True), | ||
} | ||
|
||
|
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.
Why do we need both
User
anduser_id
? Surely the former contains the ID which should then be used for the cache key given it's globally unique.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.
While yes,
User
"contains" the ID, it's__repr__
method that flask-caching uses to generate the cache key does not (see PR description).The 2 alternatives to this fix as-is would be to:
__repr__
upstream on FAB to include the id. (cc @dpgaspar if this is a welcome change)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.
@jfrag1 sorry I missed that detail when initially glancing over the PR description. Is a third alternative to just pass in
user_id
instead of bothuser
anduser_id
?