Skip to content

Commit 115adad

Browse files
JasBeilinRosenbergYehuda
authored andcommitted
Reverting sensitive str handling (#38203)
* fixing performance issue * RN * fix * fix * wip * fix * wip * remove gsuite * remove test * remove lats func * rn * pre commit --------- Co-authored-by: yrosenberg <[email protected]>
1 parent bf3b5af commit 115adad

File tree

17 files changed

+52
-138
lines changed

17 files changed

+52
-138
lines changed

Diff for: Packs/ApiModules/Scripts/GSuiteApiModule/GSuiteApiModule.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ def http_exception_handler():
137137
raise DemistoException(COMMON_MESSAGES['TRANSPORT_ERROR'].format(error))
138138
except exceptions.RefreshError as error:
139139
if error.args:
140-
# masking the token present in the error message
141-
error_msg = error.args[0]
142-
find_and_remove_sensitive_text(text=error_msg,
143-
pattern=r'(token:\s*)(\S+)')
144-
raise DemistoException(COMMON_MESSAGES['REFRESH_ERROR'].format(error_msg))
140+
raise DemistoException(COMMON_MESSAGES['REFRESH_ERROR'].format(error.args[0]))
145141
raise DemistoException(error)
146142
except TimeoutError as error:
147143
raise DemistoException(COMMON_MESSAGES['TIMEOUT_ERROR'].format(error))

Diff for: Packs/Base/ReleaseNotes/1_39_16.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Scripts
3+
4+
##### CommonServerPython
5+
6+
- Fixed performance issues.

Diff for: Packs/Base/Scripts/CommonServerPython/CommonServerPython.py

+1-55
Original file line numberDiff line numberDiff line change
@@ -1615,19 +1615,6 @@ def stringUnEscape(st):
16151615
return st.replace('\\r', '\r').replace('\\n', '\n').replace('\\t', '\t')
16161616

16171617

1618-
def doubleBackslashes(st):
1619-
"""
1620-
Double any backslashes in the given string if it contains two backslashes.
1621-
1622-
:type st: ``str``
1623-
:param st: The string to be modified (required).
1624-
1625-
:return: A modified string with doubled backslashes.
1626-
:rtype: ``str``
1627-
"""
1628-
return st.replace('\\', '\\\\')
1629-
1630-
16311618
class IntegrationLogger(object):
16321619
"""
16331620
a logger for python integrations:
@@ -1708,7 +1695,6 @@ def add_replace_strs(self, *args):
17081695
a = self.encode(a)
17091696
to_add.append(stringEscape(a))
17101697
to_add.append(stringUnEscape(a))
1711-
to_add.append(doubleBackslashes(a))
17121698
js = json.dumps(a)
17131699
if js.startswith('"'):
17141700
js = js[1:]
@@ -12649,47 +12635,7 @@ def function_runner(func, profiler, signal_event,
1264912635
return profiler_wrapper
1265012636

1265112637

12652-
def find_and_remove_sensitive_text(text, pattern):
12653-
r"""
12654-
Finds all appearances of sensitive information in a string using regex and adds the sensitive
12655-
information to the list of strings that should not appear in any logs.
12656-
The regex pattern can be used to search for a specific word, or a pattern such as a word after a given word.
12657-
Examples:
12658-
>>> text = "first secret is ID123 and the second secret is id321 and the token: ABC"
12659-
>>> pattern = r'(token:\s*)(\S+)' # Capturing groups: (token:\s*) and (\S+)
12660-
>>> find_and_remove_sensitive_text(text, pattern)
12661-
Sensitive text added to be masked in the logs: ABC
12662-
12663-
>>> pattern = r'\bid\w*\b' # Match words starting with "id", case insensitive
12664-
>>> find_and_remove_sensitive_text(text, pattern)
12665-
Sensitive text added to be masked in the logs: ID123 and id321
12666-
12667-
:param text: The input text containing the sensitive information.
12668-
:type text: str
12669-
:param pattern: The regex pattern to match the sensitive information.
12670-
:type pattern: str
12671-
12672-
:return: None
12673-
:rtype: ``None``
12674-
"""
12675-
12676-
sensitive_pattern = re.compile(pattern)
12677-
matches = sensitive_pattern.findall(text)
12678-
if not matches:
12679-
return
12680-
12681-
for match in matches:
12682-
# in case the regex serches for a group pattern
12683-
if isinstance(match, tuple):
12684-
sensitive_text = match[1]
12685-
else:
12686-
# in case the regex serches for a specific word
12687-
sensitive_text = match
12688-
add_sensitive_log_strs(sensitive_text)
12689-
return
12690-
12691-
12692-
from DemistoClassApiModule import * # type:ignore [no-redef] # noqa:E402the
12638+
from DemistoClassApiModule import * # type:ignore [no-redef] # noqa:E402
1269312639

1269412640
###########################################
1269512641
# DO NOT ADD LINES AFTER THIS ONE #

Diff for: Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py

+1-71
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import CommonServerPython
2020
import demistomock as demisto
21-
from CommonServerPython import (find_and_remove_sensitive_text, xml2json, json2xml, entryTypes, formats, tableToMarkdown, underscoreToCamelCase,
21+
from CommonServerPython import (xml2json, json2xml, entryTypes, formats, tableToMarkdown, underscoreToCamelCase,
2222
flattenCell, date_to_timestamp, datetime, timedelta, camelize, pascalToSpace, argToList,
2323
remove_nulls_from_dictionary, is_error, get_error, hash_djb2, fileResult, is_ip_valid,
2424
get_demisto_version, IntegrationLogger, parse_date_string, IS_PY3, PY_VER_MINOR, DebugLogger,
@@ -10010,73 +10010,3 @@ def test_get_engine_base_url(mocker):
1001010010
mocker.patch.object(demisto, 'internalHttpRequest', return_value=mock_response)
1001110011
res = get_engine_base_url('1111')
1001210012
assert res == '11.111.111.33:443'
10013-
10014-
10015-
@pytest.mark.parametrize('input_text, pattern, expected_output, call_count', [
10016-
pytest.param('invalid_grant: java.security.SignatureException: Invalid signature for token: 1234',
10017-
r'(token:\s*)(\S+)', '1234', 1, id='Match token value'),
10018-
pytest.param('invalid_grant: java.security.SignatureException: Invalid signature for token: 1234', r'(invalid_grant: java.security.SignatureException: Invalid signature for token: 1234)',
10019-
'invalid_grant: java.security.SignatureException: Invalid signature for token: 1234', 1, id='Match entire string')
10020-
])
10021-
def test_find_and_remove_sensitive_text__found_onc(input_text, pattern, expected_output, call_count, mocker):
10022-
"""
10023-
Given:
10024-
- Input text that includes sensitive information.
10025-
10026-
When:
10027-
- Invoking the `find_and_remove_sensitive_text` method with a regex pattern to search for sensitive information.
10028-
10029-
Then:
10030-
- Verify that the function responsible for removing sensitive information from the logs is called with the sensitive data as an argument.
10031-
- Verify that the function is called the correct number of times.
10032-
10033-
"""
10034-
input_text = 'invalid_grant: java.security.SignatureException: Invalid signature for token: 1234'
10035-
mock_remove_from_logs = mocker.patch('CommonServerPython.add_sensitive_log_strs', return_value=None)
10036-
find_and_remove_sensitive_text(input_text, pattern)
10037-
10038-
assert mock_remove_from_logs.call_count == call_count
10039-
assert mock_remove_from_logs.call_args[0][0] == expected_output
10040-
10041-
10042-
@pytest.mark.parametrize('pattern, expected_output, call_count', [
10043-
pytest.param(r'n', ['n', 'n', 'n', 'n', 'n', 'n', 'n'], 7, id='Match character "n"'),
10044-
pytest.param(r'(?i)invalid', ['invalid', 'Invalid'], 2, id='Match word "invalid" case insensitive')
10045-
])
10046-
def test_find_and_remove_sensitive_text__found_multiple(pattern, expected_output, call_count, mocker):
10047-
"""
10048-
Given:
10049-
- Input text that includes sensitive information.
10050-
10051-
When:
10052-
- Invoking the `find_and_remove_sensitive_text` method with a regex pattern to search for a sensitive information.
10053-
10054-
Then:
10055-
verify that the function responsible for removing sensitive information from the logs is called with the sensitive data as an argument.
10056-
verify that the function is called the correct number of times.
10057-
"""
10058-
input_text = 'invalid_grant: java.security.SignatureException: Invalid signature for token: 1234'
10059-
mock_remove_from_logs = mocker.patch('CommonServerPython.add_sensitive_log_strs', return_value=None)
10060-
find_and_remove_sensitive_text(input_text, pattern)
10061-
assert mock_remove_from_logs.call_count == call_count
10062-
for x in range(call_count):
10063-
assert mock_remove_from_logs.call_args_list[x][0][0] == expected_output[x]
10064-
10065-
10066-
def test_find_and_remove_sensitive_text__not_found(mocker):
10067-
"""
10068-
Given:
10069-
- Input text that does not contain any sensitive information (e.g., no word following "token:").
10070-
10071-
When:
10072-
- Invoking the `find_and_remove_sensitive_text` method with a regex pattern to search for a sensitive information (the word following "token:").
10073-
10074-
Then:
10075-
- Ensure that the function does not remove anything from the logs.
10076-
"""
10077-
10078-
input_text = 'invalid_grant: java.security.SignatureException: Invalid signature for text: 1234'
10079-
mock_remove_from_logs = mocker.patch('CommonServerPython.add_sensitive_log_strs', return_value=None)
10080-
find_and_remove_sensitive_text(input_text, r'(token:\s*)(\S+)')
10081-
10082-
mock_remove_from_logs.assert_not_called()

Diff for: 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.15",
5+
"currentVersion": "1.39.16",
66
"author": "Cortex XSOAR",
77
"serverMinVersion": "6.0.0",
88
"url": "https://www.paloaltonetworks.com/cortex",

Diff for: Packs/GSuiteAdmin/ReleaseNotes/1_2_6.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Integrations
3+
4+
##### Google Workspace Admin
5+
6+
Fixed performance issues.

Diff for: Packs/GSuiteAdmin/pack_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "G Suite Admin",
33
"description": "G Suite Admin integration with Cortex XSOAR. G Suite or Google Workspace Admin is an integration to perform an action on IT infrastructure, create users, update settings, and more administrative tasks.",
44
"support": "xsoar",
5-
"currentVersion": "1.2.5",
5+
"currentVersion": "1.2.6",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Integrations
3+
4+
##### G Suite Security Alert Center
5+
6+
Fixed performance issues.

Diff for: Packs/GSuiteSecurityAlertCenter/pack_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "G Suite Security Alert Center",
33
"description": "Fetch alert types, delete or recover alerts, retrieve an alert's metadata, and create or view alert feedback.",
44
"support": "xsoar",
5-
"currentVersion": "1.1.48",
5+
"currentVersion": "1.1.49",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

Diff for: Packs/GoogleCalendar/ReleaseNotes/1_1_51.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Integrations
3+
4+
##### Google Calendar
5+
6+
Fixed performance issues.

Diff for: Packs/GoogleCalendar/pack_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Google Calendar",
33
"description": "Google Calendar integration with Cortex XSOAR.",
44
"support": "xsoar",
5-
"currentVersion": "1.1.50",
5+
"currentVersion": "1.1.51",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

Diff for: Packs/GoogleCloudLogging/ReleaseNotes/1_0_19.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Integrations
3+
4+
##### Google Cloud Logging
5+
6+
Fixed performance issues.

Diff for: Packs/GoogleCloudLogging/pack_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Google Cloud Logging",
33
"description": "Google Cloud Logging is a managed logging solution provided by Google Cloud Platform (GCP) that allows users to collect, store, search, analyze, and monitor logs generated by GCP services, third-party applications, and custom applications running on GCP.",
44
"support": "xsoar",
5-
"currentVersion": "1.0.18",
5+
"currentVersion": "1.0.19",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

Diff for: Packs/GoogleDrive/ReleaseNotes/1_3_13.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Integrations
3+
4+
##### Google Drive
5+
6+
Fixed performance issues.

Diff for: Packs/GoogleDrive/pack_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Google Drive",
33
"description": "Google Drive allows users to store files on their servers, synchronize files across devices, and share files. This integration helps you to create a new drive, query past activity and view change logs performed by the users, as well as list drives and files, and manage their permissions.",
44
"support": "xsoar",
5-
"currentVersion": "1.3.12",
5+
"currentVersion": "1.3.13",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

Diff for: Packs/GsuiteAuditor/ReleaseNotes/1_0_28.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Integrations
3+
4+
##### G Suite Auditor
5+
6+
Fixed performance issues.

Diff for: Packs/GsuiteAuditor/pack_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "GsuiteAuditor",
33
"description": "G Suite Auditor integration with Cortex XSOAR. G Suite Auditor is an integration to recieve audit log data from G Suite services like drive,gmail and more. The integration uses Google Admin SDK",
44
"support": "xsoar",
5-
"currentVersion": "1.0.27",
5+
"currentVersion": "1.0.28",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

0 commit comments

Comments
 (0)