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(dashboard): check edit permissions correctly on frontend #14626

Merged
merged 3 commits into from
May 14, 2021

Conversation

suddjian
Copy link
Member

@suddjian suddjian commented May 13, 2021

SUMMARY

This fixes a case where users who were not owners of a dashboard were incorrectly seeing the "Edit" button. This is not a security hole as the users cannot successfully submit their edits, but it was incorrect UI that needed to be fixed.

The frontend was incorrectly inferring dashboard edit permissions. This change fixes the issue by copying logic from the backend's check_ownership function.

The code of the frontend version implements the same check, while being much simpler than the backend version due to being a pure function, dashboard-specific, and not having parameterized function behavior.

I did this instead of changing endpoints, because the caching of the existing dashboard endpoints depends on returning the same data to all users, and because implementing a new endpoint to just return a boolean felt wrong.

TEST PLAN

  1. Log in as a user with "Alpha" role (or other non-admin role with dashboard edit permissions)
  2. View a dashboard of which you are an owner - you should be able to edit
  3. View a dashboard of which you are not an owner - you should not be able to edit
  4. Log in as an admin: you should be able to edit any dashboard, regardless of ownership
  5. Log in as a user without dashboard edit permissions (e.g. Gamma role): You should not be able to edit any dashboard, regardless of ownership

ADDITIONAL INFORMATION

@codecov
Copy link

codecov bot commented May 13, 2021

Codecov Report

Merging #14626 (1fc7e8d) into master (d31958c) will increase coverage by 0.03%.
The diff coverage is 68.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14626      +/-   ##
==========================================
+ Coverage   77.47%   77.51%   +0.03%     
==========================================
  Files         959      959              
  Lines       48492    48853     +361     
  Branches     5681     5830     +149     
==========================================
+ Hits        37569    37867     +298     
- Misses      10723    10782      +59     
- Partials      200      204       +4     
Flag Coverage Δ
hive 80.96% <ø> (ø)
javascript 72.67% <68.75%> (+0.15%) ⬆️
mysql 81.24% <ø> (ø)
postgres 81.26% <ø> (ø)
presto 80.96% <ø> (ø)
python 81.79% <ø> (ø)
sqlite 80.88% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ontend/src/common/hooks/apiResources/dashboards.ts 40.00% <0.00%> (-10.00%) ⬇️
superset-frontend/src/dashboard/actions/hydrate.js 1.73% <0.00%> (-0.02%) ⬇️
...rset-frontend/src/dashboard/util/findPermission.ts 100.00% <100.00%> (ø)
...tend/src/explore/components/ExploreChartHeader.jsx 60.41% <0.00%> (-2.75%) ⬇️
superset-frontend/src/components/Menu/SubMenu.tsx 95.50% <0.00%> (-0.21%) ⬇️
...et-frontend/src/components/EditableTitle/index.tsx 83.78% <0.00%> (-0.17%) ⬇️
...nd/src/explore/components/ExploreViewContainer.jsx 2.31% <0.00%> (-0.03%) ⬇️
...components/DashboardBuilder/DashboardContainer.tsx 100.00% <0.00%> (ø)
...uperset-frontend/src/components/Menu/MenuRight.tsx 92.95% <0.00%> (+0.10%) ⬆️
...ntend/src/explore/components/ExploreChartPanel.jsx 17.33% <0.00%> (+0.19%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d31958c...1fc7e8d. Read the comment docs.

@suddjian suddjian requested a review from villebro May 13, 2021 20:34
@suddjian suddjian force-pushed the fix-dash-edit-permission branch 2 times, most recently from 189e22e to 0ba22d3 Compare May 13, 2021 21:39
@suddjian suddjian added the need:review Requires a code review label May 13, 2021
@junlincc
Copy link
Member

@suddjian hi Aaron, can you add manual test plan for our QA team to help test? thanks 😊

@suddjian
Copy link
Member Author

Done @junlincc thank you for the heads up

@suddjian suddjian added the bash! label May 14, 2021
@@ -25,8 +25,9 @@ export const useDashboard = (idOrSlug: string | number) =>
useApiV1Resource<Dashboard>(`/api/v1/dashboard/${idOrSlug}`),
dashboard => ({
...dashboard,
metadata: JSON.parse(dashboard.json_metadata),
position_data: JSON.parse(dashboard.position_json),
metadata: dashboard.json_metadata && JSON.parse(dashboard.json_metadata),
Copy link
Member

Choose a reason for hiding this comment

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

should this be initialized as a empty object if dashboard comes back as undefined.

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 assume you mean if the metadata is undefined (if the dashboard is undefined it will be a 404). I don't think it should be initialized like that, null is different from an empty object.

This is not actually new behavior, I just had to write this guard to appease the type system since I corrected the types of some dashboard fields to be nullable.

@suddjian
Copy link
Member Author

fixes #14442

Copy link
Member

@pkdotson pkdotson left a comment

Choose a reason for hiding this comment

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

LGTM!

@michael-s-molina
Copy link
Member

#14442

@suddjian GitHub will not automatically close this issue because it doesn't check for comments. You should add this text to the PR description 😉

@nytai nytai linked an issue May 14, 2021 that may be closed by this pull request
3 tasks
@suddjian suddjian merged commit f16c708 into master May 14, 2021
@suddjian suddjian deleted the fix-dash-edit-permission branch May 14, 2021 20:13
@junlincc junlincc added rush! Requires immediate attention and removed need:review Requires a code review rush! Requires immediate attention labels May 14, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
…14626)

* fix(dashboard): check edit permissions correctly on frontend

* fix types, appease linter

* handle nulls better
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
…14626)

* fix(dashboard): check edit permissions correctly on frontend

* fix types, appease linter

* handle nulls better
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
…14626)

* fix(dashboard): check edit permissions correctly on frontend

* fix types, appease linter

* handle nulls better
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.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/L 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Public dashboard does not work due to JS error in findPermission.ts
6 participants