You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2026/06/03 22:05:47 UTC

(superset) 05/06: fix(subdirectory): 2nd-review AR-M1 + CR-M1/AR-L1 + M5 doc note

This is an automated email from the ASF dual-hosted git repository.

sadpandajoe pushed a commit to branch claude/subdirectory-helpers-tdd
in repository https://gitbox.apache.org/repos/asf/superset.git

commit bcd52ceb38de9dcb1114b6393d93ad57bdb60124
Author: Joe Li <jo...@preset.io>
AuthorDate: Tue Jun 2 19:48:14 2026 -0700

    fix(subdirectory): 2nd-review AR-M1 + CR-M1/AR-L1 + M5 doc note
    
    Three findings from the post-RF 5-lane + adversarial review pass on
    HEAD `2428f3e801`. All scoped tight; mirrors the RF-1..RF-4 commit shape.
    
    AR-M1 (`superset/views/utils.py`) — `get_explore_redirect_url` only fell
    back when `form_data.slice_id` was `None`. A non-int, non-None shape
    (`"abc"`, `[1, 2]`, `{"id": 1}`, `True`) survived into
    `CommandParameters(chart_id=...)` and 500ed at the cache write — the
    residual gap RF-1 surfaced but did not fully close. Tightened to
    `not isinstance(slice_id, int) or isinstance(slice_id, bool)`; the
    fallback path `request.args.get("slice_id", type=int) or 0` already
    handles the typed parse. Bool excluded explicitly because it is a
    subclass of `int` in Python and would otherwise become `chart_id=1`.
    
    CR-M1 ≡ AR-L1 (`superset-frontend/src/utils/navigationUtils.ts`) — the
    RF-4 comment promised the bidi formatting marks U+202A..U+202E
    (LRE/RLE/PDF/LRO/RLO) and U+2066..U+2069 (LRI/RLI/FSI/PDI), but the
    original regex character class only covered U+200E/F. WHATWG strips
    these before host parsing, but defence-in-depth — close the
    documentation/regex drift. Both review lanes independently surfaced
    this; strong signal even though not exploitable.
    
    M5 doc note (`UPDATING.md`) — `EMBEDDED_DISABLE_PERMALINK_ORIGIN_REWRITE`
    (introduced at Slice 8) was missing from the operator-facing
    UPDATING.md #39925 block. Added one paragraph clarifying default
    (`False` = rewrite on), opt-out condition (proxy forwards
    `X-Forwarded-Host` and operator wants literal backend origin), and why
    the default cannot flip.
    
    Tests added:
    - 9 jest cases in `navigationUtils.test.ts` covering each new bidi
      formatting mark routed through `openInNewTab`.
    - 1 parametrised pytest in `test_explore_redirect.py` (4 non-int
      `slice_id` shapes → 302 with `chart_id=0`); deferred to CI per the
      same docker-light `/login/` POST 404 baseline as Slices 4–8.
    
    Verification:
    - `npx jest src/utils/navigationUtils.test.ts` — 47 passed (38 prior +
      9 new bidi).
    - `SKIP=pylint,oxlint-frontend pre-commit run` — clean. pylint baseline
      carried per Slices 4–8 worktree subshell miss; oxlint native-binding
      gap is a worktree env issue, not lint findings (same baseline as
      Slices 4–8 commits).
    
    Closes: AR-M1, CR-M1, AR-L1, M5 doc nit (defers CR-M2 casefold
    disable-guard, AR-M2 docstring nit — both noted as deferred in the
    review).
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <no...@anthropic.com>
---
 UPDATING.md                                        |  2 ++
 .../src/utils/navigationUtils.test.ts              | 26 +++++++++++++++++++++
 superset-frontend/src/utils/navigationUtils.ts     | 27 +++++++++++++++-------
 superset/views/utils.py                            | 10 +++++++-
 .../views/test_explore_redirect.py                 | 27 ++++++++++++++++++++++
 5 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/UPDATING.md b/UPDATING.md
index 587538468f4..c62cd1fd89b 100644
--- a/UPDATING.md
+++ b/UPDATING.md
@@ -38,6 +38,8 @@ assists people when migrating to a new version.
 
 - **`SqlaTable.sql_url` query-string format.** `SqlaTable.sql_url` now URL-encodes `table_name` and joins it as a query parameter rather than concatenating a second `?`. Previously, with `Database.sql_url` returning `/sqllab/?dbid=<id>`, the concatenation produced `/sqllab/?dbid=<id>?table_name=<raw>` — a malformed second `?` that broke the query parser. External code that parsed the legacy `<base>?table_name=<raw>` shape now sees properly percent-encoded values (e.g. `/` → `%2F`, ` ` →  [...]
 
+- **New config flag `EMBEDDED_DISABLE_PERMALINK_ORIGIN_REWRITE` (default `False`).** Share/permalink URLs now substitute `window.location.origin` for the backend-supplied origin so a proxied or subdirectory-deployed Superset never hands the user an unreachable internal hostname. Operators whose reverse proxy correctly forwards `X-Forwarded-Host` *and* who want permalinks to carry the backend's literal origin can opt out by setting `EMBEDDED_DISABLE_PERMALINK_ORIGIN_REWRITE = True` in `su [...]
+
 ### YDB now uses a native sqlglot dialect
 
 YDB SQL parsing now relies on the dedicated [`ydb-sqlglot-plugin`](https://pypi.org/project/ydb-sqlglot-plugin/) dialect, which registers itself with sqlglot automatically. YDB users must install this plugin (e.g., via `pip install "apache-superset[ydb]"`) to avoid a `ValueError` when Superset parses YDB queries.
diff --git a/superset-frontend/src/utils/navigationUtils.test.ts b/superset-frontend/src/utils/navigationUtils.test.ts
index 30795ab3fa7..7858ca15359 100644
--- a/superset-frontend/src/utils/navigationUtils.test.ts
+++ b/superset-frontend/src/utils/navigationUtils.test.ts
@@ -154,6 +154,32 @@ describe('openInNewTab', () => {
       });
     },
   );
+
+  // CR-M1 / AR-L1 (review-fix Slice 1–8, round 2): the bidi formatting
+  // ranges U+202A..U+202E (LRE/RLE/PDF/LRO/RLO) and U+2066..U+2069
+  // (LRI/RLI/FSI/PDI) were promised by the RF-4 comment but missing from
+  // the original regex. Pin them directly so a documentation/regex drift
+  // can't reintroduce the gap.
+  test.each([
+    ['‪/foo', 'U+202A LRE'],
+    ['‫/foo', 'U+202B RLE'],
+    ['‬/foo', 'U+202C PDF'],
+    ['‭/foo', 'U+202D LRO'],
+    ['‮/foo', 'U+202E RLO'],
+    ['⁦/foo', 'U+2066 LRI'],
+    ['⁧/foo', 'U+2067 RLI'],
+    ['⁨/foo', 'U+2068 FSI'],
+    ['⁩/foo', 'U+2069 PDI'],
+  ])(
+    'refuses URL containing %s bidi formatting mark (CR-M1/AR-L1)',
+    async (unsafeUrl: string, _label: string) => {
+      await withApplicationRoot('/superset/', async () => {
+        const { openInNewTab } = await import('src/utils/navigationUtils');
+        expect(() => openInNewTab(unsafeUrl)).toThrow(/refused unsafe URL/);
+        expect(openSpy).not.toHaveBeenCalled();
+      });
+    },
+  );
 });
 
 describe('redirect', () => {
diff --git a/superset-frontend/src/utils/navigationUtils.ts b/superset-frontend/src/utils/navigationUtils.ts
index ce3d569af1a..4c72d63b8dc 100644
--- a/superset-frontend/src/utils/navigationUtils.ts
+++ b/superset-frontend/src/utils/navigationUtils.ts
@@ -75,13 +75,20 @@ const SAFE_PATH_PARSE_ORIGIN = 'http://navigation-utils.invalid';
 // protocol-relative `//host` reject from above.
 // RF-4 (review-fix Slice 1–8): URL strings containing C0/C1 controls
 // (`\t`/`\n`/`\r`/etc., DEL, U+0080..U+009F) or Unicode zero-width / bidi
-// formatting marks (U+200B..U+200F, U+2028, U+2029, U+FEFF) are rejected
-// outright. Browsers strip leading C0 controls before parsing the
-// leading-slash branch, so `\t//evil.com` would otherwise leave the
-// leading-slash check unable to see the protocol-relative `//`.
-// Defence-in-depth — no known active bypass against the current
-// allow-list, but the regex would otherwise depend on browser-specific
-// normalisation behaviour.
+// formatting marks (U+200B..U+200F, U+202A..U+202E, U+2066..U+2069,
+// U+2028, U+2029, U+FEFF) are rejected outright. Browsers strip leading
+// C0 controls before parsing the leading-slash branch, so `\t//evil.com`
+// would otherwise leave the leading-slash check unable to see the
+// protocol-relative `//`. Defence-in-depth — no known active bypass
+// against the current allow-list, but the regex would otherwise depend
+// on browser-specific normalisation behaviour.
+//
+// CR-M1 / AR-L1 (review-fix Slice 1–8, round 2): the bidi range was
+// extended to cover the explicit-direction format characters U+202A..E
+// (LRE/RLE/PDF/LRO/RLO) and U+2066..9 (LRI/RLI/FSI/PDI). WHATWG strips
+// these before parsing the host, but the RF-4 comment had promised them
+// while the regex only covered U+200E/F — closing the documentation
+// drift the multi-slice code review surfaced.
 const SAFE_NAVIGATION_URL_RE =
   /^(?:\/(?!\/)|https?:\/\/|ftp:\/\/|mailto:|tel:)/i;
 const USERINFO_BEARING_SCHEME_RE = /^(?:https?|ftp):\/\//i;
@@ -89,7 +96,11 @@ const USERINFO_BEARING_SCHEME_RE = /^(?:https?|ftp):\/\//i;
 // literal so source-file tooling (Babel parser, prettier, eslint) does
 // not have to round-trip raw bidi / zero-width / line-separator bytes.
 const FORBIDDEN_CONTROL_CHARS_RE = new RegExp(
-  '[\\x00-\\x1F\\x7F-\\x9F\\u200B-\\u200F\\u2028\\u2029\\uFEFF]',
+  '[\\x00-\\x1F\\x7F-\\x9F' +
+    '\\u200B-\\u200F' +
+    '\\u202A-\\u202E' +
+    '\\u2066-\\u2069' +
+    '\\u2028\\u2029\\uFEFF]',
 );
 
 function assertSafeNavigationUrl(url: string): string {
diff --git a/superset/views/utils.py b/superset/views/utils.py
index ce9dfcdacee..2e5b332d337 100644
--- a/superset/views/utils.py
+++ b/superset/views/utils.py
@@ -269,7 +269,15 @@ def get_explore_redirect_url() -> str | None:  # noqa: C901
         return None
 
     slice_id = parsed_form_data.get("slice_id")
-    if slice_id is None:
+    if not isinstance(slice_id, int) or isinstance(slice_id, bool):
+        # AR-M1 (review-fix Slice 1–8, round 2): residual AF-3 gap — a
+        # non-int, non-None `form_data.slice_id` (`"abc"`, `[1, 2]`, `{}`,
+        # `True`) used to survive the `is None` guard and surface as 500
+        # downstream when `CommandParameters(chart_id=...)` reached the
+        # cache write. Treat any non-int shape the same as missing and
+        # fall back to the typed query parse. `bool` is excluded because
+        # it is a subclass of `int` in Python — `True` would otherwise
+        # become `chart_id=1`.
         # AF-3: previously `int(request.args.get("slice_id", 0))` blew up on
         # non-numeric values (`?slice_id=abc`). `type=int` returns None on
         # parse failure; coerce to 0 to preserve historical default.
diff --git a/tests/integration_tests/views/test_explore_redirect.py b/tests/integration_tests/views/test_explore_redirect.py
index a03e2070335..f06de7a65f1 100644
--- a/tests/integration_tests/views/test_explore_redirect.py
+++ b/tests/integration_tests/views/test_explore_redirect.py
@@ -155,6 +155,33 @@ class TestExploreRedirect(SupersetTestCase):
         )
         assert rv.status_code == 302
 
+    @pytest.mark.usefixtures("load_energy_table_with_slice")
+    @mock.patch("superset.commands.explore.form_data.create.CreateFormDataCommand")
+    @pytest.mark.parametrize(
+        "slice_id_value",
+        ["abc", [1, 2], {"id": 1}, True],
+    )
+    def test_explore_root_arm1_slice_id_non_int(
+        self, mock_command_cls: mock.Mock, slice_id_value
+    ):
+        """AR-M1 (review-fix Slice 1–8, round 2): a non-int, non-None
+        ``form_data.slice_id`` (string, list, dict, bool) used to survive
+        the ``is None`` guard and reach ``CommandParameters(chart_id=...)``,
+        500ing downstream when the cache write tried to coerce it.
+
+        The tightened ``isinstance(slice_id, int)`` guard (excluding
+        ``bool`` because it is a subclass of ``int``) treats any non-int
+        shape the same as missing: fall back to the typed query parse
+        (or 0). Chart ID lands as the integer fallback, not the malformed
+        value.
+        """
+        mock_command_cls.return_value.run.return_value = "random_key"
+        self.login(ADMIN_USERNAME)
+        form_data = {"slice_id": slice_id_value, "datasource": "1__table"}
+        rv = self.client.get(f"/explore/?form_data={quote(json.dumps(form_data))}")
+        assert rv.status_code == 302
+        assert mock_command_cls.call_args.kwargs["chart_id"] == 0
+
     @pytest.mark.usefixtures("load_energy_table_with_slice")
     @mock.patch("superset.commands.explore.form_data.create.CreateFormDataCommand")
     def test_explore_slice_id_precedence_form_data_wins(