Fix: Add wildcard support for all Hygraph Studio domains#8
Merged
Conversation
- Update default allowedOrigins to use wildcards (*.hygraph.com, *.hygraph.dev) - Fixes iframe communication issues with regional Studio domains - Supports custom Hygraph Studio deployments out of the box - Adds localhost:* wildcard for flexible local development This resolves the issue where the SDK would reject postMessage events from Studio instances running on regional or custom domains, causing the preview integration to fail silently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The SDK's default
allowedOriginslist was too restrictive, containing only:https://app.hygraph.comhttp://localhost:3000This caused the SDK to reject postMessage events from Studio instances running on:
https://studio-eu-central-1-shared-euc1-02.hygraph.com)*.hygraph.dev)Users experienced silent failures where the preview integration wouldn't work in the Studio iframe, forcing them to manually configure
allowedOriginsor usestudioUrl- neither of which should be necessary for iframe mode.Solution
Updated the default
allowedOriginsto use wildcard patterns (already supported by the MessageBridge):What This Fixes
✅ Works with regional Studio deployments:
https://app.hygraph.com✓https://studio-eu-central-1-shared-euc1-02.hygraph.com✓https://eu.app.hygraph.com✓✅ Works with all Hygraph environments:
*.hygraph.com*.hygraph.dev✅ Works with any localhost port:
http://localhost:3000✓http://localhost:4500✓http://localhost:8080✓Technical Details
The wildcard matching logic was already implemented in
MessageBridge.ts:155-165. This PR simply updates the default values to leverage that existing functionality.The pattern
https://*.hygraph.comis converted to regex^https://.*.hygraph.com$and matches any subdomain.Security
The
allowedOriginsvalidation remains in place to prevent malicious sites from sending fake postMessage events. The wildcards are scoped to Hygraph-owned domains only.Breaking Changes
None. This is purely additive and makes the SDK work in more scenarios out of the box.
Testing
Type: Bug Fix
Version: Should be patch bump (
1.0.3→1.0.4)