Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

cleanup init code (#78675)

Jakub Chodorowicz2c7b1c9608fe
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/distortions-dom-read.ts b/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/distortions-dom-read.ts
index 7445aa3d0bf..fdb98996be5 100644
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/distortions-dom-read.ts
+++ b/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/distortions-dom-read.ts
@@ -1,3 +1,4 @@
+import { BLOCKED_TAGS } from "metabase/utils/scripts-sandbox";
import type { CustomVizPluginId } from "metabase-types/api";
// DOM scoping is custom-viz-specific: each custom-viz plugin renders inside
@@ -90,7 +91,9 @@ export function isDomNode(obj: unknown): obj is Node {
function createDecoyForNode(node: Node): Node {
switch (node.nodeType) {
case Node.ELEMENT_NODE: {
- const decoy = document.createElement(node.nodeName.toLowerCase());
+ const tagName = node.nodeName.toLowerCase();
+ const decoyTag = BLOCKED_TAGS.has(tagName) ? "div" : tagName;
+ const decoy = document.createElement(decoyTag);
decoy.setAttribute("data-plugin-sandbox-decoy", "true");
decoy.setAttribute("id", "sandbox-decoy");
return decoy;
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/index.ts b/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/index.ts
index 04a84431758..6f483dd60bf 100644
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/index.ts
+++ b/enterprise/frontend/src/metabase-enterprise/custom_viz/sandbox/index.ts
@@ -29,6 +29,7 @@ export async function createPluginSandbox(
const env = await createVirtualEnvironment(window, {
...(iframeSrc ? { iframeSrc } : {}),
+ keepAlive: false,
distortionCallback: makeDistortionCallback(pluginId),
liveTargetCallback: isLiveTarget,
endowments: Object.getOwnPropertyDescriptors({
@@ -39,6 +40,7 @@ export async function createPluginSandbox(
capturedFactory = value;
},
__METABASE_VIZ_API__: window.__METABASE_VIZ_API__,
+ frameElement: null,
}),
});
diff --git a/frontend/src/metabase/utils/scripts-sandbox/distortions-blocked-apis.ts b/frontend/src/metabase/utils/scripts-sandbox/distortions-blocked-apis.ts
index b262473dc5a..091a092de82 100644
--- a/frontend/src/metabase/utils/scripts-sandbox/distortions-blocked-apis.ts
+++ b/frontend/src/metabase/utils/scripts-sandbox/distortions-blocked-apis.ts
@@ -267,6 +267,11 @@ block(
setter(HTMLAnchorElement.prototype, "target"),
"HTMLAnchorElement.set target",
);
+block(method(HTMLFormElement.prototype, "submit"), "HTMLFormElement.submit");
+block(
+ method(HTMLFormElement.prototype, "requestSubmit"),
+ "HTMLFormElement.requestSubmit",
+);
/**
* Intentionally left out:
diff --git a/frontend/src/metabase/utils/scripts-sandbox/distortions-dom-mutate.ts b/frontend/src/metabase/utils/scripts-sandbox/distortions-dom-mutate.ts
index f5f1f287a26..5e87f64278c 100644
--- a/frontend/src/metabase/utils/scripts-sandbox/distortions-dom-mutate.ts
+++ b/frontend/src/metabase/utils/scripts-sandbox/distortions-dom-mutate.ts
@@ -71,7 +71,7 @@ export function sanitizedSetterDistortion(
};
}
-const BLOCKED_TAGS = new Set([
+export const BLOCKED_TAGS = new Set([
"script",
"iframe",
"object",
diff --git a/frontend/src/metabase/utils/scripts-sandbox/index.ts b/frontend/src/metabase/utils/scripts-sandbox/index.ts
index 6ab881019b2..f92f6c952ef 100644
--- a/frontend/src/metabase/utils/scripts-sandbox/index.ts
+++ b/frontend/src/metabase/utils/scripts-sandbox/index.ts
@@ -1,2 +1,3 @@
export { BLOCKED_NATIVE_REFS } from "./distortions-blocked-apis";
+export { BLOCKED_TAGS } from "./distortions-dom-mutate";
export { makeSandboxDistortionCallback } from "./distortions";