Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: reduce permission checks on file preview endpoint
Brad Barbin8aba411041ae
diff --git a/apps/carbon/app/routes/file+/preview+/$bucket.$.tsx b/apps/carbon/app/routes/file+/preview+/$bucket.$.tsxindex dee2b1382d..95864b3fa5 100644--- a/apps/carbon/app/routes/file+/preview+/$bucket.$.tsx+++ b/apps/carbon/app/routes/file+/preview+/$bucket.$.tsx@@ -1,3 +1,4 @@+import { getCarbonServiceRole } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { supportedModelTypes } from "@carbon/react";import { type LoaderFunctionArgs } from "@vercel/remix";@@ -23,7 +24,7 @@ const supportedFileTypes: Record<string, string> = {};export let loader = async ({ request, params }: LoaderFunctionArgs) => {- const { client } = await requirePermissions(request, {});+ const { companyId } = await requirePermissions(request, {});const { bucket } = params;let path = params["*"];@@ -42,8 +43,14 @@ export let loader = async ({ request, params }: LoaderFunctionArgs) => {throw new Error(`File type ${fileType} not supported`);const contentType = supportedFileTypes[fileType];+ if (!path.includes(companyId)) {+ return new Response(null, { status: 403 });+ }++ const serviceRole = await getCarbonServiceRole();+async function downloadFile() {- const result = await client.storage.from(bucket!).download(`${path}`);+ const result = await serviceRole.storage.from(bucket!).download(`${path}`);if (result.error) {console.error(result.error);return null;diff --git a/apps/mes/app/routes/file+/preview+/$bucket.$.tsx b/apps/mes/app/routes/file+/preview+/$bucket.$.tsxindex 51957f7745..25434161b2 100644--- a/apps/mes/app/routes/file+/preview+/$bucket.$.tsx+++ b/apps/mes/app/routes/file+/preview+/$bucket.$.tsx@@ -1,3 +1,4 @@+import { getCarbonServiceRole } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { supportedModelTypes } from "@carbon/react";import { type LoaderFunctionArgs } from "@vercel/remix";@@ -23,7 +24,7 @@ const supportedFileTypes: Record<string, string> = {};export let loader = async ({ request, params }: LoaderFunctionArgs) => {- const { client } = await requirePermissions(request, {});+ const { companyId } = await requirePermissions(request, {});const { bucket } = params;const path = params["*"];@@ -40,8 +41,14 @@ export let loader = async ({ request, params }: LoaderFunctionArgs) => {throw new Error(`File type ${fileType} not supported`);const contentType = supportedFileTypes[fileType];+ if (!path.includes(companyId)) {+ return new Response(null, { status: 403 });+ }++ const serviceRole = await getCarbonServiceRole();+async function downloadFile() {- const result = await client.storage.from(bucket!).download(`${path}`);+ const result = await serviceRole.storage.from(bucket!).download(`${path}`);if (result.error) {console.error(result.error);return null;