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
@weaverse/hydrogen/next/server (see the Next.js reference).
Signature
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 inapp/weaverse/csp.ts and appends Studio’s:
app/weaverse/csp.ts
app/entry.server.tsx
Related
- Content Security Policy: full setup, third-party sources and rollout
- Preview Errors: Studio connection problems