Skip to content
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: Make g.user attribute access safe for public users #14287

Merged
merged 1 commit into from
Apr 26, 2021

Conversation

robdiciuccio
Copy link
Member

SUMMARY

Make g.user attribute access safe for public users by:

  1. Using the abstract get_id method
  2. Checking for presence of g.user.username before using (this property is not set for public users)

TEST PLAN

Automated tests should pass.

ADDITIONAL INFORMATION

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! but we probably should check if the user is authenticated instead of checking if certain attrs are present, seems cleaner

@@ -1024,7 +1024,7 @@ def estimate_query_cost(
if not cls.get_allow_cost_estimate(extra):
raise Exception("Database does not support cost estimation")

user_name = g.user.username if g.user else None
user_name = g.user.username if g.user and hasattr(g.user, "username") else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably makes more sense to just check if the user is authenticated, using g.user.is_authenticated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally was checking g.user.is_anonymous in these use cases, but opted for the explicit check for username, as this is the value that is being fetched. There may be use cases where username is not present in other states down the road, so thought explicit hasattr would be more future-proof.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -954,7 +954,7 @@ def favorite_status(self, **kwargs: Any) -> Response:
charts = ChartDAO.find_by_ids(requested_ids)
if not charts:
return self.response_404()
favorited_chart_ids = ChartDAO.favorited_ids(charts, g.user.id)
favorited_chart_ids = ChartDAO.favorited_ids(charts, g.user.get_id())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robdiciuccio
Copy link
Member Author

/testenv up

@github-actions
Copy link
Contributor

@robdiciuccio Ephemeral environment spinning up at http://54.201.39.228:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@robdiciuccio robdiciuccio merged commit 6875a1a into apache:master Apr 26, 2021
@robdiciuccio robdiciuccio deleted the rd/anonymous-usernames branch April 26, 2021 15:50
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/M 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to enable query execution in sqllab for Anonymous user(public role) ?
4 participants