forked from Budibase/budibase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/pick-relationship-fields
- Loading branch information
Showing
8 changed files
with
186 additions
and
105 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
43 changes: 43 additions & 0 deletions
43
packages/client/src/components/context/EmbedProvider.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script> | ||
import Provider from "./Provider.svelte" | ||
import { onMount } from "svelte" | ||
let data = {} | ||
function extractDomainFromUrl(url) { | ||
const { hostname } = new URL(url) | ||
const parts = hostname.split(".") | ||
const tld = parts.slice(-2).join(".") | ||
return tld | ||
} | ||
function handleMessage(event) { | ||
if (event.data?.type !== "bb-parent-window-event") { | ||
return | ||
} | ||
// Validate the event origin to ensure it's coming from a trusted source | ||
// Allow different subdomains but must match TLD | ||
const appOrigin = extractDomainFromUrl(window.location.origin) | ||
const eventOrigin = extractDomainFromUrl(event.origin) | ||
if (appOrigin === eventOrigin) { | ||
data = event.data | ||
} else { | ||
console.error( | ||
`Embedded budibase app domain ${appOrigin} does not match origin of event ${eventOrigin}. | ||
Top level domains must match` | ||
) | ||
} | ||
} | ||
onMount(() => { | ||
window.addEventListener("message", handleMessage) | ||
return () => window.removeEventListener("message", handleMessage) | ||
}) | ||
</script> | ||
<Provider key="embed" {data}> | ||
<slot /> | ||
</Provider> |