Simple Detection Match Expression Reference
Construct match expressions to define logic
Overview
A match expression is a conditional logic expression, defined in YAML, that will return true
or false
. Match expressions are used various places, for example:
In the
Detection
key of a Simple Detection written in YAMLIn the
InlineFilters
key of a Python or Simple DetectionIn the
Expressions
key of a List Comprehension match expression (effectively creating match expressions within a match expression)In the
Conditions
key of theDynamicSeverities
key of a Simple Detection
There are seven types of match expressions, with varying structures. You can group match expressions using combinators to form complex conditions.
You can use enrichment in Simple Detections with enrichment match expressions.
How match expressions work
Match expressions work roughly the following way:
A key from an incoming event is identified with a key specifier
A condition is provided, which describes the nature of the check
A value (or list of values) is provided to compare against
(There are exceptions to this pattern, where zero or multiple event keys are identified for comparison, or no value is needed.)
Types of match expressions
There are seven types of match expressions, each with a unique syntax or structure.
The match expression examples in the following sections refer to this JSON event:
In each example match expression below, a single key specifier is used to identify the event key(s), however any of the key specifiers (e.g., Key
, DeepKey
or KeyPath
) can be used in most cases.
Key/value match expressions
Key/value match expressions compare the value of a certain event key to a given value.
You can see all allowed values of Condition
in the Scalar matching conditions table below, where the "Applicable Match Expressions" column includes "Key/value."
Example:
Key/values match expressions
Key/values match expressions evaluate whether some event value is a member in a given list.
The only permitted Condition
values for key/values match expressions are IsIn
and IsNotIn
, visible in the List matching conditions table below.
Example:
Multi-key match expressions
Multi-key match expressions cannot be viewed and edited in the Simple Detection builder in the Panther Console, nor can they be used in Inline Filters. See a full list of Simple Detection builder limitations here, and Inline Filters limitations here.
Multi-key match expressions allow you to compare the values of two event keys. You can form a multi-key match expression by including a Condition
and list of Values
that contains two event keys.
See all allowed values of Condition
in the Scalar matching conditions table below, where the "Applicable Match Expressions" column includes "Multi-key."
List comprehension match expressions
List comprehension match expressions cannot be viewed and edited in the Simple Detection builder in the Panther Console, nor can they be used in Inline Filters. See a full list of Simple Detection builder limitations here, and Inline Filters limitations here.
A list comprehension match expression takes a key with a list value, and, for each item in the list, evaluates it against a list of match expressions. The list of match expressions is stored under the Expressions
key.
For list comprehension match expressions, four values for Condition
are valid:
AnyElement
AllElements
OnlyOneElement
NoElement
Learn more about these Condition
values in the List comprehension conditions table below.
Example using AnyElement
:
Within the Expressions
key, you can add either:
Nested list comprehension match expressions. Each level of nesting can only contain one list comprehension match expression. This structure effectively creates nested for loops. The innermost list comprehension can have as many match expressions as you like, so long as they are not list comprehension match expressions. Example:
Any combination of match expressions that are not list comprehension match expressions. Example:
Existence match expressions
An existence match expression determines whether a specific key matches a specified existence condition.
See all allowed values of Condition
in the Scalar matching conditions table below, where the "Applicable Match Expressions" column includes "Existence."
Example:
Absolute match expressions
Absolute match expressions cannot be viewed and edited in the Simple Detection builder in the Panther Console, nor can they be used in Inline Filters. See a full list of Simple Detection builder limitations here, and Inline Filters limitations here.
In certain cases, you may want a match expression to always evaluate to True
or False
. You can do this by creating a match expression that simply contains a Condition
key set to AlwaysTrue
or AlwaysFalse
.
Enrichment match expressions
Enrichment match expressions cannot be viewed and edited in the Simple Detection builder in the Panther Console, nor can they be used in Inline Filters. See a full list of Simple Detection builder limitations here, and Inline Filters limitations here.
Enrichment match expressions are only used to interact with a JSON event's p_enrichment
struct, which is present if there is a match on a Lookup Table, Enrichment Provider, or Identify Provider Profile.
To create an enrichment match expression, include an Enrichment
key. The contents of Enrichment
indicate the path to the event key on which to build the condition. Within Enrichment
, include the following fields:
Table
: The name of the Lookup Table, Enrichment Provider table, or Identity Provider Profile table.These names are user-defined in the case of Lookup Tables, and Panther-defined in the case of Enrichment Providers and Identity Provider Profiles.
Selector
: The name of the selector field from the incoming log.FieldPath
: The name of any one of the event fields within theSelector
field. This key takes JSON path notation, meaning you can denote nested fields, if needed.
Once you have defined Enrichment
and its sub-fields, the rest of the match expression can be modeled after the structure of any of the other match expression types—except for List comprehension match expressions (these expressions are not supported for use with enrichment) and Absolute match expressions (these expressions do not reference any event values).
For example, the enrichment match expression below—which includes Condition
and Value
keys—resembles a key/value match expression:
Combinators
The OnlyOne
and None
combinators cannot be viewed and edited in the Simple Detection builder in the Panther Console, nor can they be used in Inline Filters. See a full list of Simple Detection builder limitations here, and Inline Filters limitations here.
Combinators are YAML keys that describe the relationship between match expressions or groups of match expressions. There are four combinators: All
, Any
, OnlyOne
, and None
.
If more than one match expression is provided directly under a key that takes match expressions (e.g., Detection
, InlineFilters
or Expressions
), and no combinator is specified, All
is assumed.
When writing Simple Detections in the CLI workflow, there is no limit on the number of nested levels you can create with combinators. (In the Simple Detection builder in the Panther Console, there is a three-level limit.) Note that if match expressions are nested more than three levels deep when working locally, the Panther Console will not render them in the Simple Detection builder—they will only be viewable in raw YAML.
Example of one level of nesting using OnlyOne
:
Example of multiple levels of nesting using Any
and All
:
Key specifiers
Key specifiers are a group of YAML keys that allow you to indicate a certain key in your log event JSON. There are three key specifiers: Key
, DeepKey
, and KeyPath
.
If the event property provided as the value of the key specifier does not exist, evaluation of the match expression stops and returns false.
Key
Key
Key
lets you access a top-level event property. Example:
DeepKey
DeepKey
DeepKey
lets you access a nested event property. DeepKey
accepts a list. You can also use DeepKey
to access elements of an array when you know the absolute index.
Example using DeepKey
, which accesses the deep field foo.bar.baz
, then indexes on an array index 2:
KeyPath
KeyPath
KeyPath
lets you access:
A top-level field
A nested field, using:
Subfield indexing (
.
)Array indexing: Use
[*]
for a wildcard across the array or[x]
for specific indices. Learn more about indexing an array of objects here.
Additional JSON path features are not supported.
Example:
Condition
Condition
There are various types of Condition
values you can choose from, including scalar, list, and list comprehension groupings.
Certain Condition
values cannot be viewed and edited in the Simple Detection builder in the Panther Console, nor can they be used in Inline Filters. See a full list of Simple Detection builder limitations here, and Inline Filters limitations here.
Scalar matching conditions
Use scalar matching conditions alongside the Value
key (not Values
). The match expression's key specifier can reference a list or a single value, but Value
must be singular.
List matching conditions
Use list matching conditions alongside Values
(not Value
). The match expression's key specifier can reference a single value or a list, but Values
must reference a list.
List comprehension conditions
List comprehension conditions can only be used within list comprehension match expressions.
Value(s)
Value(s)
Values for the Value
and Values
keys can have one of the following four data types:
Integer
Float
Boolean
String
Integers, floats, and booleans should not be enclosed in quotation marks. Strings can be enclosed in quotation marks, but do not have to be.
See examples of how differently formatted Value
values will evaluate below:
Last updated