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] Exceptions flyout refreshes when it regains focus, causing configured fields to get cleared #166550

Closed
peluja1012 opened this issue Sep 14, 2023 · 12 comments
Assignees
Labels
bug Fixes for quality problems that affect the customer experience consider-next fixed impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. QA:Validated Issue has been validated by QA sdh-linked Team:Detection Engine Security Solution Detection Engine Area Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.12.0

Comments

@peluja1012
Copy link
Contributor

peluja1012 commented Sep 14, 2023

Describe the bug:
The Exception flyout refreshes and clears all configured fields when the browser loses and then regains focus.

Kibana/Elasticsearch Stack version:
8.10

Browser and Browser OS versions:
Chrome, MS Edge (originally reported)

Steps to reproduce:

  1. Click on "Add Rule Exception" either from an Alert from from the Rule Details page
  2. Add some values to the form. For example, title, and fields with AND conditions.
  3. Click on another tab on your browser so that the Exception flyout loses focus.
  4. Click on the main tab again so that the Exception flyout regains focus.
  5. Notice how the Exceptions flyout reloads, causing all configured fields to get cleared. You may have to repeat Steps 3 and 4 a couple of times before you see the unwanted behavior.

Screenshots (if relevant):

Screen.Recording.2023-09-14.at.5.19.44.PM.mov
@peluja1012 peluja1012 added bug Fixes for quality problems that affect the customer experience triage_needed Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Sep 14, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@peluja1012 peluja1012 added Team:Detections and Resp Security Detection Response Team Team:Detection Engine Security Solution Detection Engine Area labels Sep 15, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@peluja1012 peluja1012 added the impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. label Sep 15, 2023
@peluja1012
Copy link
Contributor Author

This bug is probably related to this other one, where you can see that additional calls to the /api/detection_engine/rules API are made whenever the flyout regains focus. #170081

@peluja1012
Copy link
Contributor Author

Another related and possible duplicate bug: #166759

@rylnd rylnd self-assigned this Nov 7, 2023
@rylnd
Copy link
Contributor

rylnd commented Nov 7, 2023

@e40pud since I'm on SDH today I'm investing this one, as it relates to a few tickets that came through. I will update here with my findings.

@rylnd
Copy link
Contributor

rylnd commented Nov 9, 2023

Alright, so I've traced the cause, but the solution is going to be more involved since it involves changing caching logic.

What's happening is that we have several useQuery hooks that are used within the RuleDetailsPage component that have a TTL of 5 minutes. Between that and the refetchOnWindowFocus being true by default, after a certain period of time has elapsed, focusing the tab will cause those queries to be fetched again, causing the RuleDetailsPage component to rerender.

The following diff will "fix" the problem by always caching those queries:

diff --git a/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_fetch_jobs_summary_query.ts b/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_fetch_jobs_summary_query.ts
index f2958de5a9a..477fa8fe838 100644
--- a/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_fetch_jobs_summary_query.ts
+++ b/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_fetch_jobs_summary_query.ts
@@ -24,7 +24,7 @@ export const useFetchJobsSummaryQuery = (
     async ({ signal }) => getJobsSummary({ signal, ...queryArgs }),
     {
       refetchIntervalInBackground: false,
-      staleTime: ONE_MINUTE * 5,
+      staleTime: Infinity,
       retry: false,
       ...options,
     }
diff --git a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_modules_query.ts b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_modules_query.ts
index 810801e96a5..4b8146a76c5 100644
--- a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_modules_query.ts
+++ b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_modules_query.ts
@@ -23,7 +23,7 @@ export const useFetchModulesQuery = (
     async ({ signal }) => getModules({ signal, ...queryArgs }),
     {
       refetchIntervalInBackground: false,
-      staleTime: ONE_MINUTE * 5,
+      staleTime: Infinity,
       retry: false,
       ...options,
     }
diff --git a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_recognizer_query.ts b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_recognizer_query.ts
index bd17b82cc56..f98799a482e 100644
--- a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_recognizer_query.ts
+++ b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_fetch_recognizer_query.ts
@@ -23,7 +23,7 @@ export const useFetchRecognizerQuery = (
     async ({ signal }) => checkRecognizer({ signal, ...queryArgs }),
     {
       refetchIntervalInBackground: false,
-      staleTime: ONE_MINUTE * 5,
+      staleTime: Infinity,
       retry: false,
       ...options,
     }

with these changes, I was able to re-focus the exceptions window after 10 minutes and not rerender/lose data. (Similarly, if you want to reliably reproduce the issue, change one of the above hooks to staleTime: 0, which will cause you to lose data after any refocus).

Next steps

  1. Can we simply address the issue by setting refetchOnWindowFocus: false for the above queries, or is it more nuanced than that? My understanding is that this should prevent the immediate issue, but if those queries are refetched via some other mechanism the issue will still occur. This leads to:
  2. Can we fix these hooks/component to rerender not based on query time but on actual contents?
  • In investigating the rerenders, they appear to be due to the query's internal state having its dataFetchedAt field updated, as opposed to actual security data having changed. Is this the expected behavior?

@e40pud
Copy link
Contributor

e40pud commented Nov 9, 2023

After thinking a bit about this issue, here are couple thoughts:

  1. Since we cannot guarantee that some queries won't be refetched we should fix the exception page to make sure that we preserve the state even between re-renders. I see that exception name and comment are still present after re-rendering. This way we will at least make sure the data loss does not happen.
  2. I was thinking that we probably want to set refetchOnWindowFocus: false to all our queries and if it is really needed to be true then we should discuss and think how to handle that individually. Or it can to be false based on different conditions, for example if we show flyout then main page should not be refetching queries on focus change.

The UI looks buggy with refetchOnWindowFocus: true, since we re-render page there is always some jumping of the content. I tried to disable refetchOnWindowFocus in whole security solution just to see the difference and UI behaves much better.

refetchOnWindowFocus: true

refetch-on-focus-true.mov

vs refetchOnWindowFocus: false

refetch-on-focus-false.mov

We most probably cannot just blindly disable refetchOnWindowFocus everywhere, but maybe we could walk through queries and make sure that we really need that option to be set to true.

@rylnd
Copy link
Contributor

rylnd commented Nov 9, 2023

That all makes sense to me, @e40pud! Let's see if we can address this at the exceptions component itself, and bring the refetchOnWindowFocus discussion to the larger D&R team.

@e40pud
Copy link
Contributor

e40pud commented Dec 6, 2023

To fix the state preservation properly would involve some refactoring of exception flyout components. This will take some time and will not fit FF phase.

Discussed with @yctercero and we will do a quick fix which matches current behaviour of the EditExceptionFlyout component where we avoid losing exception conditions state due to not doing conditional rendering of the ExceptionsConditions (the component which keeps conditions state). We will need to move conditions state to the parent component (AddExceptionFlyout and ExceptionsConditions) instead.

Refactoring will be prioritised in the next release https://github.com/elastic/security-team/issues/8197

e40pud added a commit to e40pud/kibana that referenced this issue Dec 6, 2023
e40pud added a commit that referenced this issue Dec 12, 2023
…, causing configured fields to get cleared (#166550) (#172666)

## Summary

Addresses #166550

These changes fix the issue where user can experience data loss while
adding rule exceptions.

The main issue is that we keep conditions state inside the child
component `ExceptionsConditions` which is rendered conditionally based
on `isLoading` flag. This flag changes when `useQuery` data gets stale
and refetching is triggered. In this case we would remove
`ExceptionsConditions` component while loading data and re-create it
after. Since conditions state stored inside `ExceptionsConditions` we
will lose it.

This is a quick fix to make sure our users are not frustrated. The state
refactoring will come separately in the next release when we are going
to address the main issue
elastic/security-team#8197

To reproduce:
1. Open "add rule exception" flyout
2. Add exception conditions
3. Wait for 5 minutes (to avoid waiting this long you can use [this
approach](#166550 (comment)))
4. Remove focus from the page (by switching to another app or navigating
to a different tab in a browser)
5. Focus on the page again

When you are back to the page all exception conditions should still be
there.

---------

Co-authored-by: Vitalii Dmyterko <[email protected]>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this issue Dec 12, 2023
…, causing configured fields to get cleared (elastic#166550) (elastic#172666)

## Summary

Addresses elastic#166550

These changes fix the issue where user can experience data loss while
adding rule exceptions.

The main issue is that we keep conditions state inside the child
component `ExceptionsConditions` which is rendered conditionally based
on `isLoading` flag. This flag changes when `useQuery` data gets stale
and refetching is triggered. In this case we would remove
`ExceptionsConditions` component while loading data and re-create it
after. Since conditions state stored inside `ExceptionsConditions` we
will lose it.

This is a quick fix to make sure our users are not frustrated. The state
refactoring will come separately in the next release when we are going
to address the main issue
elastic/security-team#8197

To reproduce:
1. Open "add rule exception" flyout
2. Add exception conditions
3. Wait for 5 minutes (to avoid waiting this long you can use [this
approach](elastic#166550 (comment)))
4. Remove focus from the page (by switching to another app or navigating
to a different tab in a browser)
5. Focus on the page again

When you are back to the page all exception conditions should still be
there.

---------

Co-authored-by: Vitalii Dmyterko <[email protected]>
(cherry picked from commit a0631cf)
kibanamachine added a commit that referenced this issue Dec 12, 2023
…s focus, causing configured fields to get cleared (#166550) (#172666) (#173131)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Security Solution] Exceptions flyout refreshes when it regains
focus, causing configured fields to get cleared (#166550)
(#172666)](#172666)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Ievgen
Sorokopud","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-12T09:14:57Z","message":"[Security
Solution] Exceptions flyout refreshes when it regains focus, causing
configured fields to get cleared (#166550) (#172666)\n\n##
Summary\r\n\r\nAddresses
https://github.com/elastic/kibana/issues/166550\r\n\r\nThese changes fix
the issue where user can experience data loss while\r\nadding rule
exceptions.\r\n\r\nThe main issue is that we keep conditions state
inside the child\r\ncomponent `ExceptionsConditions` which is rendered
conditionally based\r\non `isLoading` flag. This flag changes when
`useQuery` data gets stale\r\nand refetching is triggered. In this case
we would remove\r\n`ExceptionsConditions` component while loading data
and re-create it\r\nafter. Since conditions state stored inside
`ExceptionsConditions` we\r\nwill lose it.\r\n\r\nThis is a quick fix to
make sure our users are not frustrated. The state\r\nrefactoring will
come separately in the next release when we are going\r\nto address the
main
issue\r\nhttps://github.com/elastic/security-team/issues/8197\r\n\r\nTo
reproduce:\r\n1. Open \"add rule exception\" flyout\r\n2. Add exception
conditions\r\n3. Wait for 5 minutes (to avoid waiting this long you can
use
[this\r\napproach](https://github.com/elastic/kibana/issues/166550#issuecomment-1802941467))\r\n4.
Remove focus from the page (by switching to another app or
navigating\r\nto a different tab in a browser)\r\n5. Focus on the page
again\r\n\r\nWhen you are back to the page all exception conditions
should still be\r\nthere.\r\n\r\n---------\r\n\r\nCo-authored-by:
Vitalii Dmyterko
<[email protected]>","sha":"a0631cf8bd0ce820c1a3768f02e8384afc922b27","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:
SecuritySolution","backport:prev-minor","Team:Detection
Engine","v8.13.0"],"number":172666,"url":"https://github.com/elastic/kibana/pull/172666","mergeCommit":{"message":"[Security
Solution] Exceptions flyout refreshes when it regains focus, causing
configured fields to get cleared (#166550) (#172666)\n\n##
Summary\r\n\r\nAddresses
https://github.com/elastic/kibana/issues/166550\r\n\r\nThese changes fix
the issue where user can experience data loss while\r\nadding rule
exceptions.\r\n\r\nThe main issue is that we keep conditions state
inside the child\r\ncomponent `ExceptionsConditions` which is rendered
conditionally based\r\non `isLoading` flag. This flag changes when
`useQuery` data gets stale\r\nand refetching is triggered. In this case
we would remove\r\n`ExceptionsConditions` component while loading data
and re-create it\r\nafter. Since conditions state stored inside
`ExceptionsConditions` we\r\nwill lose it.\r\n\r\nThis is a quick fix to
make sure our users are not frustrated. The state\r\nrefactoring will
come separately in the next release when we are going\r\nto address the
main
issue\r\nhttps://github.com/elastic/security-team/issues/8197\r\n\r\nTo
reproduce:\r\n1. Open \"add rule exception\" flyout\r\n2. Add exception
conditions\r\n3. Wait for 5 minutes (to avoid waiting this long you can
use
[this\r\napproach](https://github.com/elastic/kibana/issues/166550#issuecomment-1802941467))\r\n4.
Remove focus from the page (by switching to another app or
navigating\r\nto a different tab in a browser)\r\n5. Focus on the page
again\r\n\r\nWhen you are back to the page all exception conditions
should still be\r\nthere.\r\n\r\n---------\r\n\r\nCo-authored-by:
Vitalii Dmyterko
<[email protected]>","sha":"a0631cf8bd0ce820c1a3768f02e8384afc922b27"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/172666","number":172666,"mergeCommit":{"message":"[Security
Solution] Exceptions flyout refreshes when it regains focus, causing
configured fields to get cleared (#166550) (#172666)\n\n##
Summary\r\n\r\nAddresses
https://github.com/elastic/kibana/issues/166550\r\n\r\nThese changes fix
the issue where user can experience data loss while\r\nadding rule
exceptions.\r\n\r\nThe main issue is that we keep conditions state
inside the child\r\ncomponent `ExceptionsConditions` which is rendered
conditionally based\r\non `isLoading` flag. This flag changes when
`useQuery` data gets stale\r\nand refetching is triggered. In this case
we would remove\r\n`ExceptionsConditions` component while loading data
and re-create it\r\nafter. Since conditions state stored inside
`ExceptionsConditions` we\r\nwill lose it.\r\n\r\nThis is a quick fix to
make sure our users are not frustrated. The state\r\nrefactoring will
come separately in the next release when we are going\r\nto address the
main
issue\r\nhttps://github.com/elastic/security-team/issues/8197\r\n\r\nTo
reproduce:\r\n1. Open \"add rule exception\" flyout\r\n2. Add exception
conditions\r\n3. Wait for 5 minutes (to avoid waiting this long you can
use
[this\r\napproach](https://github.com/elastic/kibana/issues/166550#issuecomment-1802941467))\r\n4.
Remove focus from the page (by switching to another app or
navigating\r\nto a different tab in a browser)\r\n5. Focus on the page
again\r\n\r\nWhen you are back to the page all exception conditions
should still be\r\nthere.\r\n\r\n---------\r\n\r\nCo-authored-by:
Vitalii Dmyterko
<[email protected]>","sha":"a0631cf8bd0ce820c1a3768f02e8384afc922b27"}}]}]
BACKPORT-->

Co-authored-by: Ievgen Sorokopud <[email protected]>
@e40pud e40pud added the fixed label Dec 12, 2023
@e40pud
Copy link
Contributor

e40pud commented Dec 12, 2023

@MadameSheema the fix was merged in both 8.12 and main (8.13)

@cybersecdiva cybersecdiva added the QA:Validated Issue has been validated by QA label Jan 13, 2024
@cybersecdiva
Copy link

cybersecdiva commented Jan 13, 2024

Tested in 8.12.0 BC6

Describe the bug:
The Exception flyout refreshes and clears all configured fields when the browser loses and then regains focus.

Kibana/Elasticsearch Stack version:
8.12.0

Server OS version:
N/A

Browser and Browser OS versions:

  • Firefox (Mac OS, Linux, and Windows)
  • Chrome (Mac OS, Linux, and Windows)
  • Edge

Steps to reproduce:

  1. Navigate to Security -> Alerts
  2. Select an Alert and More Actions -> Add Rule Exception
  3. Add rule exception name
  4. In the form, add a value OR condition value
  5. Click on another tab on your browser so that the Exception flyout loses focus
  6. Click on the main tab again so that the Exception flyout regains focus

Current behavior:
Condition state remains for exceptions flyout after refresh and focus regain and configured fields do not clear

Expected behavior:
Condition state remains for exceptions flyout after refresh and focus regain and configured fields do not clear

Screenshots (if relevant):

Screenshot of Rule Exception in 8.12.0 after refresh of tab and focus regain:
Screenshot 2024-01-12 at 6 29 10 PM

Screen share recordings:

Screen recording of behavior in 8.10.0

exceptionsflyout8.mp4

Screen recording of behavior in 8.12.0

exceptionlist.8.12.mp4

Errors in browser console (if relevant):
N/A

Provide logs and/or server output (if relevant):
N/A

Any additional context (logs, chat logs, magical formulas, etc.):
Behavior was tested on original 8.10.0 and on 8.12.0 deployment on browsers Firefox, Chrome, and Microsoft Edge and configured fields are not cleared
Validation ✅ for 8.12.0 BC6 fixed

@yctercero @e40pud FYI QA Validated fix ✅ Please confirm if expected behavior to align with your updated fix

@MadameSheema @vgomez-el FYI QA Validation of fix in 8.12.0 BC6

@vgomez-el
Copy link

I am closing this bug since it has been validated properly by @cybersecdiva on 8.12.0 BC6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience consider-next fixed impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. QA:Validated Issue has been validated by QA sdh-linked Team:Detection Engine Security Solution Detection Engine Area Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.12.0
Projects
Development

No branches or pull requests

7 participants