[ti_opencti] Fix processing of externalReferences - #8556
Conversation
|
Pinging @elastic/security-external-integrations (Team:Security-External Integrations) |
🌐 Coverage report
|
efd6
left a comment
There was a problem hiding this comment.
Changelog and manifest updates?
Now done. I should have opened this as a draft, since I wanted to wait until community PR #8428 was merged. |
| return; | ||
| } | ||
| for (int i = 0; i < edges.length; i++) { | ||
| if (!ctx.opencti?.indicator?.containsKey('external_reference')) { |
There was a problem hiding this comment.
This is not safe; the ?. operator stops the derefs being unsafe, but then we get to a look up for the method on null, and bang!
| if (!ctx.opencti?.indicator?.containsKey('external_reference')) { | |
| if (ctx.opencti?.indicator != null && !ctx.opencti.indicator.containsKey('external_reference')) { |
There was a problem hiding this comment.
Here the last null safe operator replaces a plain .containsKey() method call. My rule of thumb is that ?. will make the thing immediately to its right safe - either a field access or a method call.
This script returns "safely got a null":
POST _scripts/painless/_execute
{
"script": {
"params": {
"key": null
},
"source": """
if (params.key?.nonKey?.nonMethod("arg")?.nonMethod2("arg") == null) {
return "safely got a null";
}
"""
}
}
There was a problem hiding this comment.
Actually, I see there's a problem. The ...?.containsKey('external_reference') is okay, but null as the result of an if condition is not okay. So I fixed that and other occurrences like this
if (ctx.opencti?.indicator?.containsKey('external_reference') == true) {
...
}
There was a problem hiding this comment.
Thanks, that's very informative; I've learned something new.
|
Package ti_opencti - 0.3.2 containing this change is available at https://epr.elastic.co/search?package=ti_opencti |
Proposed commit message
Checklist
changelog.ymlfile.Author's Checklist
How to test this PR locally
Related issues