🔥 🔥 🔥 A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(auth): Shared Base / ERD / Shared View: LocalStorage token reuse causes unauthorized logged-in access
Ramesh Manebecb2e65e2f3
diff --git a/packages/nc-gui/composables/useGlobal/state.ts b/packages/nc-gui/composables/useGlobal/state.tsindex 7a1cfeb355..eb759b0844 100644--- a/packages/nc-gui/composables/useGlobal/state.ts+++ b/packages/nc-gui/composables/useGlobal/state.ts@@ -17,6 +17,10 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {vueApp: { i18n },} = useNuxtApp()+ const router = useRouter()++ const isSharedBaseOrErdOrView = computed(() => isSharedBaseOrErdOrViewRoute(router.currentRoute.value))+/*** Set initial language based on browser settings.* If the user has not set a preferred language, we fall back to 'en'.@@ -79,9 +83,32 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {storage.value.darkMode = false/** current token ref, used by `useJwt` to reactively parse our token payload */+ /**+ * Token management behavior (read/write rules):+ *+ * Issue:+ * - When opening a Shared Base, ERD, or Shared View in a new tab,+ * the main application’s auth token from `localStorage` gets reused.+ * - This incorrectly treats the user as authenticated, even though+ * shared resources must always behave as "guest/readonly" access.+ *+ * Fix:+ * - When we detect that current route is a Shared Base / ERD / Shared View,+ * we completely avoid reading from or writing to localStorage.+ * - This ensures:+ * ✅ Shared views always open as guest users+ * ✅ Real login session in main app remains unaffected+ * ✅ No accidental privilege escalation when opening links in new tab+ *+ * Result:+ * - Main app uses persistent auth from localStorage+ * - Shared resources use a temporary, isolated token only in memory+ */const token = computed({- get: () => storage.value.token || '',+ get: () => (isSharedBaseOrErdOrView.value ? '' : storage.value.token || ''),set: (val) => {+ if (isSharedBaseOrErdOrView.value) return+storage.value.token = val},})diff --git a/packages/nc-gui/utils/routeUtils.ts b/packages/nc-gui/utils/routeUtils.tsindex c53e1e8307..9d7765e595 100644--- a/packages/nc-gui/utils/routeUtils.ts+++ b/packages/nc-gui/utils/routeUtils.ts@@ -35,3 +35,14 @@ export const isPublicRoute = (route: RouteLocationNormalizedLoadedGeneric) => {return route.meta?.public}++export const isSharedBaseOrErdOrViewRoute = (route: RouteLocationNormalizedLoadedGeneric) => {+ if (!route) return false++ return (+ isSharedViewRoute(route) ||+ isSharedFormViewRoute(route) ||+ route.params.typeOrId === 'base' ||+ route.params.typeOrId === 'ERD'+ )+}