CVE-2022-23510 (TypeScript, published 2022-12-09T23:15Z)
Description: value: 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.
Severity: nan (CVSS v3 base score: 8.8)
Weakness: CWE-89 \u2014 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
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.
Repository: https://github.com/cube-js/cube.js
Files changed:
packages/cubejs-api-gateway/src/gateway.ts
packages/cubejs-server-core/src/core/CompilerApi.js
packages/cubejs-server-core/test/unit/index.test.ts
Commit message: Revert "feat(api-gateway, server-core): Added dataSources list to extended meta (#5743)" (#5785)

This reverts commit 2c5db32f2ded074ebe5e83668eee8c024101240b.

Vulnerable code:
      const { metaConfig, cubeDefinitions, dataSources } = metaConfigExtended;
      res({ cubes, dataSources });
  async getDataSources(cubeEvaluator) {
    return Promise.all(cubeEvaluator.cubeNames().map(async cube => cubeEvaluator.cubeFromPath(cube).dataSource ?? 'default'));
  }

    const { metaTransformer, cubeEvaluator } = await this.getCompilers(options);
      dataSources: await this.getDataSources(cubeEvaluator),
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'
    }
  }
});
`,
    },
  ]),
};

      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']);

Fixed code:
      const { metaConfig, cubeDefinitions } = metaConfigExtended;
      res({ cubes });
    const { metaTransformer } = await this.getCompilers(options);