Query Language
The query language used by the rule service is a LISP style language: (<operator> <args>...).
Operators
The following are the operators
eq
(eq left right)
Equality comparison
contains
(contains needle haystack)
Text contains search (case-insensitive)
matches
(matches pattern target)
Regex pattern matching
any
(any needle expr)
Value search in JSON objects
and
(and expr1 expr2 ...)
Logical AND
or
(or expr1 expr2 ...)
Logical OR
not
(not expr)
Logical NOT
Equality (eq)
eq)Compares two values for exact equality.
(eq $.name "s3-encryption")
(eq $.type "security")
(eq $.version "1.0.0")
(eq $.annotations.stable true)Contains (contains)
contains)Searches for text within a field (case-insensitive).
Matches (matches)
matches)Uses regex patterns for matching.
Regex Flags:
i- Case insensitiveg- Global matchm- Multiline
Any (any)
any)Searches for a specific value within JSON data structures.
AND (and)
and)All conditions must be true.
OR (or)
or)At least one condition must be true.
NOT (not)
not)Negates a condition.
Fields
Each object has fields that can be referenced.
finding.name
Rule name
(eq finding.name "s3-encryption")
finding.shortName
Rule short name
(contains "s3" finding.shortName)
finding.type
Rule type
(eq finding.type "security")
finding.version
Rule version
(eq finding.version "1.0.0")
finding.iacLanguage
IaC language
(eq finding.iacLanguage "terraform")
finding.metadata
Rule metadata
(any "prod" finding.metadata)
finding.body
Rule body content
(contains "aws_s3_bucket" finding.body)
finding.annotations
Rule annotations
(eq finding.annotations.stable true)
finding.classification
Rule classifications
(any "CIS" finding.classification)
channel.name
Channel name
(eq channel.name "security-channel")
channel.query
Channel query
(contains "security" channel.query)
channel.filters
Channel filters
(contains "prod" channel.filters)
channel.accountId
Channel account ID
(eq channel.accountId "account-123")
classification.name
Classification name
(eq classification.name "CIS")
classification.parent
Parent classification
(eq classification.parent "Security")
classification.shortName
Classification short name
(contains "CIS" classification.shortName)
classification.description
Classification description
(contains "security" classification.description)
classification.annotations
Classification annotations
(eq classification.annotations.stable true)
Note: There is also a $ object which represents "this" and changes behavior based on what is being returned. If executed against rules then it is a finding, if executed against channels it is a channel, and if executed against classifications then it is a classification.
Data Types
String
"text"
"aws_s3_bucket"
Number
123 or -42.5
1 or 1000.0
Boolean
true or false
true
Null
null
null
Regex
/pattern/flags
/aws_.*/i
String Escaping
Use
\"for quotes:"He said \"Hello\""Use
\\for backslashes:"path\\to\\file"
Regex Escaping
Use
\/for forward slashes:/path\/to\/file/Use
\\for backslashes:/path\\to\\file/
Common Patterns
Find Rules by Resource Type
Exclude Test/Deprecated Rules
Note: The positive can also be used in a filter.
Complex Filtering
Troubleshooting
Common Issues
Query Syntax Errors
Ensure all parentheses are balanced
Use proper string escaping
Check operator argument counts
Field Not Found
Unknown fields default to
$.bodysearchUse dot notation for nested fields
Check field names in the reference table
Regex Issues
Use proper escaping for special characters
Add flags like
ifor case-insensitive matchingTest regex patterns separately
any()Function IssuesError:
any() requires exactly 2 argsSolution: Use
(any needle field)for single values, or useORfor multiple values
Memory Errors: Complex JSON searches can cause out-of-memory
Solution: Break complex queries into smaller parts or use alternatives like
contains
Performance Considerations
Use specific field references when possible
Avoid overly complex nested queries
Consider using
containsoveranyfor simple text searchesBe cautious with
anyon very large JSON structures
Debugging Tips
Start Simple: Begin with basic queries and add complexity gradually
Test Components: Test individual parts of complex queries
Use Examples: Reference the examples in this guide
Check Syntax: Ensure proper S-Expression syntax
Last updated