🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(layout): add client-side project access verification to prevent unauthorized access errors (#10618)
Michael Fröhlich8df58098e2fe
diff --git a/web/src/components/layouts/layout.tsx b/web/src/components/layouts/layout.tsxindex aac9494d73..cc9142776a 100644--- a/web/src/components/layouts/layout.tsx+++ b/web/src/components/layouts/layout.tsx@@ -47,6 +47,7 @@ import {type NavigationItem,} from "@/src/components/layouts/utilities/routes";import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";+import { ErrorPage } from "@/src/components/error-page";const signOutUser = async () => {sessionStorage.clear();@@ -150,6 +151,16 @@ export default function Layout(props: PropsWithChildren) {// project info based on projectId in the URLconst { project, organization } = useQueryProjectOrOrganization();+ // Check project access from session data (client-side)+ const userProjects =+ session.data?.user?.organizations+ ?.flatMap((org) => org?.projects?.map((project) => project?.id))+ .filter(Boolean) ?? [];+ const userHasProjectAccess =+ !routerProjectId ||+ userProjects.includes(routerProjectId) ||+ session.data?.user?.admin === true;+// Helper function for precise path matchingconst isPathActive = (routePath: string, currentPath: string): boolean => {// Exact match@@ -308,11 +319,32 @@ export default function Layout(props: PropsWithChildren) {return <Spinner message="Redirecting" />;}+ // Handle project access verification failure (client-side check)+ if (+ session.status === "authenticated" &&+ session.data &&+ routerProjectId &&+ router.pathname.includes("[projectId]") &&+ !userHasProjectAccess+ ) {+ return (+ <ErrorPage+ title="Project Not Found"+ message="The project you are trying to access does not exist or you do not have access to it."+ additionalButton={{+ label: "Go to Home",+ href: "/",+ }}+ />+ );+ }+const hideNavigation =session.status === "unauthenticated" ||pathsWithoutNavigation.includes(router.pathname) ||router.pathname.startsWith("/public/");- if (hideNavigation)++ if (hideNavigation) {return (<SidebarProvider className="bg-primary-foreground"><main className="min-h-dvh w-full overflow-y-scroll p-3 px-4 py-4 sm:px-6 lg:px-8">@@ -320,6 +352,8 @@ export default function Layout(props: PropsWithChildren) {</main></SidebarProvider>);+ }+return (<><Head>