CVE-2024-5131 (published 2024-06-06T19:16Z)

An Improper Access Control vulnerability exists in the lunary-ai/lunary repository, affecting versions up to and including 1.2.2. The vulnerability allows unauthorized users to view any prompts in any projects by supplying a specific prompt ID to an endpoint that does not adequately verify the ownership of the prompt ID. This issue was fixed in version 1.2.25.


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 15:47:48-03:00
msg: fix: api security (#331)
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: @@ -52,14 +52,27 @@ versions.get("/latest", async (ctx: Context) => {
 })
 
 versions.get("/:id", async (ctx: Context) => {
+  const { id: versionId } = ctx.params
+  const { projectId } = ctx.state
+
   const [version] = await sql`
-    select * from template_version where id = ${ctx.params.id}
+    select
+      tv.*
+    from
+      template_version tv
+      left join template t on tv.template_id = t.id
+      left join project p on t.project_id = p.id and p.id = ${projectId}
+    where
+      tv.id = ${versionId}
   `
+  if (!version) {
+    ctx.throw(401, "You do not have access to this ressource.")
+  }
 
   version.extra = unCamelObject(version.extra)
 
   const [template] = await sql`
-    select * from template where project_id = ${ctx.state.projectId} and id = ${version.templateId}
+    select * from template where project_id = ${projectId} and id = ${version.templateId}
   `
 
   ctx.body = { ...version, template }

programming_language: Scala