@decocms/blocks 7.85.2 → 7.85.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/blocks",
|
|
3
|
-
"version": "7.85.
|
|
3
|
+
"version": "7.85.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"./sdk/csp": "./src/sdk/csp.ts",
|
|
55
55
|
"./sdk/detectDevice": "./src/sdk/detectDevice.ts",
|
|
56
56
|
"./sdk/djb2": "./src/sdk/djb2.ts",
|
|
57
|
+
"./sdk/editorOrigin": "./src/sdk/editorOrigin.ts",
|
|
57
58
|
"./sdk/encoding": "./src/sdk/encoding.ts",
|
|
58
59
|
"./sdk/env": "./src/sdk/env.ts",
|
|
59
60
|
"./sdk/fetchCache": "./src/sdk/fetchCache.ts",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useEffect } from "react";
|
|
2
|
+
import { EDITOR_ORIGIN_CHECK_JS } from "../sdk/editorOrigin";
|
|
2
3
|
import { getRequestNonce } from "../sdk/nonce";
|
|
3
4
|
|
|
4
5
|
interface LiveControlsProps {
|
|
@@ -58,19 +59,13 @@ function LiveControlsScript() {
|
|
|
58
59
|
if (window.__DECO_LIVE_CONTROLS__) return;
|
|
59
60
|
window.__DECO_LIVE_CONTROLS__ = true;
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
function isTrustedOrigin(origin) {
|
|
63
|
-
return TRUSTED_ORIGINS.indexOf(origin) !== -1 ||
|
|
64
|
-
(origin.startsWith("https://") && origin.endsWith(".deco.cx")) ||
|
|
65
|
-
(origin.startsWith("https://") && origin.endsWith(".decocms.com")) ||
|
|
66
|
-
origin === window.location.origin;
|
|
67
|
-
}
|
|
62
|
+
${EDITOR_ORIGIN_CHECK_JS}
|
|
68
63
|
|
|
69
64
|
var LIVE = JSON.parse(document.getElementById("__DECO_STATE")?.textContent || "{}");
|
|
70
65
|
window.LIVE = { ...window.LIVE, ...LIVE };
|
|
71
66
|
|
|
72
67
|
window.addEventListener("message", function(event) {
|
|
73
|
-
if (!
|
|
68
|
+
if (!isTrustedEditorOrigin(event.origin)) return;
|
|
74
69
|
|
|
75
70
|
var data = event.data;
|
|
76
71
|
if (!data || typeof data !== "object") return;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline-script source defining `isTrustedEditorOrigin(origin)`: whether a
|
|
3
|
+
* postMessage sender may drive the storefront (e.g. `editor::inject`, which
|
|
4
|
+
* evals the script it carries). An exact list of deco admin and Studio
|
|
5
|
+
* origins, never a wildcard: user-written pages live on deco subdomains too
|
|
6
|
+
* (sandbox previews). Also the page itself, and, on a local dev page, other
|
|
7
|
+
* localhost ports (Studio or the admin run locally).
|
|
8
|
+
*
|
|
9
|
+
* A source string, not a function, because every consumer is a bootstrap
|
|
10
|
+
* `<script>` that runs before any bundle loads.
|
|
11
|
+
*/
|
|
12
|
+
export const EDITOR_ORIGIN_CHECK_JS = `
|
|
13
|
+
var TRUSTED_EDITOR_ORIGINS = [
|
|
14
|
+
"https://deco.cx", "https://admin.deco.cx", "https://v0-admin.deco.cx", "https://play.deco.cx",
|
|
15
|
+
"https://decocms.com", "https://admin.decocms.com", "https://studio.decocms.com", "https://studio-stg.decocms.com"
|
|
16
|
+
];
|
|
17
|
+
function isLoopbackOrigin(origin) {
|
|
18
|
+
try { return ["localhost", "127.0.0.1", "[::1]"].indexOf(new URL(origin).hostname) !== -1; }
|
|
19
|
+
catch (e) { return false; }
|
|
20
|
+
}
|
|
21
|
+
function isTrustedEditorOrigin(origin) {
|
|
22
|
+
return TRUSTED_EDITOR_ORIGINS.indexOf(origin) !== -1 ||
|
|
23
|
+
origin === window.location.origin ||
|
|
24
|
+
(isLoopbackOrigin(window.location.origin) && isLoopbackOrigin(origin));
|
|
25
|
+
}
|
|
26
|
+
`;
|