Skip to content

Commit

Permalink
feat(api-gateway): queryTransformer security hook
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Jun 20, 2019
1 parent f5578dd commit a9c41b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class ApiGateway {
this.logger = logger;
this.checkAuthMiddleware = options.checkAuthMiddleware || this.checkAuth.bind(this);
this.basePath = options.basePath || '/cubejs-api';
// eslint-disable-next-line no-unused-vars
this.queryTransformer = options.queryTransformer || (async (query, context) => query);
}

initApp(app) {
Expand All @@ -245,7 +247,7 @@ class ApiGateway {
type: 'Load Request',
query: req.query.query
});
const normalizedQuery = normalizeQuery(query);
const normalizedQuery = await this.queryTransformer(normalizeQuery(query), this.contextByReq(req));
const [compilerSqlResult, metaConfigResult] = await Promise.all([
this.getCompilerApi(req).getSql(coerceForSqlQuery(normalizedQuery, req)),
this.getCompilerApi(req).metaConfig()
Expand Down Expand Up @@ -287,7 +289,7 @@ class ApiGateway {
throw new UserError(`query param is required`);
}
const query = JSON.parse(req.query.query);
const normalizedQuery = normalizeQuery(query);
const normalizedQuery = await this.queryTransformer(normalizeQuery(query), this.contextByReq(req));
const sqlQuery = await this.getCompilerApi(req).getSql(coerceForSqlQuery(normalizedQuery, req));
res.json({
sql: sqlQuery
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-server-core/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ class CubejsServerCore {
this.getOrchestratorApi.bind(this),
this.logger, {
basePath: this.options.basePath,
checkAuthMiddleware: this.options.checkAuthMiddleware
checkAuthMiddleware: this.options.checkAuthMiddleware,
queryTransformer: this.options.queryTransformer
}
);
apiGateway.initApp(app);
Expand Down

0 comments on commit a9c41b2

Please sign in to comment.