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/16 00:04:57 UTC
(superset) branch claude/subdirectory-helpers-tdd updated: fix(deployment): harden app-root path validation and pin trailing-slash dedupe
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
The following commit(s) were added to refs/heads/claude/subdirectory-helpers-tdd by this push:
new f0bf63eb94c fix(deployment): harden app-root path validation and pin trailing-slash dedupe
f0bf63eb94c is described below
commit f0bf63eb94c36fd1452c1f3ec2a019efb151da72
Author: Joe Li <jo...@preset.io>
AuthorDate: Mon Jun 15 17:04:37 2026 -0700
fix(deployment): harden app-root path validation and pin trailing-slash dedupe
F1: tighten APP_ROOT_PATH_RE so each segment must begin with a non-dot
character, so traversal-style roots (/app/.., /legit/../etc, /app/., /..)
degrade to root deployment instead of passing validation and being
browser-normalized away from subdir containment. Dots inside a segment
(/foo.bar) remain allowed.
F5: pin the trailing-slash appRoot normalisation in SupersetClientClass
(appRoot.replace(/\/$/,'')) covering both the //foo double-slash and the
failed dedupe of a pre-prefixed endpoint it caused.
Co-Authored-By: Claude Opus 4.8 (1M context) <no...@anthropic.com>
---
.../connection/SupersetClientAppRootContract.test.ts | 20 ++++++++++++++++++++
superset-frontend/src/utils/getBootstrapData.test.ts | 2 ++
superset-frontend/src/utils/getBootstrapData.ts | 7 ++++++-
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientAppRootContract.test.ts b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientAppRootContract.test.ts
index 3b24f5e54a5..d351c4f31a4 100644
--- a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientAppRootContract.test.ts
+++ b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientAppRootContract.test.ts
@@ -42,6 +42,26 @@ describe('SupersetClient applies the application root exactly once', () => {
);
});
+ // A trailing slash on the configured appRoot is stripped at construction
+ // (SupersetClientClass `appRoot.replace(/\/$/, '')`). Without it, a root of
+ // '/superset/' produced 'https://host/superset//foo', and the dedupe block's
+ // `startsWith('/superset//')` check silently failed to dedupe a pre-prefixed
+ // endpoint. This pins both behaviours against regression.
+ test('trailing-slash appRoot is normalised to a single root segment', () => {
+ const client = new SupersetClientClass({
+ protocol: 'https:',
+ host: 'config_host',
+ appRoot: '/superset/',
+ });
+ expect(client.getUrl({ endpoint: '/api/v1/chart' })).toBe(
+ 'https://config_host/superset/api/v1/chart',
+ );
+ // and a pre-prefixed endpoint is still deduped, not doubled
+ expect(client.getUrl({ endpoint: '/superset/api/v1/chart' })).toBe(
+ 'https://config_host/superset/api/v1/chart',
+ );
+ });
+
// Runtime safety net: if a caller pre-prefixes the endpoint (e.g. by wrapping
// with ensureAppRoot before calling), getUrl strips the duplicate. The L2
// static invariant still flags the pattern at the call site — this guards
diff --git a/superset-frontend/src/utils/getBootstrapData.test.ts b/superset-frontend/src/utils/getBootstrapData.test.ts
index 317880e44e1..2fc3bc4134c 100644
--- a/superset-frontend/src/utils/getBootstrapData.test.ts
+++ b/superset-frontend/src/utils/getBootstrapData.test.ts
@@ -115,6 +115,8 @@ describe('getBootstrapData and helpers', () => {
['protocol-relative URL', '//evil.example.com/app/'],
['absolute URL', 'https://evil.example.com/app/'],
['embedded quote', "/my'app/"],
+ ['path traversal', '/app/..'],
+ ['double-dot segment', '/legit/../etc'],
])(
'should degrade a non-path application_root to root deployment (%s)',
async (_label, applicationRootValue) => {
diff --git a/superset-frontend/src/utils/getBootstrapData.ts b/superset-frontend/src/utils/getBootstrapData.ts
index 79a4e80bcdc..eaead284545 100644
--- a/superset-frontend/src/utils/getBootstrapData.ts
+++ b/superset-frontend/src/utils/getBootstrapData.ts
@@ -43,7 +43,12 @@ const normalizePathWithFallback = (
// history.pushState in navigationUtils), so enforce the documented
// "/segment(/segment)*" shape at the source: a value that doesn't conform
// degrades to a root deployment rather than reaching those sinks.
-const APP_ROOT_PATH_RE = /^(?:\/[\w~.%-]+)*$/;
+// Each segment must begin with a non-dot character so a "." or ".." segment
+// (e.g. "/app/..") is rejected — otherwise browser path normalization would
+// collapse `ensureAppRoot('/foo')` → `/app/../foo` → `/foo`, silently
+// defeating subdirectory containment. Dots are still allowed inside a
+// segment (e.g. "/foo.bar").
+const APP_ROOT_PATH_RE = /^(?:\/[\w~%-]+(?:\.[\w~%-]+)*)*$/;
const sanitizeAppRoot = (root: string): string =>
APP_ROOT_PATH_RE.test(root) ? root : '';