Skip to content

Commit 763df1a

Browse files
authored
Reduce LoC in CSP + Readd Max Event Size Limit (demisto#38738)
* re- added mechanism to disallow sending a single event entry which is over 5MB in **send_events_to_xsiam**.
1 parent b60fafb commit 763df1a

File tree

4 files changed

+21
-44
lines changed

4 files changed

+21
-44
lines changed

Documentation/common_server_docs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"BaseHTTPClient", "DemistoHandler", "DebugLogger", "FeedIndicatorType", "Indicator",
3232
"IndicatorType", "EntryType", "EntryFormat", "abstractmethod",
3333
"HTTPAdapter", "Retry", "Common", "randint", "GetDemistoVersion", "get_demisto_version",
34-
"BaseWidget", "UTC", "WarningsHandler", "__line__", "_find_relevant_module"]
34+
"BaseWidget", "UTC", "WarningsHandler", "__line__", "_find_relevant_module", "register_module_line",
35+
"fix_traceback_line_numbers"]
3536

3637
PY_IRREGULAR_FUNCS = {"LOG": {"argList": ["message"]}}
3738

Packs/Base/ReleaseNotes/1_39_20.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#### Scripts
2+
3+
##### CommonServerPython
4+
5+
- Re-added mechanism to disallow sending a single event entry which is over 5MB in **send_events_to_xsiam**.

Packs/Base/Scripts/CommonServerPython/CommonServerPython.py

+13-42
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def __line__():
4848
XSIAM_EVENT_CHUNK_SIZE = 2 ** 20 # 1 Mib
4949
XSIAM_EVENT_CHUNK_SIZE_LIMIT = 9 * (10 ** 6) # 9 MB, note that the allowed max size for 1 entry is 5MB.
5050
# So if you're using a "heavy" API it is recommended to use maximum of 4MB chunk size.
51+
MAX_ALLOWED_ENTRY_SIZE = 5 * (10 ** 6) # 5 MB, this is the maximum allowed size of a single entry.
52+
# So if you're using a "heavy" API it is recommended to use maximum of 9MB chunk size.
5153
ASSETS = "assets"
5254
EVENTS = "events"
5355
DATA_TYPES = [EVENTS, ASSETS]
@@ -60,25 +62,6 @@ def __line__():
6062

6163

6264
def register_module_line(module_name, start_end, line, wrapper=0):
63-
"""
64-
Register a module in the line mapping for the traceback line correction algorithm.
65-
66-
:type module_name: ``str``
67-
:param module_name: The name of the module. (required)
68-
69-
:type start_end: ``str``
70-
:param start_end: Whether to register the line as the start or the end of the module.
71-
Possible values: start, end. (required)
72-
73-
:type line: ``int``
74-
:param line: the line number to record. (required)
75-
76-
:type wrapper: ``int``
77-
:param wrapper: Wrapper size (used for inline replacements with headers such as ApiModules). (optional)
78-
79-
:return: None
80-
:rtype: ``None``
81-
"""
8265
global _MODULES_LINE_MAPPING
8366
default_module_info = {'start': 0, 'start_wrapper': 0, 'end': float('inf'), 'end_wrapper': float('inf')}
8467
try:
@@ -98,15 +81,6 @@ def register_module_line(module_name, start_end, line, wrapper=0):
9881

9982

10083
def _find_relevant_module(line):
101-
"""
102-
Find which module contains the given line number.
103-
104-
:type line: ``int``
105-
:param trace_str: Line number to search. (required)
106-
107-
:return: The name of the module.
108-
:rtype: ``str``
109-
"""
11084
global _MODULES_LINE_MAPPING
11185

11286
relevant_module = ''
@@ -121,15 +95,6 @@ def _find_relevant_module(line):
12195

12296

12397
def fix_traceback_line_numbers(trace_str):
124-
"""
125-
Fixes the given traceback line numbers.
126-
127-
:type trace_str: ``str``
128-
:param trace_str: The traceback string to edit. (required)
129-
130-
:return: The new formated traceback.
131-
:rtype: ``str``
132-
"""
13398

13499
def is_adjusted_block(start, end, adjusted_lines):
135100
return any(
@@ -8718,11 +8683,11 @@ def is_xsiam():
87188683

87198684
def is_using_engine():
87208685
"""Determines whether or not the platform is using engine.
8721-
NOTE:
8686+
NOTE:
87228687
- This method works only for system integrations (not custom).
87238688
- On xsoar 8, this method works only for integrations that runs on the xsoar pod - not on the engine-0 (mainly long running
87248689
integrations) such as: EDL, Cortex Core - IOC, Cortex Core - IR, ExportIndicators, Generic Webhook, PingCastle,
8725-
Publish List, Simple API Proxy, Syslog v2, TAXII Server, TAXII2 Server, Web File Repository, Workday_IAM_Event_Generator,
8690+
Publish List, Simple API Proxy, Syslog v2, TAXII Server, TAXII2 Server, Web File Repository, Workday_IAM_Event_Generator,
87268691
XSOAR-Web-Server, Microsoft Teams, AWS-SNS-Listener.
87278692
87288693
:return: True iff the platform is using engine.
@@ -8766,7 +8731,7 @@ def is_integration_instance_running_on_engine():
87668731

87678732

87688733
def get_engine_base_url(engine_id):
8769-
"""Gets the xsoar engine id and returns it's base url.
8734+
"""Gets the xsoar engine id and returns it's base url.
87708735
For example: for engine_id = '4ccccccc-5aaa-4000-b666-dummy_id', base url = '11.180.111.111:1443'.
87718736
87728737
:type engine_id: ``str``
@@ -8821,7 +8786,7 @@ def emit(self, record):
88218786

88228787
def censor_request_logs(request_log):
88238788
"""
8824-
Censors the request logs generated from the urllib library directly by replacing sensitive information such as tokens and cookies with a mask.
8789+
Censors the request logs generated from the urllib library directly by replacing sensitive information such as tokens and cookies with a mask.
88258790
In most cases, the sensitive value is the first word after the keyword, but in some cases, it is the second one.
88268791
:param request_log: The request log to censor
88278792
:type request_log: ``str``
@@ -12059,8 +12024,14 @@ def split_data_to_chunks(data, target_chunk_size):
1205912024
yield chunk
1206012025
chunk = []
1206112026
chunk_size = 0
12027+
data_part_size = sys.getsizeof(data_part)
12028+
if data_part_size >= MAX_ALLOWED_ENTRY_SIZE:
12029+
demisto.error(
12030+
"entry size {} is larger than the maximum allowed entry size {}, skipping this entry".format(data_part_size,
12031+
MAX_ALLOWED_ENTRY_SIZE))
12032+
continue
1206212033
chunk.append(data_part)
12063-
chunk_size += sys.getsizeof(data_part)
12034+
chunk_size += data_part_size
1206412035
if chunk_size != 0:
1206512036
demisto.debug("sending the remaining chunk with size: {size}".format(size=chunk_size))
1206612037
yield chunk

Packs/Base/pack_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Base",
33
"description": "The base pack for Cortex XSOAR.",
44
"support": "xsoar",
5-
"currentVersion": "1.39.19",
5+
"currentVersion": "1.39.20",
66
"author": "Cortex XSOAR",
77
"serverMinVersion": "6.0.0",
88
"url": "https://www.paloaltonetworks.com/cortex",

0 commit comments

Comments
 (0)