Host Shell Prototype · Dedicated Workers + Typed Slot Contracts

Malleable Worker Shell

A host document exposes three versioned UI slots (header-badge, sidebar-metrics, and inspector-cards) to isolated Dedicated Worker plugins. Plugins have no DOM, no storage, and no outbound network access; every extension call and UI patch passes through an explicit capability gate before the host renders plain text nodes.

Problem & Hypothesis

Running user-written or model-generated plugins inside the main window exposes cookies, storage, and arbitrary DOM mutation. Executing plugins inside networkless Dedicated and Blob URL Workers that emit typed JSON slot patches keeps apps extensible without exposing host origin state.

Confirm Signal

Valid Worker plugins populate declared slots cleanly while undeclared host:* calls, network egress under strict worker CSP (connect-src 'none'), and raw HTML/<script> patches fail closed and appear in the Capability Gate log.

Falsify Signal

Plugin authoring hits expressiveness limits when visual interactions must serialize through declarative JSON slot schemas rather than direct DOM APIs.

3 Things To Try

  1. 1. Load Built-ins & Edit Draft

    Ensure both Dedicated Workers are mounted and edit the Host Draft below to watch header-badge, sidebar-metrics, and inspector-cards recompute live.

  2. 2. Trigger Undeclared Call & XSS Patch

    Instruct link-linter.js to request undeclared host:storage or emit a <script> patch. The gate rejects both and logs the blocks below.

  3. 3. Author & Spawn Blob Worker

    Modify the JavaScript module in the Custom Plugin Editor and spawn it via new Worker(blobUrl, { type: "module" }) to extend the shell live.

Interactive Host Shell

Draft Workspace & Declared Slots

slot:header-badge · schema:badge
No header-badge patch mounted

Host Draft Document

Edits dispatch doc:updated over postMessage only to mounted Workers whose manifest declares read:doc.

Declared Slot: inspector-cards

capability: slot:inspector-cards · type: note-cards

Mount link-linter.js or a custom plugin to populate this slot.

Custom Live Plugin Editor (Blob Worker)

Source is packaged via new Blob([source], { type: "text/javascript" }) and executed inside new Worker(blobUrl, { type: "module" }) under worker-src 'self' blob:.

Idle · not spawned

Runtime & HTTP Telemetry

Wire & Capability Gate Inspector

Allowed: 0 Blocked: 0
Live Message Wire & Capability Gate Log
Waiting for Worker frames...
HTTP Response Headers & Worker CSP Enforcement

Live response headers inspected via HEAD/GET requests to /, /api/plugins, /plugins/word-metrics.js, and /plugins/link-linter.js.

Inspecting HTTP response headers...
Slot Contract Manifest & Typed Patch Schema (/api/plugins)
Loading contract schema from /api/plugins...
Malleable Worker Shell Trust Boundary Architecture Host Document with three versioned slots communicates through a central Capability Gate Broker to isolated Dedicated Worker plugins that have no DOM and no network access. HOST ORIGIN · MAIN THREAD Host Document + 3 Slots slot: header-badge (badge) slot: sidebar-metrics (stat-list) slot: inspector-cards (note-cards) DOM built via createElement + textContent (0 innerHTML) doc patch CONTRACT BOUNDARY Capability Gate Broker validatePluginManifest() Allowlisted capabilities + slot map authorizePluginCall() Blocks undeclared host:storage / dom validateSlotPatch() Typed JSON only; blocks <script> / HTML postMessage structured clone only init msg ISOLATED DEDICATED WORKERS Worker Plugins /plugins/word-metrics.js CSP: connect-src 'none' /plugins/link-linter.js CSP: connect-src 'none' blob:... (Live Custom Module) worker-src 'self' blob: No DOM · No localStorage · No window
Plugins execute in separate Dedicated Worker threads and cannot read the host DOM or storage. All cross-boundary frames pass through slot-contract.js before reaching any UI slot.
How This Is Set Up

In-Window Script Injection vs. Capability-Gated Workers

Executing user-authored and generated UI extensions inside Dedicated and Blob Workers that publish schema-validated JSON patches into host-controlled slots.

Host-thread plugin script (baseline risk)
// Extension script injected directly into host window
const script = document.createElement("script");
script.textContent = generatedPluginCode;
document.head.appendChild(script);
// Runs with ambient access to:
// - document.cookie and window.localStorage
// - fetch() using origin credentials
// - unrestricted DOM tree mutations across the page
Isolated Worker + typed slot patch (this lab)
// Isolated Worker plugin (/plugins/word-metrics.js or Blob Worker)
export const MANIFEST = {
  id: "word-metrics",
  name: "Word & Readability Metrics",
  version: "1.0.0",
  capabilities: ["slot:header-badge", "slot:sidebar-metrics", "read:doc"],
  slots: ["header-badge", "sidebar-metrics"],
};
self.postMessage({
  type: "plugin:patch",
  slotId: "header-badge",
  patch: { type: "badge", label: "Word Metrics", value: "42 words", tone: "ok" },
});
Page Markup, Slot Contract & Blob Worker Wiring

Matches public/index.html, public/lib/slot-contract.js, src/plugin-sources.ts, public/app.js, and src/worker.ts.

<!-- 1. Host Slot Mounts & Blob Editor (public/index.html) -->
<script type="module" src="/app.js"></script>
<div id="slot-header-badge" class="slot-header-mount" aria-live="polite"></div>
<div id="slot-inspector-cards" class="slot-cards-mount" aria-live="polite"></div>
<div id="slot-sidebar-metrics" class="slot-metrics-mount" aria-live="polite"></div>
<textarea id="custom-plugin-code" class="mono-editor" rows="15"></textarea>
<button type="button" id="spawn-custom-btn" class="btn btn-primary">Spawn Blob Worker</button>

// 2. Slot Registry & Restricted Capabilities (public/lib/slot-contract.js)
export const DECLARED_SLOTS = Object.freeze({
  "header-badge": Object.freeze({ id: "header-badge", allowedPatchType: "badge", capability: "slot:header-badge" }),
  "sidebar-metrics": Object.freeze({ id: "sidebar-metrics", allowedPatchType: "stat-list", capability: "slot:sidebar-metrics" }),
  "inspector-cards": Object.freeze({ id: "inspector-cards", allowedPatchType: "note-cards", capability: "slot:inspector-cards" }),
});
export const RESTRICTED_CAPABILITIES = Object.freeze(["host:storage", "host:dom", "host:network", "host:secrets"]);

// 3. Blob Worker Boot & CSP Boundaries (public/app.js + src/worker.ts)
const blob = new Blob([customCodeTextarea.value], { type: "text/javascript" });
const blobUrl = URL.createObjectURL(blob);
const worker = new Worker(blobUrl, { type: "module" });
worker.addEventListener("message", (event) => handleWorkerMessage("custom-blob", event.data));
// src/worker.ts: HOST_SHELL_CSP sets worker-src 'self' blob:;
// /plugins/*.js sets PLUGIN_WORKER_CSP: "default-src 'none'; script-src 'self'; connect-src 'none';"
Capability Gate & Slot Patch Validation Contract
// public/app.js + public/lib/slot-contract.js
const auth = authorizePluginCall({ manifest: entry.manifest, capability: rawMsg.capability });
// Denies RESTRICTED_CAPABILITIES: host:storage, host:dom, host:network, host:secrets

const check = validateSlotPatch({ slotId: rawMsg.slotId, patch: rawMsg.patch, manifest: entry.manifest });
if (check.allowed && check.sanitizedPatch) {
  slotState[rawMsg.slotId].set(pluginId, check.sanitizedPatch);
  renderSlot(rawMsg.slotId); // Renders plain DOM nodes via createElement + textContent only
}
What is removed

Injecting extension <script> tags into the host window realm or accepting unvalidated HTML fragments across plugin boundaries.

What is enforced explicitly

PLUGIN_WORKER_CSP (connect-src 'none'), manifests checked by validatePluginManifest(), explicit host:* denials, and typed DECLARED_SLOTS patches.

Platform limits tested

Worker postMessage() structured cloning adds latency for high-frequency frames, and blob: Workers require host worker-src 'self' blob: plus explicit URL.revokeObjectURL() cleanup.