Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(scene-studio): open a #file= linked scene without its object scripts

nirholas2b6a2e1a9efa
diff --git a/src/scene-studio/README.md b/src/scene-studio/README.md
index 50e874ed1..b79c4f266 100644
--- a/src/scene-studio/README.md
+++ b/src/scene-studio/README.md
@@ -35,6 +35,7 @@ src/scene-studio/
│ adds a parsed GLB through the undo-able AddObjectCommand path
├── actions.js Layered action bar: Import from Forge, Export presets, Share
├── empty-state.js First-run overlay over the empty grid, retires on first object
+├── remote-scene.js Strips scripts and history from a scene opened by #file= link
├── toolbar-a11y.js Accessible names for the icon-only controls: the transform
│ gizmos (plus pressed state) and the animation transport
├── studio.css three.ws chrome overrides (vendor css/main.css is untouched)
@@ -79,7 +80,11 @@ the browser console.
scene, and attaches a player script that drives an `AnimationMixer` so the
clip plays in the timeline and records through Render, Video.
- `/scene#file=<url>` (upstream behavior) loads a serialized editor JSON scene
- after a confirmation prompt.
+ after a confirmation prompt. Unlike upstream, the linked scene's object
+ scripts and undo history are dropped ([remote-scene.js](remote-scene.js)):
+ scripts are compiled with `new Function` on Play, so keeping them would let
+ any link run code on the three.ws origin as the viewer. A scene you trust
+ keeps its scripts when opened through File, Import.
### Action bar
diff --git a/src/scene-studio/main.js b/src/scene-studio/main.js
index 52d0864b8..bfac90d57 100644
--- a/src/scene-studio/main.js
+++ b/src/scene-studio/main.js
@@ -31,7 +31,8 @@ import { addGltfBufferToScene as sharedAddGltfBufferToScene } from './loader.js'
import { mountStudioActions } from './actions.js';
import { mountEmptyState } from './empty-state.js';
import { enhanceAnimationA11y, enhanceToolbarA11y } from './toolbar-a11y.js';
-import { toastError } from '../shared/toast.js';
+import { toast, toastError } from '../shared/toast.js';
+import { sanitizeRemoteScene } from './remote-scene.js';
window.URL = window.URL || window.webkitURL;
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
@@ -290,8 +291,15 @@ if (hash.slice(1, 6) === 'file=') {
const loader = new THREE.FileLoader();
loader.crossOrigin = '';
loader.load(file, function (text) {
+ const { scene, removedScripts } = sanitizeRemoteScene(JSON.parse(text));
editor.clear();
- editor.fromJSON(JSON.parse(text));
+ editor.fromJSON(scene);
+ if (removedScripts > 0) {
+ toast(
+ `Opened the linked scene without its ${removedScripts} script${removedScripts === 1 ? '' : 's'}. Scripts in a linked scene could run as you on three.ws, so they only load from a file you import yourself (File, Import).`,
+ { duration: 9000 },
+ );
+ }
});
isLoadingFromHash = true;
diff --git a/src/scene-studio/remote-scene.js b/src/scene-studio/remote-scene.js
new file mode 100644
index 000000000..984802655
--- /dev/null
+++ b/src/scene-studio/remote-scene.js
@@ -0,0 +1,37 @@
+// A scene opened from a `#file=<url>` deep link is authored by whoever controls
+// that URL, not by the person looking at /scene. Its object scripts are compiled
+// with `new Function` when Play is pressed (vendor/js/libs/app.js), so keeping
+// them would let any link run arbitrary JavaScript on the three.ws origin, with
+// the viewer's session, after one generic "unsaved data will be lost" prompt.
+//
+// The geometry, materials, lights and camera are kept. Scripts and the undo
+// history (whose AddScript / SetScriptValue commands would restore the same
+// source on redo) are dropped. A scene the user trusts can still be opened with
+// its scripts through File, Import, which reads a file they chose themselves.
+
+/**
+ * Count the object scripts in a serialized editor scene.
+ * @param {unknown} scripts
+ * @returns {number}
+ */
+export function countSceneScripts(scripts) {
+ if (!scripts || typeof scripts !== 'object') return 0;
+ let n = 0;
+ for (const list of Object.values(scripts)) {
+ if (Array.isArray(list)) n += list.length;
+ }
+ return n;
+}
+
+/**
+ * Strip executable content from a scene loaded from a remote URL.
+ * @param {Record<string, unknown>} json parsed editor JSON (`editor.toJSON()` shape)
+ * @returns {{ scene: Record<string, unknown>, removedScripts: number }}
+ */
+export function sanitizeRemoteScene(json) {
+ const removedScripts = countSceneScripts(json?.scripts);
+ const scene = { ...(json || {}) };
+ delete scene.history;
+ scene.scripts = {};
+ return { scene, removedScripts };
+}
diff --git a/tests/scene-studio-remote-scene.test.js b/tests/scene-studio-remote-scene.test.js
new file mode 100644
index 000000000..bc977ca56
--- /dev/null
+++ b/tests/scene-studio-remote-scene.test.js
@@ -0,0 +1,48 @@
+import { describe, expect, it } from 'vitest';
+
+import { countSceneScripts, sanitizeRemoteScene } from '../src/scene-studio/remote-scene.js';
+
+const appJson = () => ({
+ metadata: { type: 'App' },
+ project: { shadows: true },
+ camera: { object: { uuid: 'cam' } },
+ scene: { object: { uuid: 'scene' } },
+ scripts: {
+ 'obj-a': [{ name: 'steal', source: 'fetch("/api/wallet/withdraw", { method: "POST" })' }],
+ 'obj-b': [{ name: 'a', source: '1' }, { name: 'b', source: '2' }],
+ },
+ history: {
+ undos: [{ type: 'AddScriptCommand', id: 1, name: 'Add Script', script: { source: 'alert(1)' } }],
+ redos: [],
+ },
+});
+
+describe('sanitizeRemoteScene', () => {
+ it('drops every script and the history that could restore them', () => {
+ const { scene, removedScripts } = sanitizeRemoteScene(appJson());
+ expect(removedScripts).toBe(3);
+ expect(scene.scripts).toEqual({});
+ expect(scene).not.toHaveProperty('history');
+ });
+
+ it('keeps the scene content the editor needs to render', () => {
+ const { scene } = sanitizeRemoteScene(appJson());
+ expect(scene.camera).toEqual({ object: { uuid: 'cam' } });
+ expect(scene.scene).toEqual({ object: { uuid: 'scene' } });
+ expect(scene.project).toEqual({ shadows: true });
+ });
+
+ it('does not mutate the parsed input', () => {
+ const input = appJson();
+ sanitizeRemoteScene(input);
+ expect(countSceneScripts(input.scripts)).toBe(3);
+ expect(input.history.undos).toHaveLength(1);
+ });
+
+ it('handles a scene with no scripts or a malformed scripts map', () => {
+ expect(sanitizeRemoteScene({ scene: {} }).removedScripts).toBe(0);
+ expect(sanitizeRemoteScene({ scripts: 'nope' }).removedScripts).toBe(0);
+ expect(sanitizeRemoteScene({ scripts: { x: 'not-a-list' } }).removedScripts).toBe(0);
+ expect(sanitizeRemoteScene(null).scene.scripts).toEqual({});
+ });
+});