Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(scim): gate SCIM Users provisioning behind admin-api entitlement (#14448)

Steffen Schmitz91a754687060
diff --git a/web/src/__tests__/server/scim-api.servertest.ts b/web/src/__tests__/server/scim-api.servertest.ts
index cc3f1e114a..b7fb8006b0 100644
--- a/web/src/__tests__/server/scim-api.servertest.ts
+++ b/web/src/__tests__/server/scim-api.servertest.ts
@@ -1273,7 +1273,13 @@ describe("SCIM API", () => {
beforeEach(async () => {
const org = await prisma.organization.create({
- data: { name: `scim-last-owner-${randomUUID().substring(0, 8)}` },
+ data: {
+ name: `scim-last-owner-${randomUUID().substring(0, 8)}`,
+ // Team plan carries the `admin-api` entitlement that gates SCIM, so
+ // these requests reach the last-OWNER guard rather than the plan
+ // check.
+ cloudConfig: { plan: "Team" },
+ },
});
scopedOrgId = org.id;
@@ -1476,4 +1482,159 @@ describe("SCIM API", () => {
});
});
});
+
+ // SCIM provisioning is gated behind the `admin-api` entitlement, matching the
+ // sibling organization admin REST endpoints (memberships, projects, apiKeys).
+ // Plans without that entitlement (e.g. Hobby) must be rejected before any
+ // user account is created or any membership is mutated.
+ describe("Entitlement gating (admin-api)", () => {
+ const PLAN_DETAIL = "This feature is not available on your current plan.";
+
+ let hobbyOrgId: string;
+ let hobbyPublicKey: string;
+ let hobbySecretKey: string;
+
+ let teamOrgId: string;
+ let teamPublicKey: string;
+ let teamSecretKey: string;
+
+ beforeAll(async () => {
+ // Hobby has no `admin-api` entitlement → SCIM must be blocked.
+ const hobbyOrg = await prisma.organization.create({
+ data: {
+ name: `scim-gate-hobby-${randomUUID().substring(0, 8)}`,
+ cloudConfig: { plan: "Hobby" },
+ },
+ });
+ hobbyOrgId = hobbyOrg.id;
+ hobbyPublicKey = `pk-lf-org-${randomUUID().substring(0, 8)}`;
+ hobbySecretKey = `sk-lf-org-${randomUUID().substring(0, 8)}`;
+ await createAndAddApiKeysToDb({
+ prisma,
+ entityId: hobbyOrgId,
+ scope: "ORGANIZATION",
+ predefinedKeys: {
+ publicKey: hobbyPublicKey,
+ secretKey: hobbySecretKey,
+ },
+ });
+
+ // Team carries `admin-api` → positive control that the gate does not
+ // over-block entitled plans.
+ const teamOrg = await prisma.organization.create({
+ data: {
+ name: `scim-gate-team-${randomUUID().substring(0, 8)}`,
+ cloudConfig: { plan: "Team" },
+ },
+ });
+ teamOrgId = teamOrg.id;
+ teamPublicKey = `pk-lf-org-${randomUUID().substring(0, 8)}`;
+ teamSecretKey = `sk-lf-org-${randomUUID().substring(0, 8)}`;
+ await createAndAddApiKeysToDb({
+ prisma,
+ entityId: teamOrgId,
+ scope: "ORGANIZATION",
+ predefinedKeys: {
+ publicKey: teamPublicKey,
+ secretKey: teamSecretKey,
+ },
+ });
+ });
+
+ afterAll(async () => {
+ await prisma.organization.deleteMany({
+ where: { id: { in: [hobbyOrgId, teamOrgId] } },
+ });
+ });
+
+ it("POST /Users is rejected on a plan without admin-api and creates no account", async () => {
+ const uniqueEmail = `scim.gate.${randomUUID().substring(0, 8)}@example.com`;
+ const result = await makeAPICall(
+ "POST",
+ "/api/public/scim/Users",
+ {
+ schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
+ userName: uniqueEmail,
+ name: { formatted: "Backdoor" },
+ password: "Backdoor2026!",
+ roles: ["OWNER"],
+ active: true,
+ },
+ createBasicAuthHeader(hobbyPublicKey, hobbySecretKey),
+ );
+
+ expect(result.status).toBe(403);
+ expect(result.body.detail).toBe(PLAN_DETAIL);
+
+ // The blocked request must not have created the user account.
+ const user = await prisma.user.findUnique({
+ where: { email: uniqueEmail.toLowerCase() },
+ });
+ expect(user).toBeNull();
+ });
+
+ it("GET /Users is rejected on a plan without admin-api", async () => {
+ const result = await makeAPICall(
+ "GET",
+ "/api/public/scim/Users",
+ undefined,
+ createBasicAuthHeader(hobbyPublicKey, hobbySecretKey),
+ );
+
+ expect(result.status).toBe(403);
+ expect(result.body.detail).toBe(PLAN_DETAIL);
+ });
+
+ it("PUT /Users/{id} is rejected on a plan without admin-api (before user lookup)", async () => {
+ const result = await makeAPICall(
+ "PUT",
+ `/api/public/scim/Users/${randomUUID()}`,
+ {
+ schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
+ userName: "[email protected]",
+ active: true,
+ roles: ["OWNER"],
+ },
+ createBasicAuthHeader(hobbyPublicKey, hobbySecretKey),
+ );
+
+ expect(result.status).toBe(403);
+ expect(result.body.detail).toBe(PLAN_DETAIL);
+ });
+
+ it("DELETE /Users/{id} is rejected on a plan without admin-api", async () => {
+ const result = await makeAPICall(
+ "DELETE",
+ `/api/public/scim/Users/${randomUUID()}`,
+ undefined,
+ createBasicAuthHeader(hobbyPublicKey, hobbySecretKey),
+ );
+
+ expect(result.status).toBe(403);
+ expect(result.body.detail).toBe(PLAN_DETAIL);
+ });
+
+ it("POST /Users still succeeds on a plan with admin-api", async () => {
+ const uniqueEmail = `scim.gate.ok.${randomUUID().substring(0, 8)}@example.com`;
+ const result = await makeAPICall(
+ "POST",
+ "/api/public/scim/Users",
+ {
+ schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
+ userName: uniqueEmail,
+ name: { formatted: "Allowed User" },
+ active: true,
+ },
+ createBasicAuthHeader(teamPublicKey, teamSecretKey),
+ );
+
+ expect(result.status).toBe(201);
+ expect(result.body.userName).toBe(uniqueEmail);
+
+ // Cleanup the account created by the positive-control request.
+ await prisma.user.deleteMany({
+ where: { email: uniqueEmail.toLowerCase() },
+ });
+ });
+ });
});
diff --git a/web/src/pages/api/public/scim/Users/[id].ts b/web/src/pages/api/public/scim/Users/[id].ts
index 195364afa3..e278b0df96 100644
--- a/web/src/pages/api/public/scim/Users/[id].ts
+++ b/web/src/pages/api/public/scim/Users/[id].ts
@@ -5,6 +5,7 @@ import { Prisma, prisma, type User, type Role } from "@langfuse/shared/src/db";
import { logger, redis } from "@langfuse/shared/src/server";
import { z } from "zod";
import { type NextApiRequest, type NextApiResponse } from "next";
+import { hasEntitlementBasedOnPlan } from "@/src/features/entitlements/server/hasEntitlement";
// Parse the first valid role from a SCIM `roles` array. Returns undefined when
// the attribute is absent, empty, or unparsable, which the provisioning logic
@@ -360,6 +361,23 @@ export default async function handler(
});
}
+ // Gate SCIM provisioning behind the `admin-api` entitlement, matching the
+ // sibling organization admin endpoints (memberships, projects, apiKeys).
+ // Without this, any org-scoped key could mutate memberships and roles on
+ // plans that do not include the feature.
+ if (
+ !hasEntitlementBasedOnPlan({
+ plan: authCheck.scope.plan,
+ entitlement: "admin-api",
+ })
+ ) {
+ return res.status(403).json({
+ schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],
+ detail: "This feature is not available on your current plan.",
+ status: 403,
+ });
+ }
+
logger.info(
`[SCIM] Received request for /api/public/scim/Users/[id] with method ${req.method} for orgId ${authCheck.scope.orgId} and userId ${req.query.id}`,
);
diff --git a/web/src/pages/api/public/scim/Users/index.ts b/web/src/pages/api/public/scim/Users/index.ts
index b9a5c53aa4..ad5add8ea4 100644
--- a/web/src/pages/api/public/scim/Users/index.ts
+++ b/web/src/pages/api/public/scim/Users/index.ts
@@ -8,6 +8,7 @@ import { hashPassword } from "@/src/features/auth-credentials/lib/credentialsSer
import { z } from "zod";
import { type Role } from "@langfuse/shared";
import { auditLog } from "@/src/features/audit-logs/auditLog";
+import { hasEntitlementBasedOnPlan } from "@/src/features/entitlements/server/hasEntitlement";
export default async function handler(
req: NextApiRequest,
@@ -53,6 +54,23 @@ export default async function handler(
});
}
+ // Gate SCIM provisioning behind the `admin-api` entitlement, matching the
+ // sibling organization admin endpoints (memberships, projects, apiKeys).
+ // Without this, any org-scoped key could create users and assign roles on
+ // plans that do not include the feature.
+ if (
+ !hasEntitlementBasedOnPlan({
+ plan: authCheck.scope.plan,
+ entitlement: "admin-api",
+ })
+ ) {
+ return res.status(403).json({
+ schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],
+ detail: "This feature is not available on your current plan.",
+ status: 403,
+ });
+ }
+
logger.info(
`[SCIM] Received request for /api/public/scim/Users with method ${req.method} for orgId ${authCheck.scope.orgId}`,
);