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/01 22:43:24 UTC
(superset) 01/01: fix(deck.gl): strip all JS-executed form_data keys when JS controls are off
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch fix/deckgl-js-control-form-data-stripping
in repository https://gitbox.apache.org/repos/asf/superset.git
commit c7178f71689bd9f116c552382a4113a7150aeded
Author: Claude Code <no...@anthropic.com>
AuthorDate: Mon Jun 1 15:42:56 2026 -0700
fix(deck.gl): strip all JS-executed form_data keys when JS controls are off
The deck.gl charts execute several form_data fields as JavaScript at render
time via the frontend sandboxedEval helper. The backend strips these keys from
form_data when ENABLE_JAVASCRIPT_CONTROLS is disabled (the default), but the
strip list only covered js_tooltip, js_onclick_href and js_data_mutator.
The Geojson layer also evaluates label_javascript_config_generator and
icon_javascript_config_generator, which were not in the strip list, so those
two fields were preserved in form_data even with the flag disabled.
Add both keys to the strip list and centralize the JS-executed keys in a named
constant kept in sync with the sandboxedEval call sites. Add unit tests
asserting every JS-executed key is rejected when the flag is off.
Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
superset/views/utils.py | 15 ++++++++++-
tests/unit_tests/views/test_utils.py | 48 ++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/superset/views/utils.py b/superset/views/utils.py
index 8d8f1170285..a667cf4eea2 100644
--- a/superset/views/utils.py
+++ b/superset/views/utils.py
@@ -58,9 +58,22 @@ from superset.viz import BaseViz
logger = logging.getLogger(__name__)
stats_logger = app.config["STATS_LOGGER"]
+# Form-data keys whose values are executed as JavaScript at render time by the
+# deck.gl charts (via the frontend ``sandboxedEval`` helper). These are stripped
+# from incoming form_data unless the ``ENABLE_JAVASCRIPT_CONTROLS`` feature flag
+# is enabled. Keep this list in sync with every ``sandboxedEval(fd.<key>)`` call
+# site in the deck.gl plugins.
+JS_CONTROL_FORM_DATA_KEYS: list[str] = [
+ "js_tooltip",
+ "js_onclick_href",
+ "js_data_mutator",
+ "label_javascript_config_generator",
+ "icon_javascript_config_generator",
+]
+
REJECTED_FORM_DATA_KEYS: list[str] = []
if not feature_flag_manager.is_feature_enabled("ENABLE_JAVASCRIPT_CONTROLS"):
- REJECTED_FORM_DATA_KEYS = ["js_tooltip", "js_onclick_href", "js_data_mutator"]
+ REJECTED_FORM_DATA_KEYS = list(JS_CONTROL_FORM_DATA_KEYS)
def redirect_to_login(next_target: str | None = None) -> FlaskResponse:
diff --git a/tests/unit_tests/views/test_utils.py b/tests/unit_tests/views/test_utils.py
new file mode 100644
index 00000000000..d4d70f79488
--- /dev/null
+++ b/tests/unit_tests/views/test_utils.py
@@ -0,0 +1,48 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Tests for superset.views.utils module"""
+
+from superset.views.utils import (
+ get_form_data,
+ JS_CONTROL_FORM_DATA_KEYS,
+ REJECTED_FORM_DATA_KEYS,
+)
+
+
+def test_rejected_form_data_keys_cover_all_js_control_keys() -> None:
+ """
+ With ENABLE_JAVASCRIPT_CONTROLS disabled (the default), every form_data key
+ that is later executed as JavaScript by the deck.gl charts must be rejected.
+
+ This guards against a new ``sandboxedEval(fd.<key>)`` call site being added
+ without also adding its key to the strip list.
+ """
+ # The test app keeps ENABLE_JAVASCRIPT_CONTROLS at its default (off).
+ assert set(JS_CONTROL_FORM_DATA_KEYS) <= set(REJECTED_FORM_DATA_KEYS)
+
+
+def test_get_form_data_strips_js_control_keys() -> None:
+ """get_form_data drops all JS-executed keys when the flag is disabled."""
+ initial_form_data = {key: "data => data" for key in JS_CONTROL_FORM_DATA_KEYS}
+ initial_form_data["viz_type"] = "deck_geojson"
+
+ form_data, _ = get_form_data(initial_form_data=initial_form_data)
+
+ for key in JS_CONTROL_FORM_DATA_KEYS:
+ assert key not in form_data
+ # Non-JS keys are preserved.
+ assert form_data["viz_type"] == "deck_geojson"