CVE-2022-23510 (published 2022-12-09T23:15Z)

cube-js is a headless business intelligence platform. In version 0.31.23 all authenticated Cube clients could bypass SQL row-level security and run arbitrary SQL via the newly introduced /v1/sql-runner endpoint. This issue has been resolved in version 0.31.24. Users are advised to either upgrade to 0.31.24 or to downgrade to 0.31.22. There are no known workarounds for this vulnerability.

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

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/cube-js/cube.js
commit_details: repo_url: https://github.com/cube-js/cube.js
author: Mike Nitsenko
author_date: 2022-12-10 00:53:23+06:00
msg: Revert "feat(api-gateway, server-core): Added dataSources list to extended meta (#5743)" (#5785)

This reverts commit 2c5db32f2ded074ebe5e83668eee8c024101240b.
repository: repo_url: https://github.com/cube-js/cube.js
repo_name: cube-js/cube
description: 📊  Cube — The Semantic Layer for Building Data Applications
repo_language: Rust
owner: cube-js
file_changes: filename: gateway.ts
change_type: ModificationType.MODIFY
diff: @@ -448,7 +448,7 @@ class ApiGateway {
       const metaConfigExtended = await this.getCompilerApi(context).metaConfigExtended({
         requestId: context.requestId,
       });
-      const { metaConfig, cubeDefinitions, dataSources } = metaConfigExtended;
+      const { metaConfig, cubeDefinitions } = metaConfigExtended;
 
       const cubes = this.filterVisibleItemsInMeta(context, metaConfig)
         .map((meta) => meta.config)
@@ -466,7 +466,7 @@ class ApiGateway {
           joins: transformJoins(cubeDefinitions[cube.name]?.joins),
           preAggregations: transformPreAggregations(cubeDefinitions[cube.name]?.preAggregations),
         }));
-      res({ cubes, dataSources });
+      res({ cubes });
     } catch (e) {
       this.handleError({
         e,

programming_language: TypeScript
filename: CompilerApi.js
change_type: ModificationType.MODIFY
diff: @@ -66,10 +66,6 @@ export class CompilerApi {
     return this.compilers;
   }
 
-  async getDataSources(cubeEvaluator) {
-    return Promise.all(cubeEvaluator.cubeNames().map(async cube => cubeEvaluator.cubeFromPath(cube).dataSource ?? 'default'));
-  }
-
   async createQueryFactory(compilers) {
     const { cubeEvaluator } = compilers;
 
@@ -184,10 +180,9 @@ export class CompilerApi {
   }
 
   async metaConfigExtended(options) {
-    const { metaTransformer, cubeEvaluator } = await this.getCompilers(options);
+    const { metaTransformer } = await this.getCompilers(options);
     return {
       metaConfig: metaTransformer?.cubes,
-      dataSources: await this.getDataSources(cubeEvaluator),
       cubeDefinitions: metaTransformer?.cubeEvaluator?.cubeDefinitions,
     };
   }

programming_language: TypeScript
filename: index.test.ts
change_type: ModificationType.MODIFY
diff: @@ -52,34 +52,6 @@ cube('Bar', {
   ]),
 };
 
-const repositoryWithDataSource: SchemaFileRepository = {
-  localPath: () => __dirname,
-  dataSchemaFiles: () => Promise.resolve([
-    {
-      fileName: 'main.js', content: `
-cube('Bar', {
-  sql: 'select * from bar',
-  
-  measures: {
-    count: {
-      type: 'count'
-    }
-  },
-
-  dataSource: 'dataSource',
-
-  dimensions: {
-    time: {
-      sql: 'timestamp',
-      type: 'time'
-    }
-  }
-});
-`,
-    },
-  ]),
-};
-
 const repositoryWithoutContent: SchemaFileRepository = {
   localPath: () => __dirname,
   dataSchemaFiles: () => Promise.resolve([{ fileName: 'main.js', content: '' }]),
@@ -363,29 +335,6 @@ describe('index.test', () => {
       expect(metaConfigExtended).toHaveProperty('metaConfig');
       expect(metaConfigExtended.metaConfig.length).toBeGreaterThan(0);
       expect(metaConfigExtended).toHaveProperty('cubeDefinitions');
-      expect(metaConfigExtended).toHaveProperty('dataSources');
-      expect(metaConfigExtended.dataSources).toEqual(['default']);
-      expect(metaConfigExtendedSpy).toHaveBeenCalled();
-      metaConfigExtendedSpy.mockClear();
-    });
-  });
-  
-  describe('CompilerApi with dataSource', () => {
-    const logger = jest.fn(() => {});
-    const compilerApi = new CompilerApi(
-      repositoryWithDataSource,
-      async () => 'mysql',
-      { logger }
-    );
-    const metaConfigExtendedSpy = jest.spyOn(compilerApi, 'metaConfigExtended');
-
-    test('CompilerApi metaConfigExtended', async () => {
-      const metaConfigExtended = await compilerApi.metaConfigExtended({ requestId: 'XXX' });
-      expect(metaConfigExtended).toHaveProperty('metaConfig');
-      expect(metaConfigExtended.metaConfig.length).toBeGreaterThan(0);
-      expect(metaConfigExtended).toHaveProperty('cubeDefinitions');
-      expect(metaConfigExtended).toHaveProperty('dataSources');
-      expect(metaConfigExtended.dataSources).toEqual(['dataSource']);
       expect(metaConfigExtendedSpy).toHaveBeenCalled();
       metaConfigExtendedSpy.mockClear();
     });

programming_language: TypeScript
repo_url: https://github.com/cube-js/cube.js
commit_details: repo_url: https://github.com/cube-js/cube.js
author: Mike Nitsenko
author_date: 2022-12-10 00:48:41+06:00
msg: Revert "chore(cubejs-api-gateway): added endpoint to run sql query directly (#5723)" (#5784)

This reverts commit f1e25bb50323c0b99f3891d349467e7b637baeea.
repository: repo_url: https://github.com/cube-js/cube.js
repo_name: cube-js/cube
description: 📊  Cube — The Semantic Layer for Building Data Applications
repo_language: Rust
owner: cube-js
file_changes: filename: gateway.ts
change_type: ModificationType.MODIFY
diff: @@ -251,19 +251,6 @@ class ApiGateway {
       }
     }));
 
-    app.post(
-      `${this.basePath}/v1/sql-runner`,
-      jsonParser,
-      userMiddlewares,
-      async (req: Request, res: Response) => {
-        await this.sqlRunner({
-          query: req.body.query,
-          context: req.context!,
-          res: this.resToResultFn(res),
-        });
-      }
-    );
-
     app.get(`${this.basePath}/v1/run-scheduled-refresh`, userMiddlewares, (async (req, res) => {
       await this.runScheduledRefresh({
         queryingOptions: req.query.queryingOptions,
@@ -1083,54 +1070,6 @@ class ApiGateway {
     }
   }
 
-  public async sqlRunner({ query, context, res }: QueryRequest) {
-    const requestStarted = new Date();
-    try {
-      if (!query) {
-        throw new UserError(
-          'A user\'s query must contain a body'
-        );
-      }
-      
-      if (!(query as Record<string, any>).query) {
-        throw new UserError(
-          'A user\'s query must contain at least one query param.'
-        );
-      }
-
-      query = {
-        ...query,
-        requestId: context.requestId
-      };
-
-      this.log(
-        {
-          type: 'Load SQL Runner Request',
-          query,
-        },
-        context
-      );
-
-      const result = await this.getAdapterApi(context).executeQuery(query);
-
-      this.log(
-        {
-          type: 'Load SQL Runner Request Success',
-          query,
-          duration: this.duration(requestStarted),
-          dbType: result.dbType,
-        },
-        context
-      );
-
-      res(result);
-    } catch (e) {
-      this.handleError({
-        e, context, query, res, requestStarted
-      });
-    }
-  }
-
   protected createSecurityContextExtractor(options?: JWTOptions): SecurityContextExtractorFn {
     if (options?.claimsNamespace) {
       return (ctx: Readonly<RequestContext>) => {

programming_language: TypeScript
filename: index.test.ts
change_type: ModificationType.MODIFY
diff: @@ -339,58 +339,6 @@ describe('API Gateway', () => {
     expect(res.body.query.measures).toStrictEqual(['Foo.bar']);
   });
 
-  test('post http method for sql-runner route required params', async () => {
-    const { app } = createApiGateway();
-
-    const res = await request(app)
-      .post('/cubejs-api/v1/sql-runner')
-      .set('Content-type', 'application/json')
-      .set(
-        'Authorization',
-        'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
-      )
-      .send({})
-      .expect(400);
-
-    expect(res.body && res.body.error).toStrictEqual('A user\'s query must contain a body');
-
-    const res2 = await request(app)
-      .post('/cubejs-api/v1/sql-runner')
-      .set('Content-type', 'application/json')
-      .set(
-        'Authorization',
-        'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
-      )
-      .send({ query: { query: '' } })
-      .expect(400);
-
-    expect(res2.body && res2.body.error).toStrictEqual(
-      'A user\'s query must contain at least one query param.'
-    );
-  });
-
-  test('post http method for sql-runner route', async () => {
-    const { app } = createApiGateway();
-
-    const query = {
-      query: 'SELECT * FROM Foo',
-    };
-
-    const res = await request(app)
-      .post('/cubejs-api/v1/sql-runner')
-      .set('Content-type', 'application/json')
-      .set(
-        'Authorization',
-        'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
-      )
-      .send({ query })
-      .expect(200);
-
-    expect(res.body.data).toStrictEqual([
-      { foo__bar: 42 },
-    ]);
-  });
-
   test('meta endpoint to get schema information', async () => {
     const { app } = createApiGateway();
 

programming_language: TypeScript