Skip to content

Commit a9c41b2

Browse files
committed
feat(api-gateway): queryTransformer security hook
1 parent f5578dd commit a9c41b2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/cubejs-api-gateway/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ class ApiGateway {
232232
this.logger = logger;
233233
this.checkAuthMiddleware = options.checkAuthMiddleware || this.checkAuth.bind(this);
234234
this.basePath = options.basePath || '/cubejs-api';
235+
// eslint-disable-next-line no-unused-vars
236+
this.queryTransformer = options.queryTransformer || (async (query, context) => query);
235237
}
236238

237239
initApp(app) {
@@ -245,7 +247,7 @@ class ApiGateway {
245247
type: 'Load Request',
246248
query: req.query.query
247249
});
248-
const normalizedQuery = normalizeQuery(query);
250+
const normalizedQuery = await this.queryTransformer(normalizeQuery(query), this.contextByReq(req));
249251
const [compilerSqlResult, metaConfigResult] = await Promise.all([
250252
this.getCompilerApi(req).getSql(coerceForSqlQuery(normalizedQuery, req)),
251253
this.getCompilerApi(req).metaConfig()
@@ -287,7 +289,7 @@ class ApiGateway {
287289
throw new UserError(`query param is required`);
288290
}
289291
const query = JSON.parse(req.query.query);
290-
const normalizedQuery = normalizeQuery(query);
292+
const normalizedQuery = await this.queryTransformer(normalizeQuery(query), this.contextByReq(req));
291293
const sqlQuery = await this.getCompilerApi(req).getSql(coerceForSqlQuery(normalizedQuery, req));
292294
res.json({
293295
sql: sqlQuery

packages/cubejs-server-core/core/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ class CubejsServerCore {
174174
this.getOrchestratorApi.bind(this),
175175
this.logger, {
176176
basePath: this.options.basePath,
177-
checkAuthMiddleware: this.options.checkAuthMiddleware
177+
checkAuthMiddleware: this.options.checkAuthMiddleware,
178+
queryTransformer: this.options.queryTransformer
178179
}
179180
);
180181
apiGateway.initApp(app);

0 commit comments

Comments
 (0)