-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 Bug #99442
[Security Solution] Invalid KQL Query Bug #99442
Conversation
@@ -70,6 +70,9 @@ const escapeSpecialCharacters = (val: string) => val.replace(/["]/g, '\\$&'); // | |||
|
|||
export const escapeKuery = flow(escapeSpecialCharacters, escapeWhitespace); | |||
|
|||
/** | |||
* Deprecated in leiu of `convertToBuildEsQueryOrError` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not lucky because only spellings that I can fix are the french ones ;)
* Deprecated in leiu of `convertToBuildEsQueryOrError` | |
* Deprecated in lieu of `convertToBuildEsQueryOrError` |
@@ -80,7 +83,7 @@ export const convertToBuildEsQuery = ({ | |||
indexPattern: IIndexPattern; | |||
queries: Query[]; | |||
filters: Filter[]; | |||
}) => { | |||
}): string | undefined => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just thinking out loud here, instead of creating convertToBuildEsQueryOrError
, I am wondering if convertToBuildEsQuery
can return a type like that [string | undefined, Error | undefined]
or we can even be stricter [string, undefined] | [undefined, Error]
Since we are changing the type, we can do a little more to avoid the deprecation and this will also avoid to call esQuery.buildEsQuery
twice to get the error and it will simplify your new hook useInvalidFilterQuery
to display the error. I am always scared of function that can return the valid answer or an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do that, i think that's a good idea to condense the two and update inline instead of creating the new function. @spong @andrew-goldstein thoughts?
5a96e57
to
c702648
Compare
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
a85c258
to
05a8f68
Compare
@@ -199,7 +202,7 @@ const HostsComponent = () => { | |||
deleteQuery={deleteQuery} | |||
docValueFields={docValueFields} | |||
to={to} | |||
filterQuery={tabsFilterQuery} | |||
filterQuery={tabsFilterQuery || ''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right approach here? Our plan was to skip the tab filter queries so this just continues the logic that was in place before, just further down the line
} | ||
// This disable is required to only trigger the toast once per render | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [filterQuery, addError]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can go for it and add addError
as a dependency, because you won't have kqlError != null
Thanks for this thoughtful, surgical fix @dplumlee! I'm seeing an unexpected result that doesn't appear to be introduced by this PR, but the fix makes the unexpected result more obvious:
Expected result:
Expected result:
Actual result:
Additional observations:
|
@andrew-goldstein good catch 🎣 as always. @dplumlee I think to fix this behavior without you going crazy, will be to override the refetch function to show the toaster again. |
There appears to be a similar statefulness issue with the Inspect action:
Expected result:
Expected result:
Actual result:
Expected results:
Actual results:
|
In the (specific) case of a KQL syntax error, the internal Kibana stack trace of the error that was thrown will not be useful to the user. All the relevant feedback is contained in the Consider, if this suggestion doesn't introduce significant complexity, eliminating the stack trace in the screenshot above, by displaying only the |
x-pack/plugins/security_solution/public/common/lib/keury/index.ts
Outdated
Show resolved
Hide resolved
Hi team! Thanks for working on this :) BC5 has been already shipped, last BC (BC6) is planned for next week. If you think that this fix is risky, we should probably wait for 7.13.1. |
As a team, we've collaborated and iterated on the fix to minimize risk, and we are all still in agreement it should be included in the final BC. I'm also thoroughly desk testing it as part of the review. @MadameSheema, would you be willing to coordinate with the team such that the fix is tested as soon as it's merged to |
Thanks for the heads up @andrew-goldstein :) I'll coordinate with the team to make sure this issue is tested on master as soon as is merged. |
ea839a8
to
9543753
Compare
useEffect(() => { | ||
if (filterQuery === undefined && kqlError != null) { | ||
// Removes error stack from user view | ||
delete kqlError.stack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we might avoid mutating the kqlError
arg, because consumers of the hook are probably not expecting this side effect.
As an alternative to using delete
to remove the stack
, I would typically recommend using a utility function like omit
from lodash/fp
, because it's guaranteed not to mutate the original, and it's less verbose than the native TS alternative. Unfortunately when I tried that, the error toaster didn't behave as expected, because the implementation of addError
uses IEsError
in a TS type guard.
I experimented with a few different options for safely cloning and/or constructing a new error (that omits the stack
), but each path I explored had some unexpected "gotchas".
To keep this PR moving forward, consider documenting the side effect of mutating kqlError
if we can't reasonably eliminate it.
985e3cc
to
02dd544
Compare
It looks like the KPIs in Timeline are showing unexpected results when a
Expected result:
Expected results:
Above: The KPIs are displayed with -s when Timeline is first opened, because there are no matching documents Actual result:
|
e273995
to
d3805a6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing two unexpected behaviors in Timeline:
- Clicking the
Refresh
button while the query is invalid sometimes (other times it hangs, per#2
, below) refreshes the grid with invalid results:
- Clicking the
Refresh
button when the query is invalid sometimes causes timeline to hang forever in the "Loading Events..." state:
💚 Build SucceededMetrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: cc @dplumlee |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your effort on this fix @dplumlee!
Per a discussion with @peluja1012, let's merge this immediately ahead of the BC that's about to be built, and fix the last known issue in a follow-up PR
LGTM
💔 Backport failed
To backport manually run: |
## Summary Addresses elastic#98283 Currently, our method of converting KQL to Elasticsearch queries silently suppresses errors bubbled up by ES and returns an empty query string. This makes it so the entire query, including filters, etc. gets wiped out and potentially incorrect data is displayed. This PR addresses that by bubbling up the errors and putting them in a toast component as well as cancelling any request that was made with the invalid query so that incorrect data is never fetched. ![Screen Shot 2021-05-11 at 5 05 24 PM](https://user-images.githubusercontent.com/56367316/117895214-e8bf9500-b28b-11eb-83a6-522deebecbe2.png) ### Checklist Delete any items that are not applicable to this PR. - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
## Summary Addresses elastic#98283 Currently, our method of converting KQL to Elasticsearch queries silently suppresses errors bubbled up by ES and returns an empty query string. This makes it so the entire query, including filters, etc. gets wiped out and potentially incorrect data is displayed. This PR addresses that by bubbling up the errors and putting them in a toast component as well as cancelling any request that was made with the invalid query so that incorrect data is never fetched. ![Screen Shot 2021-05-11 at 5 05 24 PM](https://user-images.githubusercontent.com/56367316/117895214-e8bf9500-b28b-11eb-83a6-522deebecbe2.png) ### Checklist Delete any items that are not applicable to this PR. - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
## Summary Addresses #98283 Currently, our method of converting KQL to Elasticsearch queries silently suppresses errors bubbled up by ES and returns an empty query string. This makes it so the entire query, including filters, etc. gets wiped out and potentially incorrect data is displayed. This PR addresses that by bubbling up the errors and putting them in a toast component as well as cancelling any request that was made with the invalid query so that incorrect data is never fetched. ![Screen Shot 2021-05-11 at 5 05 24 PM](https://user-images.githubusercontent.com/56367316/117895214-e8bf9500-b28b-11eb-83a6-522deebecbe2.png) ### Checklist Delete any items that are not applicable to this PR. - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) Co-authored-by: Davis Plumlee <[email protected]>
## Summary Addresses #98283 Currently, our method of converting KQL to Elasticsearch queries silently suppresses errors bubbled up by ES and returns an empty query string. This makes it so the entire query, including filters, etc. gets wiped out and potentially incorrect data is displayed. This PR addresses that by bubbling up the errors and putting them in a toast component as well as cancelling any request that was made with the invalid query so that incorrect data is never fetched. ![Screen Shot 2021-05-11 at 5 05 24 PM](https://user-images.githubusercontent.com/56367316/117895214-e8bf9500-b28b-11eb-83a6-522deebecbe2.png) ### Checklist Delete any items that are not applicable to this PR. - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) Co-authored-by: Davis Plumlee <[email protected]>
Summary
Addresses #98283
Currently, our method of converting KQL to Elasticsearch queries silently suppresses errors bubbled up by ES and returns an empty query string. This makes it so the entire query, including filters, etc. gets wiped out and potentially incorrect data is displayed.
This PR addresses that by bubbling up the errors and putting them in a toast component as well as cancelling any request that was made with the invalid query so that incorrect data is never fetched.
Checklist
Delete any items that are not applicable to this PR.
For maintainers