CVE-2024-5127 (published 2024-06-06T18:15Z)

In lunary-ai/lunary versions 1.2.2 through 1.2.25, an improper access control vulnerability allows users on the Free plan to invite other members and assign them any role, including those intended for Paid and Enterprise plans only. This issue arises due to insufficient backend validation of roles and permissions, enabling unauthorized users to join a project and potentially exploit roles and permissions not intended for their use. The vulnerability specifically affects the Team feature, where the backend fails to validate whether a user has paid for a plan before allowing them to send invite links with any role assigned. This could lead to unauthorized access and manipulation of project settings or data.


Weakness information:
cwe_id: CWE-284
cwe_name: Improper Access Control
description: The product does not restrict or incorrectly restricts access to a resource from an unauthorized actor.
extended_description: 
            Access control involves the use of several protection mechanisms such as:
            
               Authentication (proving the identity of an actor)
               Authorization (ensuring that a given actor can access a resource), and
               Accountability (tracking of activities that were performed)
            
            When any mechanism is not applied or otherwise fails, attackers can compromise the security of the product by gaining privileges, reading sensitive information, executing commands, evading detection, etc.
            There are two distinct behaviors that can introduce access control weaknesses:
               
                  Specification: incorrect privileges, permissions, ownership, etc. are explicitly specified for either the user or the resource (for example, setting a password file to be world-writable, or giving administrator capabilities to a guest user). This action could be performed by the program or the administrator.
                  Enforcement: the mechanism contains errors that prevent it from properly enforcing the specified access control requirements (e.g., allowing the user to specify their own privileges, or allowing a syntactically-incorrect ACL to produce insecure settings). This problem occurs within the program itself, in that it does not actually enforce the intended security policy that the administrator specifies.
               
         
		 

Fix information:
repo_url: https://github.com/lunary-ai/lunary
commit_details: repo_url: https://github.com/lunary-ai/lunary
author: Hugues Chocart
author_date: 2024-05-19 14:35:54-03:00
msg: fix: backend plan check (#329)
repository: repo_url: https://github.com/lunary-ai/lunary
repo_name: lunary-ai/lunary
description: The production toolkit for LLMs. Observability, prompt management and evaluations. 
repo_language: TypeScript
owner: lunary-ai
file_changes: filename: template-versions.ts
change_type: ModificationType.MODIFY
diff: @@ -4,6 +4,7 @@ import { Context } from "koa"
 import postgres from "postgres"
 import { unCamelObject } from "@/src/utils/misc"
 import { checkAccess } from "@/src/utils/authorization"
+import { z } from "zod"
 
 const versions = new Router({
   prefix: "/template_versions",
@@ -68,25 +69,46 @@ versions.patch(
   "/:id",
   checkAccess("prompts", "update"),
   async (ctx: Context) => {
-    const { content, extra, testValues, isDraft } = ctx.request.body as {
-      id: string
-      content: any[]
-      extra: any
-      testValues: any
-      isDraft: boolean
-    }
+    const bodySchema = z.object({
+      content: z.array(z.any()),
+      extra: z.any(),
+      testValues: z.any(),
+      isDraft: z.boolean(),
+    })
+
+    const { content, extra, testValues, isDraft } = bodySchema.parse(
+      ctx.request.body,
+    )
 
     const [templateVersion] = await sql`
-    update template_version set
-      content = ${sql.json(content)},
-      extra = ${sql.json(unCamelObject(extra))},
-      test_values = ${sql.json(testValues)},
-      is_draft = ${isDraft}
-    where id = ${ctx.params.id}
-    returning *
-  `
+      select
+        *
+      from
+        template_version tv
+        left join template t on tv.template_id = t.id
+        left join project p on t.project_id = p.id 
+      where
+        tv.id = ${ctx.params.id}
+        and p.org_id = ${ctx.state.orgId}
+    `
+
+    if (!templateVersion) {
+      ctx.throw(401, "You don't have access to this template")
+    }
 
-    ctx.body = templateVersion
+    const [updatedTemplateVersion] = await sql`
+      update template_version 
+      set
+        content = ${sql.json(content)},
+        extra = ${sql.json(unCamelObject(extra))},
+        test_values = ${sql.json(testValues)},
+        is_draft = ${isDraft}
+      where 
+        id = ${ctx.params.id}
+      returning *
+    `
+
+    ctx.body = updatedTemplateVersion
   },
 )
 

programming_language: Scala
filename: users.ts
change_type: ModificationType.MODIFY
diff: @@ -183,9 +183,21 @@ users.post("/", checkAccess("teamMembers", "create"), async (ctx: Context) => {
     select name, plan from org where id = ${orgId}
   `
 
+  if (
+    role !== "member" &&
+    role !== "admin" &&
+    (org.plan === "free" || org.plan === "pro")
+  ) {
+    ctx.throw(
+      401,
+      "Your plan doesn't allow you to access granular access control.",
+    )
+  }
+
   const [orgUserCountResult] = await sql`
     select count(*) from account where org_id = ${orgId}
   `
+
   const orgUserCount = orgUserCountResult.count
 
   const token = await signJWT({ email, orgId }, FIFTEEN_DAYS)

programming_language: TypeScript