Developer Reference: Apply these practices to create maintainable, performant, and reliable security detection logic.
Rule Development Best Practices
1. Start Simple and Iterate
- Begin with basic conditions that identify the threat
- Test with known-good and known-bad examples
- Add complexity incrementally
- Validate each addition before proceeding
- Document reasoning for complex logic
2. Be Specific with Data Types
- Only include relevant data types
- Avoid using too many data types in one rule
- Create separate rules for different data sources when logic differs
3. Handle Missing Data Gracefully
- Always check field existence with
has()orexists() - Use
safe()with sensible defaults - Test with incomplete events
- Consider what happens when fields are missing
4. Optimize Performance
Limit Data Scope
- Narrow
dataTypesselection - Use specific index patterns
- Reduce time windows when possible
Efficient Expressions
- Put cheapest checks first
- Avoid complex string operations
- Cache repeated calculations
Smart Correlation
- Limit
afterEventssearches - Use reasonable count thresholds
- Set appropriate time windows
Proper Deduplication
- Include key identifying fields
- Avoid time-based fields
- Balance between noise and visibility
5. Implement Effective Deduplication
6. Write Clear Descriptions
Include in Description:
- What the rule detects
- Why it’s important
- What action should be taken
- Known limitations or false positive scenarios
- Related rules or techniques
- MITRE ATT&CK technique IDs
- CVE numbers
- Security advisories
- Internal documentation
Filter Development Best Practices
1. Standardize Field Names
Use UTMStack Standard Fields:
origin.ip,origin.port,origin.user,origin.hosttarget.ip,target.port,target.user,target.hostdeviceTime- Event timestampaction- Normalized action (get, post, login, etc.)actionResult- Result (success, failure, denied, accepted)protocol- Network protocolseverity- Event severity
- Consistent queries across data sources
- Rules work with multiple data types
- Dashboards work universally
- Easier correlation
2. Parsing Strategy
3. Optimize Grok Patterns
Pattern Design:
- Use specific patterns over generic ones
- Order patterns from most to least specific
- Test patterns with real data
- Avoid greedy patterns when possible
- Use built-in patterns
4. Conditional Processing
5. Remove Unnecessary Fields Early
6. Handle Edge Cases
Common Edge Cases:
- Missing fields
- Malformed data
- Empty strings
- Null values
- Unexpected formats
- Special characters
- Encoding issues
Testing Strategies
Rule Testing
1
Unit Testing
Test individual conditions with sample events
2
Integration Testing
Deploy to development environment
- Monitor for alerts
- Verify alert content
- Check performance impact
3
Load Testing
Test with realistic event volumes
- Monitor CPU and memory usage
- Check for bottlenecks
- Verify deduplication works
4
False Positive Testing
Run against historical data
- Identify false positives
- Refine conditions
- Add exclusions
Filter Testing
1
Sample Data Testing
Test with representative samples
- Valid formatted data
- Malformed data
- Edge cases
2
Field Validation
Verify output fields
- Check field names match standards
- Verify data types are correct
- Ensure required fields exist
3
Performance Testing
Measure processing time
- Test with various event sizes
- Monitor resource usage
- Optimize slow steps
Performance Optimization
Rule Optimization Checklist
- Limit
dataTypesto necessary types only - Use efficient CEL expressions
- Put cheapest conditions first in
where - Limit
afterEventssearch count and time window - Use appropriate index patterns (specific vs wildcard)
- Implement proper deduplication
- Avoid excessive regex patterns
- Test with realistic event volumes
Filter Optimization Checklist
- Delete unnecessary fields early
- Use conditional steps with
where - Optimize grok patterns (specific over generic)
- Minimize number of parsing steps
- Cache expensive operations
- Use efficient data type conversions
- Remove debug/temporary fields
- Test filter performance with real data