CVE-2023-35167 (published 2023-06-23T20:15Z)

Remult is a CRUD framework for full-stack TypeScript. If you used the apiPrefilter option of the `@Entity` decorator, by setting it to a function that returns a filter that prevents unauthorized access to data, an attacker who knows the `id` of an entity instance is not authorized to access, can gain read, update and delete access to it. The issue is fixed in version 0.20.6. As a workaround, set the `apiPrefilter` option to a filter object instead of a function.

CVSS v3 base score: 6.3, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L)

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/remult/remult
commit_details: repo_url: https://github.com/remult/remult
author: Noam Honig
author_date: 2023-06-19 18:50:12+03:00
msg: fixed api prefilter
repository: repo_url: https://github.com/remult/remult
repo_name: remult/remult
description: Full-stack CRUD, simplified, with SSOT TypeScript entities
repo_language: TypeScript
owner: remult
file_changes: filename: CHANGELOG.md
change_type: ModificationType.MODIFY
diff: @@ -2,6 +2,10 @@
 
 All notable changes to this project will be documented in this file.
 
+## [0.20.6] - 2023-06-19
+
+- Fixed an issue when apiPrefilter was an arrow function, it did not affect get of a specific resource
+
 ## [0.20.5] - 2023-06-11
 
 - fixed issue #200 transactions on mongo db

programming_language: Markdown
filename: remult-mongo.d.ts
change_type: ModificationType.MODIFY
diff: @@ -1,11 +1,19 @@
-import type { MongoClient, Db } from 'mongodb';
+import type { MongoClient, Db, ClientSession } from 'mongodb';
 import { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, Remult } from '.';
 import { RepositoryOverloads } from './src/remult3';
 export declare class MongoDataProvider implements DataProvider {
     private db;
     private client;
-    constructor(db: Db, client: MongoClient);
-    static getDb(remult?: Remult): Db;
+    constructor(db: Db, client: MongoClient, options?: {
+        session?: ClientSession;
+        disableTransactions?: boolean;
+    });
+    session?: ClientSession;
+    disableTransactions: boolean;
+    static getDb(remult?: Remult): {
+        db: Db;
+        session: ClientSession;
+    };
     getEntityDataProvider(entity: EntityMetadata<any>): EntityDataProvider;
     transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
     static filterToRaw<entityType>(entity: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>): Promise<{

programming_language: TypeScript
filename: db-tests-setup.d.ts
change_type: ModificationType.MODIFY
diff: @@ -13,6 +13,7 @@ export declare function testInMemory(key: string, what: dbTestWhatSignature, foc
 export declare const TestDbs: {
     restDataProvider: string;
     mongo: string;
+    inMemory: string;
 };
 export declare type dbTestWhatSignature = ((db: {
     db: DataProvider;

programming_language: TypeScript
filename: data-api.ts
change_type: ModificationType.MODIFY
diff: @@ -195,10 +195,16 @@ export class DataApi<T = any> {
   private async doOnId(response: DataApiResponse, id: any, what: (row: T) => Promise<void>) {
     try {
 
-
+      var where: EntityFilter<any>[] = [this.repository.metadata.idMetadata.getIdFilter(id)];
+      if (this.repository.metadata.options.apiPrefilter) {
+        if (typeof this.repository.metadata.options.apiPrefilter === "function")
+          where.push(await this.repository.metadata.options.apiPrefilter());
+        else
+          where.push(this.repository.metadata.options.apiPrefilter);
+      }
 
       await this.repository.find({
-        where: { $and: [this.repository.metadata.options.apiPrefilter, this.repository.metadata.idMetadata.getIdFilter(id)] } as EntityFilter<any>
+        where: { $and: where } as EntityFilter<any>
       })
         .then(async r => {
           if (r.length == 0)

programming_language: TypeScript
filename: predefined-filter.spec.ts
change_type: ModificationType.MODIFY
diff: @@ -131,6 +131,21 @@ describe("data api", () => {
     await api.put(t, 1, { name: 'YAEL' });
     d.test();
   });
+  it("put id 1 works with predefined filterand shouldnt return anything", async () => {
+    let [c, remult] = await createData(async (i) => {
+      await i(1, 'noam', 'a');
+      await i(2, 'yael', 'b');
+      await i(3, 'yoni', 'a');
+    }, CategoriesForThisTest2);
+    var api = new DataApi(c, remult);
+    let t = new TestDataApiResponse();
+    let d = new Done();
+    t.notFound = () => {
+      d.ok();
+    };
+    await api.put(t, 1, { name: 'YAEL' });
+    d.test();
+  });
   it("getArray works with predefined filter", async () => {
     let [c, remult] = await createData(async (i) => {
       await i(1, 'noam', 'a');

programming_language: TypeScript
filename: products.component.ts
change_type: ModificationType.MODIFY
diff: @@ -42,7 +42,11 @@ export class ProductsComponent {
 
 }
 
-@Entity("categories", { allowApiRead: false })
+@Entity<Category>("categories", {
+  allowApiCrud: true, apiPrefilter: () => ({
+    id: { $ne: "clj30u9o500000kr3956ph9ep" }
+  })
+})
 export class Category {
   @Fields.cuid()
   id = ''

programming_language: TypeScript