-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Description
This issue was created using Cursor
Summary
When using POST /api/detection_engine/rules/_import with overwrite_exceptions=true, there is a race condition that causes false-positive alerts. Existing exception list items are deleted before new items are written back, creating a window where running rules see empty exception lists and generate alerts that should have been suppressed.
Expected Behavior
Importing rules and exceptions with overwrite flags should be an atomic-like operation. Running rules should never evaluate against partially-imported (empty) exception lists.
Actual Behavior
The overwrite flow in importExceptionLists deletes all existing exception list items first (deleteListItemsToBeOverwritten), then new items are imported in a separate subsequent step (importExceptionListItems). During this window, any enabled rule that fires will query the now-empty exception lists and produce alerts that should have been excluded.
Steps to Reproduce
- Create a detection rule with an exception list that excludes certain events
- Enable the rule so it runs on a schedule (e.g., every 5 minutes)
- Use the import API with
overwrite=trueandoverwrite_exceptions=trueto re-import the same rule and exceptions - If the rule fires during the import window (between exception item deletion and re-creation), alerts are generated for events that should be excluded
Root Cause
The exception overwrite uses a delete-then-recreate pattern with no transactional guarantees:
importExceptionLists()→ callsdeleteListItemsToBeOverwritten()to remove all items from overwritten listsimportExceptionListItems()→ writes new items back
Between steps 1 and 2, the exception lists exist but contain zero items. There is no mechanism to pause rules during import.