Skip to content

[Rule Tuning] Fix quoted KQL wildcards in four rules - #7216

Open
LiamCarPer wants to merge 2 commits into
elastic:mainfrom
LiamCarPer:fix/7214-kql-quoted-wildcards
Open

LiamCarPer wants to merge 2 commits into
elastic:mainfrom
LiamCarPer:fix/7214-kql-quoted-wildcards

Conversation

@LiamCarPer

@LiamCarPer LiamCarPer commented Nov 22, 2026 •

Copy link
Copy Markdown

Issue link(s): Fixes #7214

Summary - What I changed

KQL treats * inside double quotes as a literal character, so several prebuilt rule queries contained wildcard-looking values that could never match as patterns. This PR moves the wildcards outside the quoted values in the four affected rules:

  • rules/network/initial_access_splunk_postgres_recovery_body_injection.toml — unquotes the url.path recovery endpoint gate, the http.request.body.content filename/database markers, and the two status-400 url.path values. Embedded quotes are escaped as \".
  • rules/cross-platform/impact_destructive_aws_cli_execution_by_genai_agent.toml — unquotes the process.args --dry-run*, --help*, -help*, and --version* exclusions.
  • rules/cross-platform/discovery_cloud_offensive_framework_execution.toml — unquotes the *site-packages/pip* exclusion arm.
  • rules/windows/persistence_webshell_detection.toml — unquotes the WAMP Apache parent path, escaping the literal : as E\:/....

I also bumped updated_date to 2026/11/22 for each tuned rule and rebased the branch onto current main.

Per review feedback, I removed the rule-specific AST test from tests/test_specific_rules.py. The KQL AST can be iterated directly, and a hardcoded list of rules would be brittle; RTA coverage is the better long-term place for this. The rule changes are covered by the existing rule validation suite.

How To Test

$ source env/detection-rules-build/bin/activate
$ PYTHONPATH= python -m pytest tests/test_specific_rules.py -q
6 passed in 342.08s

$ PYTHONPATH= make lint
ruff check: All checks passed!
ruff format: 85 files already formatted
pyright: 0 errors, 0 warnings, 0 informations

$ PYTHONPATH= python -m detection_rules test
429 passed, 1 skipped, 417 subtests passed in 529.30s (0:08:49)

The PYTHONPATH= prefix only clears a local ROS pytest plugin that otherwise fails to load; it does not affect the repository code under test.

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 — I could not apply labels from the fork (GitHub returns 403, maintainer/admin rights required); please add Rule: Tuning.
  • Added the meta:rapid-merge label if planning to merge within 24 hours
  • Secret and sensitive material has been managed correctly (no credentials or tokens; exclusions use generic non-identifying vendor/install paths — not usernames, hostnames, org names, cluster/agent IDs, IP addresses, or internal workspace/repo trees; cloud/SaaS rules only hard-code vendor first-party or marketplace-listed app/client IDs — never tenant, subscription, account, or project IDs; sample JSON is redacted)
  • Automated testing was updated or added to match the most common scenarios
  • Documentation and comments were added for features that require explanation

Contributor checklist

@LiamCarPer
LiamCarPer marked this pull request as ready for review November 22, 2026 05:50
Copilot AI balanced review requested due to automatic review settings November 22, 2026 05:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@eric-forte-elastic eric-forte-elastic left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally I think this PR is fine, but the tests in tests/test_specific_rules.py can be simpler. You do not need a custom walk_ast() function. You can use can iterate over the object like this instead:

for node in rule.contents.data.ast:
    ...

Also, given that quoted "*" for literals may be desired, we may not want to have direct tests for this in the python test cases, it might be better served by using RTAs (as opposed to having to maintain a list of rules we want/do not want to test).

@botelastic botelastic Bot added Domain: Endpoint OS: Windows windows related rules labels Dec 1, 2026
Unquote wildcard values in KQL queries so the patterns match as wildcards instead of literal asterisks, as reported in elastic#7214. Escape literal colons and embedded quotes where the values are now unquoted, and add regression tests asserting these values parse as Wildcard nodes.
Address review feedback: the KQL AST can be iterated directly and a hardcoded rule list is brittle. The rule changes remain covered by the existing rule validation suite; RTA coverage is the better follow-up.
@LiamCarPer
LiamCarPer force-pushed the fix/7214-kql-quoted-wildcards branch from afca985 to 79dbb24 Compare December 1, 2026 04:40
@LiamCarPer

Copy link
Copy Markdown
Author

Thanks @eric-forte-elastic — I removed the rule-specific test class and the custom walk_ast helper. You are right that the AST can be iterated directly, and a hardcoded list of rules would be brittle; I agree that RTA coverage is the better place for this. The four rule changes are unchanged, and I have rebased the branch onto current main. I reran tests/test_specific_rules.py, make lint, and the full detection_rules test suite (429 passed, 1 skipped, 417 subtests), and updated the PR description to match. Happy to add RTA coverage as a follow-up if you would like.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Rule Tuning] KQL rules with quoted wildcards match only the literal string

3 participants