Skip to content

Commit

Permalink
sanitize create acceleration queries and direct queries
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 committed Mar 21, 2024
1 parent 76d206c commit 61143d8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/constants/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const ACCELERATION_ADD_FIELDS_TEXT = '(add fields here)';
export const ACCELERATION_INDEX_NAME_REGEX = /^[a-z0-9_]+$/;
export const ACCELERATION_S3_URL_REGEX = /^(s3|s3a):\/\/[a-zA-Z0-9.\-]+/;
export const SPARK_HIVE_TABLE_REGEX = /Provider:\s*hive/;
export const SANITIZE_QUERY_REGEX = /\s+/g;
export const TIMESTAMP_DATATYPE = 'timestamp';

export const ACCELERATION_INDEX_TYPES = [
Expand Down
11 changes: 8 additions & 3 deletions public/components/common/search/direct_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import {
EuiPopoverFooter,
EuiToolTip,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { isEmpty, isEqual } from 'lodash';
import React, { useEffect, useState } from 'react';
import { batch, useDispatch, useSelector } from 'react-redux';
import { i18n } from '@osd/i18n';
import { ASYNC_POLLING_INTERVAL, QUERY_LANGUAGE } from '../../../../common/constants/data_sources';
import {
ASYNC_POLLING_INTERVAL,
QUERY_LANGUAGE,
SANITIZE_QUERY_REGEX,
} from '../../../../common/constants/data_sources';
import {
APP_ANALYTICS_TAB_ID_REGEX,
RAW_QUERY,
Expand Down Expand Up @@ -223,9 +227,10 @@ export const DirectSearch = (props: any) => {
);
});
const sessionId = getAsyncSessionId(explorerSearchMetadata.datasources[0].label);
const requestQuery = tempQuery || query;
const requestPayload = {
lang: lang.toLowerCase(),
query: tempQuery || query,
query: requestQuery.replaceAll(SANITIZE_QUERY_REGEX, ' '),
datasource: explorerSearchMetadata.datasources[0].label,
} as DirectQueryRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { EuiButton } from '@elastic/eui';
import React, { useEffect, useState } from 'react';
import { SANITIZE_QUERY_REGEX } from '../../../../../../../../common/constants/data_sources';
import { CreateAccelerationForm } from '../../../../../../../../common/types/data_connections';
import {
DirectQueryLoadingStatus,
Expand Down Expand Up @@ -39,7 +40,7 @@ export const CreateAccelerationButton = ({

const requestPayload: DirectQueryRequest = {
lang: 'sql',
query: accelerationQueryBuilder(accelerationFormData),
query: accelerationQueryBuilder(accelerationFormData).replaceAll(SANITIZE_QUERY_REGEX, ' '),
datasource: accelerationFormData.dataSource,
};

Expand Down

0 comments on commit 61143d8

Please sign in to comment.