Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: send user info only to app.nocodb.com origin

DarkPhoenix2704a557fc11fb5b
diff --git a/packages/nc-gui/composables/useUserSync.ts b/packages/nc-gui/composables/useUserSync.ts
index 6369605478..f8bd2c5a52 100644
--- a/packages/nc-gui/composables/useUserSync.ts
+++ b/packages/nc-gui/composables/useUserSync.ts
@@ -1,17 +1,42 @@
-import { onMounted, onUnmounted, ref, watch } from 'vue'
-
export interface UserObject {
id?: string
email?: string
display_name?: string
}
+const MESSAGE_TYPE = '___NC_USER_SYNC' as const
+
export const useUserSync = createSharedComposable(() => {
const isIFrame = ncIsIframe()
const { user } = useGlobal()
const currentUser = ref<UserObject | null>(null)
let syncInterval: NodeJS.Timeout | null = null
+ /**
+ * Determines the appropriate target origin for an iframe
+ * @param iframe - The iframe element to check
+ * @returns The target origin URL, or null if iframe should be skipped
+ */
+ const getIframeTargetOrigin = (iframe: HTMLIFrameElement): string | null => {
+ try {
+ const src = iframe.getAttribute('src')
+
+ if (!src || src === 'about:blank' || src.startsWith('data:') || src.startsWith('blob:')) {
+ return null
+ }
+
+ const url = new URL(src, window.location.origin)
+ if (url.origin === 'https://app.nocodb.com') {
+ return url.origin
+ }
+ console.warn('Skipping iframe with untrusted origin:', url.origin)
+ return null
+ } catch (error) {
+ console.warn('Failed to determine iframe origin:', error)
+ return null
+ }
+ }
+
const sendToAllIframes = () => {
const userObj = {
id: user.value?.id,
@@ -21,12 +46,18 @@ export const useUserSync = createSharedComposable(() => {
document.querySelectorAll('iframe').forEach((iframe) => {
try {
+ const targetOrigin = getIframeTargetOrigin(iframe)
+
+ if (!targetOrigin) {
+ return
+ }
+
iframe.contentWindow?.postMessage(
{
- type: '___NC_USER_SYNC',
+ type: MESSAGE_TYPE,
user: userObj,
},
- '*',
+ targetOrigin,
)
} catch (error) {
console.warn('Failed to send user data to iframe:', error)
@@ -37,7 +68,7 @@ export const useUserSync = createSharedComposable(() => {
// IFRAME MODE: Listen for user data
if (isIFrame) {
window.addEventListener('message', (event) => {
- if (event.data.type === '___NC_USER_SYNC') {
+ if (event.data.type === MESSAGE_TYPE) {
currentUser.value = event.data.user
}
})