Ignore Keep * for ES|QL hash calc (#5638)

* Ignore Keep * for ES|QL hash calc

Co-authored-by: Mika Ayenson, PhD <Mikaayenson@users.noreply.github.com>

---------

Co-authored-by: Mika Ayenson, PhD <Mikaayenson@users.noreply.github.com>

(cherry picked from commit d252cae4ee)
This commit is contained in:
Eric Forte
2026-01-27 23:01:27 -05:00
committed by tradebot-elastic
parent 08a9a3244e
commit 1bfe4e4146
2 changed files with 22 additions and 1 deletions
+21
View File
@@ -1259,6 +1259,22 @@ class BaseRuleContents(ABC):
return obj
def _uses_keep_star(self, hashable_dict: dict[str, Any]) -> bool:
"""Check if this is an ES|QL rule that uses `| keep *`."""
if hashable_dict.get("language") != "esql":
return False
query: str | None = hashable_dict.get("query")
if not isinstance(query, str) or not query:
return False
keep_pattern = re.compile(r"\|\s*keep\b\s+([^\|]+)", re.IGNORECASE | re.DOTALL)
keep_match: re.Match[str] | None = keep_pattern.search(query)
if keep_match:
keep_fields: list[str] = [field.strip() for field in keep_match.group(1).split(",")]
return "*" in keep_fields
return False
@abstractmethod
def to_api_format(self, include_version: bool = True) -> dict[str, Any]:
"""Convert the rule to the API format."""
@@ -1273,6 +1289,11 @@ class BaseRuleContents(ABC):
if not include_integrations:
hashable_dict.pop("related_integrations", None)
# For ES|QL rules with `| keep *`, exclude required_fields since they're
# non-deterministic (depend on integration schemas which vary by stack version)
if self._uses_keep_star(hashable_dict):
hashable_dict.pop("required_fields", None)
return hashable_dict
@cached
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "detection_rules"
version = "1.5.35"
version = "1.5.36"
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Securitys Detection Engine."
readme = "README.md"
requires-python = ">=3.12"