You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/02 00:25:18 UTC
(superset) branch fix/chart-query-context-access-check created (now 632f8702c4b)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a change to branch fix/chart-query-context-access-check
in repository https://gitbox.apache.org/repos/asf/superset.git
at 632f8702c4b fix(chart): require chart access for query_context-only updates
This branch includes the following new commits:
new 632f8702c4b fix(chart): require chart access for query_context-only updates
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: fix(chart): require chart access for query_context-only updates
Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch fix/chart-query-context-access-check
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 632f8702c4beda28379ce5994ac219b92cb2572b
Author: Claude Code <no...@anthropic.com>
AuthorDate: Mon Jun 1 17:24:52 2026 -0700
fix(chart): require chart access for query_context-only updates
UpdateChartCommand skips the ownership check for "query_context-only" updates
(payload == {query_context, query_context_generation:true}) so report workers
and the UI's lazy query_context backfill can run as non-owners. But it skipped
ALL authorization, so any user with can_write on Chart could rewrite the
query_context of a chart they don't own (CWE-639).
Replace the unconditional skip with security_manager.raise_for_access(chart=...)
on that path. That still permits the legitimate non-owner flows (admins, owners,
and any user with access to the chart's datasource — which includes viewers who
can render the chart and the report executor), while rejecting users who cannot
access the chart at all.
DRAFT: needs CI / manual validation that the report-execution screenshot path
(executor user) passes raise_for_access in all configurations before merge.
Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
superset/commands/chart/update.py | 14 ++++++++++--
tests/integration_tests/charts/commands_tests.py | 27 ++++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/superset/commands/chart/update.py b/superset/commands/chart/update.py
index 25ca2539a1a..f9ec3497c6a 100644
--- a/superset/commands/chart/update.py
+++ b/superset/commands/chart/update.py
@@ -112,8 +112,13 @@ class UpdateChartCommand(UpdateMixin, BaseCommand):
if not self._model:
raise ChartNotFoundError()
- # Check and update ownership; when only updating query context we ignore
- # ownership so the update can be performed by report workers
+ # Check and update ownership; when only updating query context we relax
+ # the ownership requirement so that non-owners (report workers and any
+ # viewer whose UI lazily backfills a missing query_context) can perform
+ # the update. We still require access to the chart in that case, so a
+ # user cannot rewrite the query_context of a chart they cannot access
+ # (raise_for_access permits admins, owners, and users with access to the
+ # chart's datasource).
if not is_query_context_update(self._properties):
try:
security_manager.raise_for_ownership(self._model)
@@ -126,6 +131,11 @@ class UpdateChartCommand(UpdateMixin, BaseCommand):
raise ChartForbiddenError() from ex
except ValidationError as ex:
exceptions.append(ex)
+ else:
+ try:
+ security_manager.raise_for_access(chart=self._model)
+ except SupersetSecurityException as ex:
+ raise ChartForbiddenError() from ex
# validate tags
try:
diff --git a/tests/integration_tests/charts/commands_tests.py b/tests/integration_tests/charts/commands_tests.py
index b5fa05b7264..765db4a5ea5 100644
--- a/tests/integration_tests/charts/commands_tests.py
+++ b/tests/integration_tests/charts/commands_tests.py
@@ -25,6 +25,7 @@ from flask import g # noqa: F401
from superset import db, security_manager
from superset.commands.chart.create import CreateChartCommand
from superset.commands.chart.exceptions import (
+ ChartForbiddenError,
ChartNotFoundError,
WarmUpCacheChartNotFoundError,
)
@@ -452,6 +453,32 @@ class TestChartsUpdateCommand(SupersetTestCase):
assert len(chart.owners) == 1
assert chart.owners[0] == admin
+ @patch("superset.commands.chart.update.g")
+ @patch("superset.utils.core.g")
+ @patch("superset.security.manager.g")
+ @pytest.mark.usefixtures("load_energy_table_with_slice")
+ def test_query_context_update_requires_chart_access(self, mock_sm_g, mock_g):
+ """
+ A query_context-only update relaxes the ownership requirement but must
+ still require access to the chart: a non-owner without access to the
+ chart's datasource is rejected with ChartForbiddenError.
+ """
+ chart = db.session.query(Slice).all()[0]
+ pk = chart.id
+ admin = security_manager.find_user(username="admin")
+ chart.owners = [admin]
+ db.session.commit()
+
+ # gamma has no access to the energy datasource and does not own the chart
+ gamma = security_manager.find_user(username="gamma")
+ mock_g.user = mock_sm_g.user = gamma
+ json_obj = {
+ "query_context_generation": True,
+ "query_context": json.dumps({"foo": "bar"}),
+ }
+ with pytest.raises(ChartForbiddenError):
+ UpdateChartCommand(pk, json_obj).run()
+
@patch("superset.commands.chart.update.g")
@patch("superset.utils.core.g")
@patch("superset.security.manager.g")