Skip to content

Commit 7d30d85

Browse files
authored
ti_abusech: Handle API errors inside CEL (#13708)
ti_abusech: Report API errors inside CEL programs. Currently some of the CEL programs inside ti_abusech don't check if API returns success. There are also certain checks missing on empty data. These lead to CEL execution errors. Add checks where necessary and report errors inside all data-streams. Also update remove the conversion of bytes for resp.Body as it is no longer required after 8.16.
1 parent b16e934 commit 7d30d85

File tree

6 files changed

+87
-24
lines changed

6 files changed

+87
-24
lines changed

packages/ti_abusech/changelog.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# newer versions go on top
2+
- version: "2.9.1"
3+
changes:
4+
- description: Properly handle CEL errors.
5+
type: bugfix
6+
link: https://github.com/elastic/integrations/pull/13708
27
- version: "2.9.0"
38
changes:
49
- description: Enable request trace log removal.

packages/ti_abusech/data_stream/malware/agent/stream/cel.yml.hbs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,33 @@ program: |
3131
:
3232
optional.none(),
3333
}
34-
}).as(req, req.do_request().as(resp,
35-
bytes(resp.Body).decode_json().as(body, {
36-
"events": body.payloads.map(payload, {
37-
"message": payload.encode_json()
38-
}),
34+
}).as(req, req.do_request().as(resp, resp.StatusCode == 200 ?
35+
resp.Body.decode_json().as(body, {
36+
"events": (has(body.payloads) ?
37+
body.payloads.map(payload, {
38+
"message": payload.encode_json()
39+
})
40+
:
41+
[]
42+
),
3943
"url": state.url
4044
})
45+
:
46+
{
47+
"events": {
48+
"error": {
49+
"code": string(resp.StatusCode),
50+
"id": string(resp.Status),
51+
"message": "GET "+ state.url.trim_right("/") + ":" + (
52+
size(resp.Body) != 0 ?
53+
string(resp.Body)
54+
:
55+
string(resp.Status) + ' (' + string(resp.StatusCode) + ')'
56+
),
57+
},
58+
},
59+
"want_more": false,
60+
}
4161
))
4262
)
4363

packages/ti_abusech/data_stream/malwarebazaar/agent/stream/cel.yml.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ program: |
3232
optional.none(),
3333
}
3434
}).do_request().as(resp, resp.StatusCode == 200 ?
35-
bytes(resp.Body).decode_json().as(body, body.?query_status == optional.of("ok") ?
35+
resp.Body.decode_json().as(body, body.?query_status == optional.of("ok") ?
3636
{
3737
"events": body.data.map(ind, {
3838
"message": ind.encode_json()

packages/ti_abusech/data_stream/threatfox/agent/stream/cel.yml.hbs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,37 @@ program: |
3333
:
3434
optional.none(),
3535
}
36-
}).as(req, req.do_request().as(resp,
37-
bytes(resp.Body).decode_json().as(body, {
38-
"events": body.data.map(ind, {
39-
"message": ind.encode_json()
40-
}),
36+
}).as(req, req.do_request().as(resp, resp.StatusCode == 200 ?
37+
resp.Body.decode_json().as(body, {
38+
"events": (has(body.data) ?
39+
body.data.map(ind, {
40+
"message": ind.encode_json()
41+
})
42+
:
43+
[]
44+
),
4145
"cursor": {
4246
"days": "1"
4347
},
4448
"initial_interval": state.initial_interval,
4549
"url": state.url
4650
})
51+
:
52+
{
53+
"events": {
54+
"error": {
55+
"code": string(resp.StatusCode),
56+
"id": string(resp.Status),
57+
"message": "POST "+ state.url.trim_right("/") + ":" + (
58+
size(resp.Body) != 0 ?
59+
string(resp.Body)
60+
:
61+
string(resp.Status) + ' (' + string(resp.StatusCode) + ')'
62+
),
63+
},
64+
},
65+
"want_more": false,
66+
}
4767
))
4868
)
4969

packages/ti_abusech/data_stream/url/agent/stream/cel.yml.hbs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,39 @@ program: |
3333
}
3434
})
3535
.do_request()
36-
.as(resp, resp.Body.mime("application/zip").File.as(file, file.size() > 0 ?
37-
file[0].Data.as(data, bytes(data).decode_json().as(body, {
38-
"events": body.map(id, body[id].size() > 0 ?
39-
{"message": body[id][0].with({"id": id}).encode_json()}
40-
:
41-
{"message": ""}
42-
),
43-
"url": state.url
44-
}))
36+
.as(resp, resp.StatusCode == 200 ?
37+
resp.Body.mime("application/zip").File.as(file, file.size() > 0 ?
38+
file[0].Data.as(data, bytes(data).decode_json().as(body, {
39+
"events": body.map(id, body[id].size() > 0 ?
40+
{"message": body[id][0].with({"id": id}).encode_json()}
41+
:
42+
{"message": ""}
43+
),
44+
"url": state.url
45+
}))
46+
:
47+
{
48+
"events": [],
49+
"url": state.url
50+
}
51+
)
4552
:
4653
{
47-
"events": [],
48-
"url": state.url
54+
"events": {
55+
"error": {
56+
"code": string(resp.StatusCode),
57+
"id": string(resp.Status),
58+
"message": "GET "+ state.url.trim_right("/") + ":" + (
59+
size(resp.Body) != 0 ?
60+
string(resp.Body)
61+
:
62+
string(resp.Status) + ' (' + string(resp.StatusCode) + ')'
63+
),
64+
},
65+
},
66+
"want_more": false,
4967
}
50-
))
68+
)
5169
)
5270

5371
fields_under_root: true

packages/ti_abusech/manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: ti_abusech
22
title: AbuseCH
3-
version: "2.9.0"
3+
version: "2.9.1"
44
description: Ingest threat intelligence indicators from URL Haus, Malware Bazaar, and Threat Fox feeds with Elastic Agent.
55
type: integration
66
format_version: "3.2.3"

0 commit comments

Comments
 (0)