Skip to content

[Bug] Ignore Other Keep Wildcards#5792

Merged
eric-forte-elastic merged 6 commits intomainfrom
5764-bug-esql-hash-calc-should-ignore-all-keep-wildcards-not-only-keep
Mar 9, 2026
Merged

[Bug] Ignore Other Keep Wildcards#5792
eric-forte-elastic merged 6 commits intomainfrom
5764-bug-esql-hash-calc-should-ignore-all-keep-wildcards-not-only-keep

Conversation

@eric-forte-elastic
Copy link
Copy Markdown
Contributor

Pull Request

Issue link(s): #5764

Resolves #5764

Summary - What I changed

A small PR to change detection_rules/rule.py: extend _uses_keep_star() so it treats both “keep ” and “keep …” as wildcards. This will resolve version double bump issues due to the wildcard introducing new fields from different integration/stack versions.

This was the cause of the second double bump in #5761 (comment). See issue for more details.

Diff of detection_rules/rule.py vs main:

--- a/detection_rules/rule.py
+++ b/detection_rules/rule.py
@@ -1261,7 +1261,7 @@ 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 *`."""
+        """Check if this is an ES|QL rule that uses `| keep *` or fields ending with '*'."""
         if hashable_dict.get("language") != "esql":
             return False
 
@@ -1273,7 +1273,7 @@ class BaseRuleContents(ABC):
         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 any(field == "*" or field.endswith("*") for field in keep_fields)
         return False

How To Test

Unit tests to build package. Use the rule file Entra ID Federated Identity Credential Issuer Modified and set its min_stack version to 9.1 and check for double bumps when building a package.

Checklist

  • Added a label for the type of pr: bug, enhancement, schema, maintenance, Rule: New, Rule: Deprecation, Rule: Tuning, Hunt: New, or Hunt: Tuning so guidelines can be generated
  • Added the meta:rapid-merge label if planning to merge within 24 hours
  • Secret and sensitive material has been managed correctly
  • Automated testing was updated or added to match the most common scenarios
  • Documentation and comments were added for features that require explanation

Contributor checklist

@eric-forte-elastic eric-forte-elastic self-assigned this Feb 26, 2026
@eric-forte-elastic eric-forte-elastic added bug Something isn't working python Internal python for the repository labels Feb 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Bug - Guidelines

These guidelines serve as a reminder set of considerations when addressing a bug in the code.

Documentation and Context

  • Provide detailed documentation (description, screenshots, reproducing the bug, etc.) of the bug if not already documented in an issue.
  • Include additional context or details about the problem.
  • Ensure the fix includes necessary updates to the release documentation and versioning.

Code Standards and Practices

  • Code follows established design patterns within the repo and avoids duplication.
  • Ensure that the code is modular and reusable where applicable.

Testing

  • New unit tests have been added to cover the bug fix or edge cases.
  • Existing unit tests have been updated to reflect the changes.
  • Provide evidence of testing and detecting the bug fix (e.g., test logs, screenshots).
  • Validate that any rules affected by the bug are correctly updated.
  • Ensure that performance is not negatively impacted by the changes.
  • Verify that any release artifacts are properly generated and tested.
  • Conducted system testing, including fleet, import, and create APIs (e.g., run make test-cli, make test-remote-cli, make test-hunting-cli)

Additional Checks

  • Verify that the bug fix works across all relevant environments (e.g., different OS versions).
  • Confirm that the proper version label is applied to the PR patch, minor, major.

@eric-forte-elastic eric-forte-elastic marked this pull request as ready for review February 26, 2026 23:03
Copy link
Copy Markdown
Contributor

@Mikaayenson Mikaayenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple things to think about. otherwise lgtm

Comment thread detection_rules/rule.py
Comment thread detection_rules/rule.py
@eric-forte-elastic eric-forte-elastic merged commit 26d37dd into main Mar 9, 2026
17 checks passed
@eric-forte-elastic eric-forte-elastic deleted the 5764-bug-esql-hash-calc-should-ignore-all-keep-wildcards-not-only-keep branch March 9, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport: auto bug Something isn't working patch python Internal python for the repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ES|QL hash calc should ignore all keep wildcards (not only | keep *)

3 participants