Skip to main content

getWeaverseStudioCspDirectives

getWeaverseStudioCspDirectives returns the CSP sources Weaverse Studio needs while it drives your storefront in its iframe. Merge the result into the directives you pass to Hydrogen’s createContentSecurityPolicy. Requires @weaverse/hydrogen 6.3.0 or later. createContentSecurityPolicy requires @shopify/hydrogen 2026.10.3 or later.

Import

Next.js storefronts import it from @weaverse/hydrogen/next/server (see the Next.js reference).

Signature

The shape matches Hydrogen’s ContentSecurityPolicyDirectives, where each array extends Hydrogen’s default for that directive (and replaces a 'none' default such as frame-ancestors).

Return Value

weaverseHost comes from the URL, so anyone can set it. The helper runs it through the same trust check that gates the Studio bridge script: only https:// hosts on weaverse.io or weaverse.dev (or their subdomains) are trusted, and loopback hosts only when the storefront itself runs on loopback. Without a weaverseHost, the default Studio origin https://studio.weaverse.io is used. The result works in both report-only and enforcing policies.
A self-hosted or staging Studio on another domain isn’t trusted, so the helper returns {} for it. Add that origin to your own directives if you use one.

Usage

Pilot keeps its own sources in app/weaverse/csp.ts and appends Studio’s:
app/weaverse/csp.ts
app/entry.server.tsx
Append Studio’s arrays to yours instead of assigning them. Overwriting scriptSrc with Studio’s drops your own sources, such as 'unsafe-inline', inside Studio.
Last modified on November 23, 2026