🪢 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(auth): clarify permission-denied messages (#18783)
Mark Salpeter6dbd0524db7f
diff --git a/packages/shared/src/errors/ForbiddenError.ts b/packages/shared/src/errors/ForbiddenError.tsindex 8a63fb0cc9..104c68026d 100644--- a/packages/shared/src/errors/ForbiddenError.ts+++ b/packages/shared/src/errors/ForbiddenError.ts@@ -1,7 +1,9 @@import { BaseError } from "./BaseError";export class ForbiddenError extends BaseError {- constructor(description = "Forbidden") {+ constructor(+ description = "Access denied. You do not have permission to access this resource.",+ ) {super("ForbiddenError", 403, description, true);}}diff --git a/web/src/__tests__/server/blob-storage-integration-api.servertest.ts b/web/src/__tests__/server/blob-storage-integration-api.servertest.tsindex 5b8bf38ef2..7a5b1fc0ac 100644--- a/web/src/__tests__/server/blob-storage-integration-api.servertest.ts+++ b/web/src/__tests__/server/blob-storage-integration-api.servertest.ts@@ -265,9 +265,6 @@ describe("Blob Storage Integrations API", () => {createBasicAuthHeader(projectApiKey.publicKey, projectApiKey.secretKey),);expect(result.status).toBe(403);- expect(result.body.message).toContain(- "Organization-scoped API key required",- );// Clean upawait prisma.apiKey.delete({ where: { id: projectApiKey.id } });diff --git a/web/src/__tests__/server/mcp-error-formatting.servertest.ts b/web/src/__tests__/server/mcp-error-formatting.servertest.tsindex 3355778b43..89b66e709b 100644--- a/web/src/__tests__/server/mcp-error-formatting.servertest.ts+++ b/web/src/__tests__/server/mcp-error-formatting.servertest.ts@@ -213,14 +213,21 @@ describe("MCP Error Formatting", () => {expect(mcpError.message).toContain("Invalid credentials");});- it("should format ForbiddenError with permission message", () => {- const error = new ForbiddenError("Access denied");- const mcpError = formatErrorForUser(error);-- expect(mcpError.code).toBe(ErrorCode.InvalidRequest);- expect(mcpError.message).toContain("forbidden");- expect(mcpError.message).toContain("permission");- });+ it.each([+ ["Access denied", "MCP error -32600: Access denied"],+ [+ undefined,+ "MCP error -32600: Access denied. You do not have permission to access this resource.",+ ],+ ])(+ "preserves the ForbiddenError message: %s",+ (description, expectedMessage) => {+ const mcpError = formatErrorForUser(new ForbiddenError(description));++ expect(mcpError.code).toBe(ErrorCode.InvalidRequest);+ expect(mcpError.message).toBe(expectedMessage);+ },+ );it("should format LangfuseNotFoundError with original message", () => {const error = new LangfuseNotFoundError("Prompt not found: chatbot");diff --git a/web/src/__tests__/server/mcp-tools-write.servertest.ts b/web/src/__tests__/server/mcp-tools-write.servertest.tsindex eb05783cd6..eb0893b1dc 100644--- a/web/src/__tests__/server/mcp-tools-write.servertest.ts+++ b/web/src/__tests__/server/mcp-tools-write.servertest.ts@@ -44,6 +44,7 @@ vi.mock(import { prisma, Role } from "@langfuse/shared/src/db";import { nanoid } from "nanoid";import { z } from "zod";+import { ErrorCode } from "@modelcontextprotocol/sdk/types.js";import {createInAppAgentMcpContext,createMcpTestSetup,@@ -2115,7 +2116,9 @@ describe("MCP Write Tools", () => {if (testCase.expectForbidden) {await expect(update).rejects.toMatchObject({name: "McpError",- message: expect.stringContaining("Access forbidden"),+ code: ErrorCode.InvalidRequest,+ message:+ "MCP error -32600: You don't have permission to add a protected label to a prompt. Please contact your project admin for assistance.\n\n Protected labels are: production",});const prompt = await prisma.prompt.findFirst({@@ -2164,7 +2167,8 @@ describe("MCP Write Tools", () => {),).rejects.toMatchObject({name: "McpError",- message: expect.stringContaining("Access forbidden"),+ code: ErrorCode.InvalidRequest,+ message: `MCP error -32600: You don't have permission to create a prompt with a protected label. Please contact your project admin for assistance.\n\n Protected labels are: ${protectedLabel}`,});await expect(@@ -2205,7 +2209,9 @@ describe("MCP Write Tools", () => {),).rejects.toMatchObject({name: "McpError",- message: expect.stringContaining("Access forbidden"),+ code: ErrorCode.InvalidRequest,+ message:+ "MCP error -32600: You don't have permission to add a protected label to a prompt. Please contact your project admin for assistance.\n\n Protected labels are: production",});});});diff --git a/web/src/__tests__/server/organizations-api.servertest.ts b/web/src/__tests__/server/organizations-api.servertest.tsindex 368d999098..27fcb6a1ec 100644--- a/web/src/__tests__/server/organizations-api.servertest.ts+++ b/web/src/__tests__/server/organizations-api.servertest.ts@@ -1092,9 +1092,6 @@ describe("Public Organizations API", () => {),);expect(result.status).toBe(403);- expect(result.body.error).toContain(- "Organization-scoped API key required",- );// Clean upawait prisma.apiKey.delete({@@ -1456,9 +1453,6 @@ describe("Public Organizations API", () => {);expect(response.status).toBe(403);- expect(response.body.error).toContain(- "Organization-scoped API key required",- );// Clean upawait prisma.apiKey.delete({diff --git a/web/src/__tests__/server/projects-api.servertest.ts b/web/src/__tests__/server/projects-api.servertest.tsindex fd813ebb2b..c3194e0622 100644--- a/web/src/__tests__/server/projects-api.servertest.ts+++ b/web/src/__tests__/server/projects-api.servertest.ts@@ -461,9 +461,6 @@ describe("Projects API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.message).toContain(- "Organization-scoped API key required",- );});it("should return 401 when invalid API keys are provided", async () => {@@ -767,9 +764,6 @@ describe("Projects API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.message).toContain(- "Organization-scoped API key required",- );});it("should return 404 when project does not exist", async () => {@@ -844,9 +838,6 @@ describe("Projects API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.message).toContain(- "Organization-scoped API key required",- );});it("should return 401 when invalid API keys are provided", async () => {@@ -909,9 +900,6 @@ describe("Projects API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.message).toContain(- "Organization-scoped API key required",- );});it("should return 404 when project does not exist", async () => {@@ -1149,9 +1137,6 @@ describe("Projects API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.message).toContain(- "Organization-scoped API key required",- );});it("should return 401 when invalid API keys are provided", async () => {@@ -1422,9 +1407,6 @@ describe("Projects API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.message).toContain(- "Organization-scoped API key required",- );});it("should return 401 when invalid API keys are provided", async () => {diff --git a/web/src/__tests__/server/scim-api.servertest.ts b/web/src/__tests__/server/scim-api.servertest.tsindex a3cbf84b99..e9d48dfa07 100644--- a/web/src/__tests__/server/scim-api.servertest.ts+++ b/web/src/__tests__/server/scim-api.servertest.ts@@ -194,9 +194,6 @@ describe("SCIM API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.detail).toContain(- "Organization-scoped API key required",- );});it("should return 405 for non-GET methods", async () => {@@ -259,9 +256,6 @@ describe("SCIM API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.detail).toContain(- "Organization-scoped API key required",- );});it("should return 405 for non-GET methods", async () => {@@ -317,9 +311,6 @@ describe("SCIM API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.detail).toContain(- "Organization-scoped API key required",- );});it("should return 405 for non-GET methods", async () => {@@ -426,9 +417,6 @@ describe("SCIM API", () => {createBasicAuthHeader(projectApiKey, projectSecretKey),);expect(result.status).toBe(403);- expect(result.body.detail).toContain(- "Organization-scoped API key required",- );});it("should return 405 for non-GET/POST methods", async () => {diff --git a/web/src/__tests__/server/unit/assertToolAuthorized.servertest.ts b/web/src/__tests__/server/unit/assertToolAuthorized.servertest.tsindex c09a4dd0e3..3fd459f9d7 100644--- a/web/src/__tests__/server/unit/assertToolAuthorized.servertest.ts+++ b/web/src/__tests__/server/unit/assertToolAuthorized.servertest.ts@@ -90,7 +90,12 @@ describe("assertToolAuthorized", () => {serverContext(authContext([allowPrompts])),),).toThrow(- expect.objectContaining({ code: ErrorCode.InvalidRequest }) as Error,+ expect.objectContaining({+ code: ErrorCode.InvalidRequest,+ message: expect.stringContaining(+ 'Access denied. The "prompts:CUD" permission is required to access this resource.',+ ),+ }) as Error,);});@@ -103,6 +108,22 @@ describe("assertToolAuthorized", () => {).not.toThrow();});+ it("keeps the generic permission message for an invalid wildcard target", () => {+ expect(() =>+ assertToolAuthorized(tool("prompts:read"), {+ ...serverContext(authContext([allowPrompts])),+ projectId: "*",+ }),+ ).toThrow(+ expect.objectContaining({+ code: ErrorCode.InvalidRequest,+ message: expect.stringContaining(+ "Access denied. You do not have permission to access this resource.",+ ),+ }) as Error,+ );+ });+it("passes an ungated tool regardless of context", () => {expect(() =>assertToolAuthorized(@@ -123,7 +144,12 @@ describe("assertToolAuthorized", () => {expect(() =>assertToolAuthorized(tool("prompts:CUD"), serverContext()),).toThrow(- expect.objectContaining({ code: ErrorCode.InvalidRequest }) as Error,+ expect.objectContaining({+ code: ErrorCode.InvalidRequest,+ message: expect.stringContaining(+ "Authentication failed. Please check your API key.",+ ),+ }) as Error,);});diff --git a/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.ts b/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.tsindex 1efc16cf80..3850f0503f 100644--- a/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.ts+++ b/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.ts@@ -2,8 +2,10 @@ import type { NextApiRequest, NextApiResponse } from "next";import { createMocks } from "node-mocks-http";import { z } from "zod";import type * as PrismaClientModule from "@prisma/client";+import type * as StructuredPublicApiErrorContract from "@/src/features/public-api/server/structuredPublicApiErrorContract";const {+ mockAuthenticate,mockVerifyAuthHeaderAndReturnScope,mockIsPrismaException,mockRateLimitRequest,@@ -17,6 +19,7 @@ const {mockSendStructuredPublicApiErrorResponse,mockEnv,} = vi.hoisted(() => ({+ mockAuthenticate: vi.fn(),mockVerifyAuthHeaderAndReturnScope: vi.fn(),mockIsPrismaException: vi.fn(),mockRateLimitRequest: vi.fn(),@@ -40,12 +43,17 @@ const {mockSendStructuredPublicApiErrorResponse: vi.fn(),mockEnv: {NODE_ENV: "test",+ API_AUTH_MIGRATION: "legacy" as "legacy" | "enforce",NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined as string | undefined,LANGFUSE_API_ORGANIZATION_CUTOFF_ENABLED: "false" as "true" | "false",LANGFUSE_API_ORGANIZATION_CUTOFF_DATE: "2026-09-16T00:00:00.000Z",},}));+vi.mock("@/src/features/apiKey/server", () => ({+ authenticator: { authenticate: mockAuthenticate },+}));+vi.mock("@/src/features/public-api/server/apiAuth", () => ({ApiAuthService: class {verifyAuthHeaderAndReturnScope = mockVerifyAuthHeaderAndReturnScope;@@ -149,6 +157,7 @@ describe("createAuthedProjectAPIRoute auth error handling", () => {beforeEach(() => {vi.clearAllMocks();+ mockEnv.API_AUTH_MIGRATION = "legacy";mockIsPrismaException.mockReturnValue(false);mockRateLimitRequest.mockResolvedValue({isRateLimited: () => false,@@ -346,6 +355,64 @@ describe("createAuthedProjectAPIRoute auth error handling", () => {expect(mockFindOrganization).not.toHaveBeenCalled();});+ it.each([false, true])(+ "preserves the required permission in enforce-mode 403 responses with structured=%s",+ async (useStructuredErrorContract) => {+ mockEnv.API_AUTH_MIGRATION = "enforce";+ mockAuthenticate.mockResolvedValueOnce({+ success: true,+ context: {+ principal: {+ kind: "apiKey",+ apiKeyId: "api-key-1",+ publicKey: "pk-test",+ userId: null,+ isInAppAgentKey: false,+ scope: "PROJECT",+ presentation: "privateKey",+ boundResource: { orgId: "org-1", projectId: "project-1" },+ organizations: [+ {+ orgId: "org-1",+ projectIds: ["project-1"],+ organizationCreatedAt: "2026-09-16T00:00:00.000Z",+ plan: "cloud:hobby",+ rateLimitOverrides: [],+ isIngestionSuspended: false,+ },+ ],+ },+ policies: [],+ },+ });+ if (useStructuredErrorContract) {+ const contract = await vi.importActual<+ typeof StructuredPublicApiErrorContract+ >("@/src/features/public-api/server/structuredPublicApiErrorContract");+ mockCreateStructuredPublicApiAuthError.mockImplementationOnce(+ contract.createStructuredPublicApiAuthError,+ );+ mockSendStructuredPublicApiErrorResponse.mockImplementationOnce(+ contract.sendStructuredPublicApiErrorResponse,+ );+ }++ const res = await callRoute({ useStructuredErrorContract });++ expect(res.statusCode).toBe(403);+ expect(res._getJSONData()).toEqual({+ message:+ 'Access denied. The "project:read" permission is required to access this resource.',+ ...(useStructuredErrorContract+ ? { code: "access_denied" }+ : { error: "ForbiddenError" }),+ });+ expect(mockAuthenticate).toHaveBeenCalledOnce();+ expect(mockVerifyAuthHeaderAndReturnScope).not.toHaveBeenCalled();+ expect(mockRateLimitRequest).not.toHaveBeenCalled();+ },+ );+it("returns 401 for invalid credentials", async () => {mockVerifyAuthHeaderAndReturnScope.mockResolvedValueOnce({validKey: false,diff --git a/web/src/__tests__/server/unit/policy/authorize.servertest.ts b/web/src/__tests__/server/unit/policy/authorize.servertest.tsindex 90d98bc3a2..1e9df630ea 100644--- a/web/src/__tests__/server/unit/policy/authorize.servertest.ts+++ b/web/src/__tests__/server/unit/policy/authorize.servertest.ts@@ -127,7 +127,13 @@ describe("authorize — org resources need an exact match", () => {describe("authorize — deny-overrides and deny-by-default", () => {it("denies by default when nothing matches", () => {- expect(authorize(ctx([]), TENANT, "prompts:read", PRJ).success).toBe(false);+ const decision = authorize(ctx([]), TENANT, "prompts:read", PRJ);+ expect(decision.success).toBe(false);+ expect(decision.error).toMatchObject({+ httpCode: 403,+ message:+ 'Access denied. The "prompts:read" permission is required to access this resource.',+ });});it("a matching deny beats a matching allow on the same resource", () => {const suspended = ctx([@@ -138,23 +144,27 @@ describe("authorize — deny-overrides and deny-by-default", () => {false,);});- it("a deny carries the generic Forbidden message", () => {+ it("an explicit deny carries the required action", () => {const decision = authorize(ctx([policy({ actions: ["traces:create"], effect: "DENY" })]),TENANT,"traces:create",PRJ,);- expect(decision.error?.message).toBe(new ForbiddenError().message);+ expect(decision.error).toMatchObject({+ httpCode: 403,+ message:+ 'Access denied. The "traces:create" permission is required to access this resource.',+ });});});describe("authorize — kind wildcards are never a target", () => {it("denies an authorization check against project/*", () => {const wildcardGrant = ctx([policy({ resources: [WILDCARD] })]);- expect(- authorize(wildcardGrant, TENANT, "prompts:read", WILDCARD).success,- ).toBe(false);+ const decision = authorize(wildcardGrant, TENANT, "prompts:read", WILDCARD);+ expect(decision.success).toBe(false);+ expect(decision.error?.message).toBe(new ForbiddenError().message);});it("denies an authorization check against organization/*", () => {const wildcardGrant = ctx([diff --git a/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.ts b/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.tsindex 13d91974fe..df7c3ee99a 100644--- a/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.ts+++ b/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.ts@@ -56,6 +56,7 @@ vi.mock();import { shadowAuth, shadowAuthorize } from "@/src/features/public-api/server";+import { authorizeBlobStorageRequest } from "@/src/features/blobstorage-integration/authorizeBlobStorageRequest";import { type AuthorizationContext } from "@/src/features/auth/policy/types";const mappedFields = {@@ -120,8 +121,7 @@ describe("org-family dispatch (allowedAccessLevels ['organization'])", () => {it("403s a non-org key, leaving the body to the route", async () => {legacyProjectKey();expect(await call()).toMatchObject({- success: false,- error: { httpCode: 403, message: "Forbidden" },+ error: { httpCode: 403 },});});});@@ -218,6 +218,37 @@ describe("org-family dispatch (allowedAccessLevels ['organization'])", () => {},);+ it("preserves the required permission through blob-storage authorization", async () => {+ const error = new ForbiddenError(+ 'Access denied. The "projects:read" permission is required to access this resource.',+ );+ mockEnforceAuth.mockResolvedValue({ success: false, error });++ await expect(authorizeBlobStorageRequest(req)).rejects.toBe(error);+ });++ it.each([+ { name: "500", ErrorClass: InternalServerError },+ { name: "503", ErrorClass: ServiceUnavailableError },+ ])(+ "preserves sanitized $name errors through blob-storage authorization",+ async ({ ErrorClass }) => {+ vi.spyOn(logger, "error").mockImplementation(() => logger);+ mockEnforceAuth.mockResolvedValue({+ success: false,+ error: new ErrorClass(+ "database host private-db:5432 rejected lookup",+ ),+ });++ await expect(authorizeBlobStorageRequest(req)).rejects.toMatchObject({+ name: new ErrorClass().name,+ httpCode: new ErrorClass().httpCode,+ message: new ErrorClass().message,+ });+ },+ );+it("sanitizes unexpected throws and redacts secrets from diagnostics", async () => {const secret = "sk-lf-test-secret-12345678";const log = vi.spyOn(logger, "error").mockImplementation(() => logger);diff --git a/web/src/__tests__/server/unit/public-api/write-error.servertest.ts b/web/src/__tests__/server/unit/public-api/write-error.servertest.tsnew file mode 100644index 0000000000..2ac47dc8cf--- /dev/null+++ b/web/src/__tests__/server/unit/public-api/write-error.servertest.ts@@ -0,0 +1,47 @@+import { type NextApiResponse } from "next";+import { createResponse } from "node-mocks-http";++import { ForbiddenError } from "@langfuse/shared";+import {+ writeOrgError,+ writeProjectError,+ writeScimError,+} from "@/src/features/public-api/server/writeError";++describe.each([+ {+ name: "organization",+ write: writeOrgError,+ field: "error",+ envelope: {},+ },+ {+ name: "project",+ write: writeProjectError,+ field: "message",+ envelope: {},+ },+ {+ name: "SCIM",+ write: writeScimError,+ field: "detail",+ envelope: {+ schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],+ status: 403,+ },+ },+])("$name authorization error response", ({ write, field, envelope }) => {+ it("preserves the required permission", () => {+ const description =+ 'Access denied. The "projects:read" permission is required to access this resource.';+ const res = createResponse<NextApiResponse>();++ write(res, new ForbiddenError(description));++ expect(res.statusCode).toBe(403);+ expect(res._getJSONData()).toEqual({+ ...envelope,+ [field]: description,+ });+ });+});diff --git a/web/src/features/blobstorage-integration/authorizeBlobStorageRequest.ts b/web/src/features/blobstorage-integration/authorizeBlobStorageRequest.tsindex 293ecc4959..91883b7df0 100644--- a/web/src/features/blobstorage-integration/authorizeBlobStorageRequest.ts+++ b/web/src/features/blobstorage-integration/authorizeBlobStorageRequest.ts@@ -1,13 +1,10 @@import { type NextApiRequest } from "next";-import { ForbiddenError, UnauthorizedError } from "@langfuse/shared";+import { ForbiddenError } from "@langfuse/shared";import { type ApiAccessScope } from "@langfuse/shared/src/server";import { hasEntitlementBasedOnPlan } from "@/src/features/entitlements/server";-import {- shadowAuth,- ErrorOrgApiKeyRequired,-} from "@/src/features/public-api/server";+import { shadowAuth } from "@/src/features/public-api/server";/** authorizeBlobStorageRequest gates a blob-storage request on an organization key and the blob-export entitlement, returning the verified scope. */export async function authorizeBlobStorageRequest(@@ -19,10 +16,7 @@ export async function authorizeBlobStorageRequest(allowedAccessLevels: ["organization"],});if (!authCheck.success) {- if (authCheck.error.httpCode === 401) {- throw new UnauthorizedError(authCheck.error.message);- }- throw new ForbiddenError(ErrorOrgApiKeyRequired);+ throw authCheck.error;}if (!hasEntitlementBasedOnPlan({diff --git a/web/src/features/mcp/core/error-formatting.ts b/web/src/features/mcp/core/error-formatting.tsindex 9eeada3db1..1e30039a43 100644--- a/web/src/features/mcp/core/error-formatting.ts+++ b/web/src/features/mcp/core/error-formatting.ts@@ -62,10 +62,7 @@ export function formatErrorForUser(error: unknown): McpError {}if (error instanceof ForbiddenError) {- return new McpError(- ErrorCode.InvalidRequest,- "Access forbidden. You do not have permission to access this resource.",- );+ return new McpError(ErrorCode.InvalidRequest, error.message);}if (error instanceof LangfuseNotFoundError) {diff --git a/web/src/features/public-api/server/index.ts b/web/src/features/public-api/server/index.tsindex 92583b7a76..6180f66c09 100644--- a/web/src/features/public-api/server/index.ts+++ b/web/src/features/public-api/server/index.ts@@ -175,12 +175,7 @@ export {shadowAuthorize,type ShadowAuthParams,} from "./shadowAuth";-export {- ErrorOrgApiKeyRequired,- writeOrgError,- writeProjectError,- writeScimError,-} from "./writeError";+export { writeOrgError, writeProjectError, writeScimError } from "./writeError";export {ObservationPromptVariableMappingInput,PromptVariableMappingRead,diff --git a/web/src/features/public-api/server/writeError.ts b/web/src/features/public-api/server/writeError.tsindex 40fb89f68f..166d47a298 100644--- a/web/src/features/public-api/server/writeError.ts+++ b/web/src/features/public-api/server/writeError.ts@@ -2,15 +2,11 @@ import { type NextApiResponse } from "next";import { type BaseError, ServiceUnavailableError } from "@langfuse/shared";-/** ErrorOrgApiKeyRequired is the 403 message when a non-organization key hits an organization-scoped operation. */-export const ErrorOrgApiKeyRequired =- "Invalid API key. Organization-scoped API key required for this operation.";-/** writeScimError renders an auth-deny error in the SCIM error envelope. */export function writeScimError(res: NextApiResponse, error: BaseError): void {return res.status(error.httpCode).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],- detail: error.httpCode === 403 ? ErrorOrgApiKeyRequired : error.message,+ detail: error.message,status: error.httpCode,});}@@ -18,7 +14,7 @@ export function writeScimError(res: NextApiResponse, error: BaseError): void {/** writeOrgError renders an auth-deny error in the organization error envelope. */export function writeOrgError(res: NextApiResponse, error: BaseError): void {return res.status(error.httpCode).json({- error: error.httpCode === 403 ? ErrorOrgApiKeyRequired : error.message,+ error: error.message,});}@@ -28,7 +24,7 @@ export function writeProjectError(error: BaseError,): void {return res.status(error.httpCode).json({- message: error.httpCode === 403 ? ErrorOrgApiKeyRequired : error.message,+ message: error.message,});}diff --git a/web/src/features/rbac/authorize.ts b/web/src/features/rbac/authorize.tsindex 0a5bd6398b..ff98d3a518 100644--- a/web/src/features/rbac/authorize.ts+++ b/web/src/features/rbac/authorize.ts@@ -33,7 +33,9 @@ export function authorize(const policiesForResource = matchesResource(ctx, tenant, resource);const grant = policiesForResource.filter(byAction(action));if (grant.length === 0 || grant.some(byEffect("DENY"))) {- return forbiddenError();+ return forbiddenError(+ `Access denied. The "${action}" permission is required to access this resource.`,+ );}return { success: true };}