← Blog

postMessage origin validation vulnerabilities in Claude MCP skill dashboards and OAuth popups — SA-SKL-POSTMESSAGE

The window.postMessage() API enables cross-origin communication between browser windows, iframes, and popups. MCP skill dashboards that embed third-party frames, integrate OAuth popup flows, or use widget embeds rely on postMessage — and each of these integration points is an authentication boundary. SA-SKL-POSTMESSAGE covers four origin validation failures: wildcard targetOrigin, missing event.origin check in message listeners, opener postMessage OAuth token leak, and MessageChannel port forwarding without authentication.

By SkillAudit  |  6 Nov 2026

Why postMessage is a high-value attack surface in MCP skills

postMessage bypasses the same-origin policy by design — it is the standard mechanism for cross-origin communication in browsers. But this means that any page on the internet can post a message to your skill's window if your skill has a message event listener that does not validate the sender's origin. Conversely, if your skill posts a message with a wildcard targetOrigin, any page that holds a reference to your window (via window.opener, iframe.contentWindow, or a shared BroadcastChannel) will receive the message. MCP skill dashboards that embed third-party report frames, skill output iframes, or OAuth return popups are especially exposed because they deliberately open cross-origin communication channels as a product feature — and those channels must be guarded at both ends.

SA-SKL-POSTMESSAGE in scope: POSTMESSAGE-001 (wildcard targetOrigin sends tokens to any page), POSTMESSAGE-002 (missing event.origin check in message listener), POSTMESSAGE-003 (opener.postMessage OAuth token leak), POSTMESSAGE-004 (MessageChannel port forwarding without authentication). Each pattern includes SkillAudit detection rules and correct fixes.

POSTMESSAGE-001 — Wildcard targetOrigin sends auth tokens to any page

The second argument to window.postMessage(data, targetOrigin) specifies which origin is allowed to receive the message. When this argument is '*', any page — including attacker-controlled pages that hold a reference to your window — receives the message. If the data contains an authentication token, session ID, or sensitive configuration, the attacker captures it. MCP skill dashboards that embed a third-party analytics or reporting iframe and communicate token data back to it are a common case: the developer uses postMessage(token, '*') for convenience, not realizing that any other iframe on the page also receives the message. The fix is to always specify the exact expected origin as the targetOrigin argument, never use '*' for messages containing sensitive data.

// VULNERABLE — wildcard targetOrigin; any page receives the token
// Skill dashboard embeds a third-party analytics iframe and passes auth context:
function sendTokenToAnalyticsFrame(token: string) {
  const analyticsFrame = document.getElementById('analytics-frame') as HTMLIFrameElement;
  // Any page holding a reference to this window receives the token
  // If the page is embedded in an attacker iframe, attacker captures token
  analyticsFrame.contentWindow?.postMessage(
    { type: 'AUTH_TOKEN', token },
    '*'  // Wildcard — sends to ANY origin
  );
}

// Also vulnerable: popup sends token back to opener with wildcard
// In OAuth popup return page:
window.opener?.postMessage({ type: 'OAUTH_TOKEN', token: extractTokenFromUrl() }, '*');
// FIXED — specify exact expected origin as targetOrigin
const DASHBOARD_ORIGIN = 'https://app.skillaudit.dev';
const ANALYTICS_FRAME_ORIGIN = 'https://analytics.skillaudit.dev';

function sendTokenToAnalyticsFrame(token: string) {
  const analyticsFrame = document.getElementById('analytics-frame') as HTMLIFrameElement;
  // Only analyticsFrame pages at ANALYTICS_FRAME_ORIGIN receive the message
  // A malicious page at evil.com that holds a reference to analyticsFrame's window
  // will NOT receive the message — browser silently drops it
  analyticsFrame.contentWindow?.postMessage(
    { type: 'AUTH_TOKEN', token },
    ANALYTICS_FRAME_ORIGIN  // Exact origin — not '*'
  );
}

// OAuth popup return page — sends only to the specific expected parent origin:
window.opener?.postMessage(
  { type: 'OAUTH_TOKEN', token: extractTokenFromUrl() },
  DASHBOARD_ORIGIN  // Only the app.skillaudit.dev dashboard receives the token
);
CRITICAL
SA-SKL-POSTMESSAGE-001 — Calls to window.postMessage(data, '*') that include authentication tokens, session IDs, or sensitive configuration send that data to any page holding a reference to the target window, including attacker-controlled pages; fix by always specifying the exact expected receiver origin as the targetOrigin argument. Detection: SkillAudit flags postMessage() calls where the second argument is the string literal '*' and the first argument contains keys named token, auth, session, key, or secret.

POSTMESSAGE-002 — Missing event.origin check in message listener accepts messages from any page

A window.addEventListener('message', handler) listener receives messages from every origin — not just your expected partner. If the handler processes messages without first checking event.origin against an allowlist of trusted origins, any page on the internet can post a message that the handler processes as legitimate. This is exploitable when the handler performs privileged actions based on message content: loading a URL into a frame, updating authentication state, triggering a mutation, or executing a configuration change. The attacker embeds the skill dashboard in a hidden iframe (if the skill's X-Frame-Options allows it), or simply opens a new window to the dashboard URL, and posts a crafted message that triggers the privileged action.

// VULNERABLE — message listener processes messages without checking event.origin
window.addEventListener('message', (event) => {
  // No origin check — attacker at evil.com can post this message
  if (event.data.type === 'LOAD_CONFIG') {
    // Attacker posts: { type: 'LOAD_CONFIG', config: { apiEndpoint: 'https://evil.com/steal' } }
    applyConfig(event.data.config);
  }
  if (event.data.type === 'AUTH_COMPLETE') {
    // Attacker posts: { type: 'AUTH_COMPLETE', userId: 'admin', role: 'superadmin' }
    setAuthState(event.data.userId, event.data.role);
  }
});
// FIXED — strict event.origin allowlist before processing any message
const TRUSTED_ORIGINS = new Set([
  'https://app.skillaudit.dev',
  'https://analytics.skillaudit.dev',
  'https://github.com', // If using GitHub OAuth popup
]);

window.addEventListener('message', (event) => {
  // ALWAYS check origin before processing any message
  if (!TRUSTED_ORIGINS.has(event.origin)) {
    // Log unexpected origins for security monitoring, then ignore
    console.warn('postMessage from untrusted origin:', event.origin);
    return;
  }

  // Also validate message structure to prevent prototype pollution
  if (!event.data || typeof event.data !== 'object' || typeof event.data.type !== 'string') {
    return;
  }

  if (event.data.type === 'LOAD_CONFIG') {
    // Safe to process — origin verified as trusted
    applyConfig(event.data.config);
  }
  if (event.data.type === 'AUTH_COMPLETE') {
    setAuthState(event.data.userId, event.data.role);
  }
});
HIGH
SA-SKL-POSTMESSAGE-002 — Message event listeners that process messages without first validating event.origin against a trusted-origin allowlist allow any page on the internet to trigger privileged actions in the skill dashboard by posting a crafted message; fix by checking event.origin against an explicit allowlist at the top of every message handler and returning immediately for any untrusted origin. Detection: SkillAudit flags addEventListener('message', handler) where the handler function body does not contain an event.origin check before any branch that mutates application state or makes API calls.

POSTMESSAGE-003 — window.opener.postMessage leaks OAuth token to any opener

The OAuth popup pattern is common in MCP skill dashboards: clicking "Connect GitHub" opens a popup window that completes the OAuth flow, then sends the resulting token back to the parent window via window.opener.postMessage(). The vulnerability is that window.opener refers to whichever window opened the popup — and if the popup was opened from a page that is itself framed by an attacker (or if the attacker directly opened the popup via JavaScript), window.opener is the attacker's window. The token is posted directly to the attacker. The fix is to specify the exact expected parent origin as the targetOrigin for all window.opener.postMessage() calls, and to close the opener reference immediately after posting by setting window.opener = null.

// VULNERABLE — OAuth popup posts token to window.opener without origin restriction
// OAuth callback page (e.g., /oauth/callback?code=xxx&state=yyy):
window.addEventListener('DOMContentLoaded', () => {
  const params = new URLSearchParams(window.location.search);
  const code = params.get('code');
  const state = params.get('state');

  // Exchange code for token... (server-side)
  fetch('/api/oauth/exchange', { method: 'POST', body: JSON.stringify({ code, state }) })
    .then(r => r.json())
    .then(({ token }) => {
      // Posts token to whoever opened this popup — attacker can open it too
      window.opener?.postMessage({ type: 'OAUTH_COMPLETE', token }, '*');
      window.close();
    });
});
// FIXED — verify state parameter encodes expected parent origin; specify exact targetOrigin
// When initiating OAuth, encode the parent origin in the state parameter:
function initiateOAuth() {
  const state = btoa(JSON.stringify({
    nonce: crypto.randomUUID(),
    parentOrigin: window.location.origin, // e.g., 'https://app.skillaudit.dev'
    // Server verifies this nonce when receiving the callback
  }));
  const authUrl = `https://github.com/login/oauth/authorize?client_id=...&state=${state}`;
  window.open(authUrl, 'oauth-popup', 'width=600,height=700');
}

// In the OAuth callback page:
window.addEventListener('DOMContentLoaded', () => {
  const params = new URLSearchParams(window.location.search);
  const code = params.get('code');
  const rawState = params.get('state');

  let parentOrigin: string;
  try {
    const stateObj = JSON.parse(atob(rawState ?? ''));
    parentOrigin = stateObj.parentOrigin;
    // Validate parentOrigin is one of your allowed app origins
    if (!['https://app.skillaudit.dev'].includes(parentOrigin)) {
      throw new Error('Invalid parent origin in state');
    }
  } catch {
    // Invalid state — do not post anything
    window.close();
    return;
  }

  fetch('/api/oauth/exchange', { method: 'POST', body: JSON.stringify({ code, rawState }) })
    .then(r => r.json())
    .then(({ token }) => {
      // Specific targetOrigin — only your app receives the token
      window.opener?.postMessage({ type: 'OAUTH_COMPLETE', token }, parentOrigin);
      window.opener = null; // Sever opener reference immediately
      window.close();
    });
});
HIGH
SA-SKL-POSTMESSAGE-003 — OAuth popup callback pages that call window.opener.postMessage(token, '*') send the OAuth token to any window that opened the popup — including attacker-controlled windows; fix by encoding the expected parent origin in the OAuth state parameter, validating it on return, and specifying it as the targetOrigin argument to prevent token delivery to unintended windows. Detection: SkillAudit flags window.opener?.postMessage( or window.opener.postMessage( calls on OAuth callback URL patterns where the second argument is '*' rather than a specific origin string.

POSTMESSAGE-004 — MessageChannel port forwarded to child frame without authentication

The MessageChannel API creates a pair of ports for direct bidirectional communication. A skill dashboard may create a channel and pass one port to an embedded child frame via postMessage — the child frame then uses that port to communicate back to the parent without additional origin checks (because the channel is already established). The vulnerability is that if the child frame is a user-controllable URL (e.g., a skill output preview rendered at an attacker-controlled URL), the frame receives the MessageChannel port and can use it to send authenticated commands to the parent dashboard. The fix is to only pass MessageChannel ports to child frames at known, allowlisted origins, and to validate the message type and content on every message received on the port.

// VULNERABLE — MessageChannel port passed to any-URL child frame; no auth on port messages
function embedSkillPreview(previewUrl: string) {
  const iframe = document.createElement('iframe');
  iframe.src = previewUrl; // User-controllable: attacker supplies https://evil.com
  document.body.appendChild(iframe);

  const channel = new MessageChannel();
  // Port 1 kept by parent; Port 2 sent to iframe
  iframe.contentWindow?.postMessage({ type: 'INIT_CHANNEL' }, '*', [channel.port2]);

  channel.port1.onmessage = (event) => {
    // Attacker at evil.com sends: { type: 'NAVIGATE', url: '/admin/delete-all' }
    // No origin check possible on MessageChannel port messages (event.origin is '')
    if (event.data.type === 'NAVIGATE') {
      window.location.href = event.data.url; // Attacker controls navigation target
    }
    if (event.data.type === 'API_CALL') {
      fetch(event.data.endpoint, { credentials: 'include' }); // CSRF via port
    }
  };
}
// FIXED — only pass port to frames at allowlisted origins; validate all port messages
const PREVIEW_FRAME_ORIGINS = new Set([
  'https://preview.skillaudit.dev',
  'https://sandbox.skillaudit.dev',
]);

function embedSkillPreview(previewUrl: string) {
  // Validate preview URL is on an allowlisted origin before creating iframe
  let parsed: URL;
  try {
    parsed = new URL(previewUrl);
  } catch {
    throw new Error('Invalid preview URL');
  }
  if (!PREVIEW_FRAME_ORIGINS.has(parsed.origin)) {
    throw new Error('Preview URL origin not in allowlist');
  }

  const iframe = document.createElement('iframe');
  iframe.src = previewUrl;
  document.body.appendChild(iframe);

  const channel = new MessageChannel();
  // Specify exact targetOrigin when passing the port — only that origin receives it
  iframe.contentWindow?.postMessage(
    { type: 'INIT_CHANNEL' },
    parsed.origin, // Exact origin, not '*'
    [channel.port2]
  );

  channel.port1.onmessage = (event) => {
    // Validate message structure rigorously — MessageChannel event.origin is ''
    // so origin cannot be re-verified here; allowlist was enforced at port creation time
    if (typeof event.data !== 'object' || typeof event.data.type !== 'string') return;

    // Only allow a strict allowlist of message types from the port
    const ALLOWED_PORT_MESSAGE_TYPES = new Set(['RESIZE', 'LOADED', 'ERROR']);
    if (!ALLOWED_PORT_MESSAGE_TYPES.has(event.data.type)) {
      console.warn('Unexpected message type on preview port:', event.data.type);
      return;
    }
    // Handle only allowed types
    if (event.data.type === 'RESIZE') {
      iframe.style.height = `${Math.min(Number(event.data.height) || 0, 2000)}px`;
    }
  };
}
MEDIUM
SA-SKL-POSTMESSAGE-004 — MessageChannel ports passed to child frames at attacker-controllable URLs give the attacker an authenticated communication channel to the parent dashboard — the port's onmessage handler cannot re-check origin (it is always empty string ''), so origin validation must happen when the port is created and assigned; fix by validating the frame URL against an origin allowlist before creating the channel, by specifying the exact origin as targetOrigin when passing the port, and by restricting the port message handler to an explicit allowlist of safe message types. Detection: SkillAudit flags new MessageChannel() patterns where the port-2 postMessage call uses '*' as targetOrigin, or where the port-1 message handler accepts NAVIGATE, API_CALL, or similar privileged message types without validating the frame's origin at channel creation time.