Incorrect null
handling in if
conditions and elsewhere
#8646
Labels
bug
Something isn't working, use only for issues
Integration:atlassian_bitbucket
Atlassian Bitbucket
Integration:atlassian_confluence
Atlassian Confluence
Integration:atlassian_jira
Atlassian Jira
Integration:aws
AWS
Integration:box_events
Box Events
Integration:cisco_asa
Cisco ASA
Integration:cisco_ftd
Cisco FTD
Integration:cisco_ise
Cisco ISE
Integration:cisco_meraki
Cisco Meraki
Integration:cisco_nexus
Cisco Nexus
Integration:cisco_secure_endpoint
Cisco Secure Endpoint
Integration:cloudflare_logpush
Cloudflare Logpush
Integration:cloudflare
Cloudflare
Integration:cyberarkpas
CyberArk Privileged Access Security
Integration:elastic_package_registry
Elastic Package Registry
Integration:elasticsearch
Elasticsearch
Integration:fortinet_fortigate
Fortinet FortiGate Firewall Logs
Integration:github
GitHub
Integration:hid_bravura_monitor
Bravura Monitor
Integration:infoblox_nios
Infoblox NIOS
Integration:jamf_compliance_reporter
Jamf Compliance Reporter
Integration:juniper_srx
Juniper SRX
Integration:mattermost
Mattermost
Integration:microsoft_defender_endpoint
Microsoft Defender for Endpoint
Integration:mimecast
Mimecast
Integration:nagios_xi
Nagios XI
Integration:panw_cortex_xdr
Palo Alto Cortex XDR
Integration:pfsense
pfSense
Integration:ping_one
PingOne
Integration:proofpoint_tap
Proofpoint TAP
Integration:salesforce
Salesforce
Integration:suricata
Suricata
Integration:tenable_sc
Tenable Security Center
Integration:ti_cif3
Collective Intelligence Framework v3
Integration:trendmicro
Trend Micro Deep Security
Integration:vectra_detect
Vectra Detect
Integration:zeek
Zeek
Integration:zoom
Zoom
Team:Security-Deployment and Devices
Deployment and Devices Security team [elastic/sec-deployment-and-devices]
Team:Security-Linux Platform
Linux Platform Security team [elastic/sec-linux-platform]
Team:Security-Service Integrations
Security Service Integrations Team [elastic/security-service-integrations]
Team:Security-Windows Platform
Security Windows Platform Team [elastic/sec-windows-platform]
The problem
In the Painless scripting language it is an error for the result of an
if
condition to benull
. This matches Java but differs from many other languages, in whichnull
is falsy.The null safe operator
?.
is often used to attempt field access or method invocation on objects that may benull
, but it doesn't turnnull
s in to non-null
s.After discovering incorrect
null
handling in my own code, I checked elsewhere and found many other occurrences.Demonstration of the problem in an
if
statementDemonstration of the problem in an
if
processor optionIdentified cases
In 3431bbe I looked for lines with an
if
condition, the null safe operator, and without an equality orinstanceof
check:And also for lines with a
for
loop and the null safe operator:About half of the candidates were actual problems: 225 lines spread across 39 integrations.
Summary of identified cases
List of identified cases
Variations of the problem
In these identified cases there were a number of different types of
null
handling errors:null
as the result of anif
condition:if (ctx?.risky?.value)
null
an an operand of a boolean operator:if: ctx.event?.action?.contains('substring') || ...
null
as an operand of a comparison operatorif (nameArray?.length > 0)
null
in the iteration statement of afor
loop:for (item in ctx.risky?.items)
equals()
method:if (ctx.event?.action.equals("some action"))
if (ctx?.safe.notSafe.moreNotSafe(arg))
if: '[...].contains(ctx.risk.unprotected) && ![...].contains(ctx?.risk?.protected)'
Constructed examples
Checklist of fixes
It's probably best to fix these with a separate pull request for each integration.
sec-deployment-and-devices
sec-windows-platform
security-service-integrations
stack-monitoring
obs-infraobs-intergrations
obs-ds-hosted-services
ecosystem
The text was updated successfully, but these errors were encountered: