Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Invalid kql query timeline refresh bug #105525

Merged
merged 4 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
timelineId,
toStr,
updateReduxTime,
disabled,
}) => {
const [recentlyUsedRanges, setRecentlyUsedRanges] = useState<EuiSuperDatePickerRecentRange[]>(
[]
Expand Down Expand Up @@ -201,6 +202,7 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
refreshInterval={duration}
showUpdateButton={true}
start={startDate}
isDisabled={disabled}
/>
);
},
Expand All @@ -216,6 +218,7 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
prevProps.startAutoReload === nextProps.startAutoReload &&
prevProps.stopAutoReload === nextProps.stopAutoReload &&
prevProps.timelineId === nextProps.timelineId &&
prevProps.disabled === nextProps.disabled &&
prevProps.toStr === nextProps.toStr &&
prevProps.updateReduxTime === nextProps.updateReduxTime &&
deepEqual(prevProps.kqlQuery, nextProps.kqlQuery) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,21 @@ export const QueryTabContentComponent: React.FC<Props> = ({
});

const isBlankTimeline: boolean =
isEmpty(dataProviders) && isEmpty(filters) && isEmpty(kqlQuery.query);

const canQueryTimeline = () =>
combinedQueries != null &&
loadingSourcerer != null &&
!loadingSourcerer &&
!isEmpty(start) &&
!isEmpty(end);
isEmpty(dataProviders) &&
isEmpty(filters) &&
isEmpty(kqlQuery.query) &&
combinedQueries?.filterQuery === undefined;

const canQueryTimeline = useMemo(
() =>
combinedQueries != null &&
loadingSourcerer != null &&
!loadingSourcerer &&
!isEmpty(start) &&
!isEmpty(end) &&
combinedQueries?.filterQuery !== undefined,
[combinedQueries, end, loadingSourcerer, start]
);

const getTimelineQueryFields = () => {
const columnsHeader = isEmpty(columns) ? defaultHeaders : columns;
Expand Down Expand Up @@ -264,7 +271,7 @@ export const QueryTabContentComponent: React.FC<Props> = ({
limit: itemsPerPage,
filterQuery: combinedQueries?.filterQuery,
startDate: start,
skip: !canQueryTimeline() || combinedQueries?.filterQuery === undefined,
skip: !canQueryTimeline,
sort: timelineQuerySortField,
timerangeKind,
});
Expand All @@ -290,6 +297,10 @@ export const QueryTabContentComponent: React.FC<Props> = ({
);
}, [loadingSourcerer, timelineId, isQueryLoading, dispatch]);

const isDatePickerDisabled = useMemo(() => {
return (combinedQueries && combinedQueries.kqlError != null) || false;
}, [combinedQueries]);

const leadingControlColumns: ControlColumnProps[] = [defaultControlColumn];
const trailingControlColumns: ControlColumnProps[] = [];

Expand All @@ -304,6 +315,7 @@ export const QueryTabContentComponent: React.FC<Props> = ({
inspect={inspect}
loading={isQueryLoading}
refetch={refetch}
skip={!canQueryTimeline}
/>
<FullWidthFlexGroup gutterSize="none">
<ScrollableFlexItem grow={2}>
Expand All @@ -323,7 +335,11 @@ export const QueryTabContentComponent: React.FC<Props> = ({
/>
)}
<DatePicker grow={1}>
<SuperDatePicker id="timeline" timelineId={timelineId} />
<SuperDatePicker
id="timeline"
timelineId={timelineId}
disabled={isDatePickerDisabled}
/>
</DatePicker>
<EuiFlexItem grow={false}>
<TimelineDatePickerLock />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TimelineRefetchProps {
inspect: inputsModel.InspectQuery | null;
loading: boolean;
refetch: inputsModel.Refetch;
skip?: boolean;
}

const TimelineRefetchComponent: React.FC<TimelineRefetchProps> = ({
Expand All @@ -26,12 +27,15 @@ const TimelineRefetchComponent: React.FC<TimelineRefetchProps> = ({
inspect,
loading,
refetch,
skip,
}) => {
const dispatch = useDispatch();

useEffect(() => {
dispatch(inputsActions.setQuery({ id, inputId, inspect, loading, refetch }));
}, [dispatch, id, inputId, loading, refetch, inspect]);
if (!skip) {
dispatch(inputsActions.setQuery({ id, inputId, inspect, loading, refetch }));
}
}, [dispatch, id, inputId, loading, refetch, inspect, skip]);

return null;
};
Expand Down