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: Chart can be added to dashboard by non-owner via save as option #24630

Conversation

jfrag1
Copy link
Member

@jfrag1 jfrag1 commented Jul 8, 2023

SUMMARY

This PR fixes a bug that allowed a user to add a chart to a dashboard they had access to view, but did not own. This was possible because the POST /api/v1/chart endpoint used to create new charts allows a list of dashboard id's to be passed that the new chart should be added to. However, the endpoint did not validate whether the user was an owner of these dashboards, only if they could view the dashboard (via the filter on the DashboardDAO).

This PR patches this endpoint so that it now verifies the user is an owner of each dashboard they are trying to add the new chart to. It also includes a fix to the explore frontend code so that the save modal dashboard dropdown only pre-populates if the user is an owner of the dashboard they came from.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before (logged in as alpha role but not owner of the dashboard):

non_owner_save_as_before

After (same user):

non_owner_save_as_after

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jul 8, 2023

Codecov Report

Merging #24630 (98f8467) into master (c53b249) will increase coverage by 0.10%.
The diff coverage is 100.00%.

❗ Current head 98f8467 differs from pull request most recent head b5fe9c4. Consider uploading reports for the commit b5fe9c4 to get more accurate results

@@            Coverage Diff             @@
##           master   #24630      +/-   ##
==========================================
+ Coverage   68.97%   69.08%   +0.10%     
==========================================
  Files        1907     1907              
  Lines       74153    74156       +3     
  Branches     8182     8180       -2     
==========================================
+ Hits        51148    51230      +82     
+ Misses      20882    20803      -79     
  Partials     2123     2123              
Flag Coverage Δ
hive 54.13% <37.50%> (?)
mysql 79.48% <100.00%> (?)
postgres 79.56% <100.00%> (+<0.01%) ⬆️
presto 54.03% <37.50%> (-0.01%) ⬇️
python 83.54% <100.00%> (+0.21%) ⬆️
sqlite 78.12% <100.00%> (+<0.01%) ⬆️
unit 54.82% <37.50%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...hart-echarts/src/MixedTimeseries/transformProps.ts 0.78% <ø> (ø)
...rset-frontend/src/explore/components/SaveModal.tsx 35.13% <ø> (+0.04%) ⬆️
superset/datasets/commands/create.py 100.00% <ø> (ø)
superset/examples/birth_names.py 70.00% <ø> (ø)
superset/utils/pandas_postprocessing/prophet.py 81.03% <ø> (ø)
superset/charts/api.py 87.85% <100.00%> (+0.07%) ⬆️
superset/charts/commands/create.py 92.30% <100.00%> (+0.64%) ⬆️
superset/charts/commands/exceptions.py 94.23% <100.00%> (+0.23%) ⬆️

... and 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -69,6 +71,9 @@ def validate(self) -> None:
dashboards = DashboardDAO.find_by_ids(dashboard_ids)
if len(dashboards) != len(dashboard_ids):
exceptions.append(DashboardsNotFoundValidationError())
for dash in dashboards:
if not security_manager.is_owner(dash):
raise DashboardsForbiddenError()
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should return DashboardsNotFoundValidationError as otherwise it can be exploit to validate this dashboard id does exist

Copy link
Contributor

Choose a reason for hiding this comment

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

also should we append the error to the exceptions array to keep it consistent

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 wonder if we should return DashboardsNotFoundValidationError as otherwise it can be exploit to validate this dashboard id does exist

I don't believe this is necessary here since DashboardDAO.find_by_ids will only return dashboards the user can view (via the DashboardAccessFilter).

also should we append the error to the exceptions array to keep it consistent

I considered this, but the ChartInvalidError thrown at the end with all the exceptions will always return a 422 error response, and I thought it was more appropriate to return a 403 here. Other commands, for example UpdateChartCommand have some exceptions which get appended and others which are thrown immediately, so it's not a new pattern.

Copy link
Member

@Antonio-RiveroMartnez Antonio-RiveroMartnez left a comment

Choose a reason for hiding this comment

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

lgtm, all comments and discussions resolved.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for the fix @jfrag1 and for addressing all comments.

@Antonio-RiveroMartnez Antonio-RiveroMartnez merged commit 4caf33b into apache:master Jul 11, 2023
29 checks passed
@Antonio-RiveroMartnez Antonio-RiveroMartnez deleted the jack/dashboard-non-owner-can-add-chart-via-save-as branch July 11, 2023 15:58
@michael-s-molina michael-s-molina added the v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch label Jul 12, 2023
michael-s-molina pushed a commit that referenced this pull request Jul 26, 2023
@mistercrunch mistercrunch added 🍒 3.0.0 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Mar 8, 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 size/M v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch 🍒 3.0.0 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants