Skip to content

Legacy explore save: chart is committed before the dashboard permission check, and invalid save_to_dashboard_id returns 500 #46324

Closed

Description

@mant-raj

Bug description

Bug description

In superset/views/core.py, Superset.save_or_overwrite_slice creates or overwrites the chart and calls db.session.commit() BEFORE it validates the dashboard it should be added to:

  1. The chart is created/updated and committed (ChartDAO.create / ChartDAO.update + db.session.commit()).
  2. Only afterwards is save_to_dashboard_id / new_dashboard_name handled, including the permission checks (security_manager.is_editor(dash), can_access("can_write", "Dashboard")).

If the dashboard check fails, the request returns 403 ("You don't have the rights to alter this dashboard"), but the chart has already been saved or overwritten. The operation is not atomic.

Additionally, int(save_to_dashboard_id) and .one() are unguarded: a non-numeric value raises ValueError, and a nonexistent dashboard id raises NoResultFound. Both return a 500 instead of a 400/404, and again happen after the chart was committed.

Steps to reproduce:

  1. Log in as a user who can create charts but cannot edit dashboard X.
  2. Send a request to the legacy explore endpoint with action=saveas, a slice_name, valid form_data, and save_to_dashboard_id=<id of dashboard X>.
  3. Observe the 403 response.
  4. Check the chart list: the new chart exists despite the 403.
  5. Repeat with save_to_dashboard_id=abc or a nonexistent id: observe a 500 and a saved chart.

Expected behavior: dashboard id parsing and permission checks happen before any chart is committed. On failure, nothing is persisted, and invalid or nonexistent ids return 400/404.

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.11

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions