Skip to content

Commit 60a9393

Browse files
authored
Sanitize Curl Logs (demisto#31702)
1 parent 6ed630c commit 60a9393

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Packs/Base/ReleaseNotes/1_33_15.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Scripts
3+
4+
##### CommonServerPython
5+
6+
- Fixed an issue where logging curl calls could expose sensitive values.

Packs/Base/Scripts/CommonServerPython/CommonServerPython.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __line__():
4949
EVENTS = "events"
5050
DATA_TYPES = [EVENTS, ASSETS]
5151

52+
SECRET_REPLACEMENT_STRING = '<XX_REPLACED>'
53+
5254

5355
def register_module_line(module_name, start_end, line, wrapper=0):
5456
"""
@@ -1591,7 +1593,7 @@ def encode(self, message):
15911593
else:
15921594
res = "Failed encoding message with error: {}".format(exception)
15931595
for s in self.replace_strs:
1594-
res = res.replace(s, '<XX_REPLACED>')
1596+
res = res.replace(s, SECRET_REPLACEMENT_STRING)
15951597
return res
15961598

15971599
def __call__(self, message):
@@ -1670,6 +1672,7 @@ def build_curl(self, text):
16701672
url = ''
16711673
headers = []
16721674
headers_to_skip = ['Content-Length', 'User-Agent', 'Accept-Encoding', 'Connection']
1675+
headers_to_sanitize = ['Authorization', 'Cookie']
16731676
request_parts = repr(data).split('\\\\r\\\\n') # splitting lines on repr since data is a bytes-string
16741677
for line, part in enumerate(request_parts):
16751678
if line == 0:
@@ -1681,6 +1684,9 @@ def build_curl(self, text):
16811684
else:
16821685
if any(header_to_skip in part for header_to_skip in headers_to_skip):
16831686
continue
1687+
if any(header_to_sanitize in part for header_to_sanitize in headers_to_sanitize):
1688+
headers.append(part.split(' ')[0] + " " + SECRET_REPLACEMENT_STRING)
1689+
continue
16841690
headers.append(part)
16851691
curl_headers = ''
16861692
for header in headers:

Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ def test_build_curl_post_noproxy():
14521452
"Content-Type: application/json\\r\\n\\r\\n'")
14531453
ilog.build_curl("send: b'{\"data\": \"value\"}'")
14541454
assert ilog.curl == [
1455-
'curl -X POST https://demisto.com/api -H "Authorization: TOKEN" -H "Content-Type: application/json" '
1455+
'curl -X POST https://demisto.com/api -H "Authorization: <XX_REPLACED>" -H "Content-Type: application/json" '
14561456
'--noproxy "*" -d \'{"data": "value"}\''
14571457
]
14581458

@@ -1479,7 +1479,7 @@ def test_build_curl_post_xml():
14791479
"Content-Type: application/json\\r\\n\\r\\n'")
14801480
ilog.build_curl("send: b'<?xml version=\"1.0\" encoding=\"utf-8\"?>'")
14811481
assert ilog.curl == [
1482-
'curl -X POST https://demisto.com/api -H "Authorization: TOKEN" -H "Content-Type: application/json" '
1482+
'curl -X POST https://demisto.com/api -H "Authorization: <XX_REPLACED>" -H "Content-Type: application/json" '
14831483
'--noproxy "*" -d \'<?xml version="1.0" encoding="utf-8"?>\''
14841484
]
14851485

@@ -1511,7 +1511,7 @@ def test_build_curl_get_withproxy(mocker):
15111511
"Content-Type: application/json\\r\\n\\r\\n'")
15121512
ilog.build_curl("send: b'{\"data\": \"value\"}'")
15131513
assert ilog.curl == [
1514-
'curl -X GET https://demisto.com/api -H "Authorization: TOKEN" -H "Content-Type: application/json" '
1514+
'curl -X GET https://demisto.com/api -H "Authorization: <XX_REPLACED>" -H "Content-Type: application/json" '
15151515
'--proxy http://proxy -k -d \'{"data": "value"}\''
15161516
]
15171517

@@ -1548,9 +1548,9 @@ def test_build_curl_multiple_queries():
15481548
"Content-Type: application/json\\r\\n\\r\\n'")
15491549
ilog.build_curl("send: b'{\"getdata\": \"value\"}'")
15501550
assert ilog.curl == [
1551-
'curl -X POST https://demisto.com/api/post -H "Authorization: TOKEN" -H "Content-Type: application/json" '
1551+
'curl -X POST https://demisto.com/api/post -H "Authorization: <XX_REPLACED>" -H "Content-Type: application/json" '
15521552
'--noproxy "*" -d \'{"postdata": "value"}\'',
1553-
'curl -X GET https://demisto.com/api/get -H "Authorization: TOKEN" -H "Content-Type: application/json" '
1553+
'curl -X GET https://demisto.com/api/get -H "Authorization: <XX_REPLACED>" -H "Content-Type: application/json" '
15541554
'--noproxy "*" -d \'{"getdata": "value"}\''
15551555
]
15561556

Packs/Base/pack_metadata.json

Lines changed: 1 addition & 1 deletion
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.33.14",
5+
"currentVersion": "1.33.15",
66
"author": "Cortex XSOAR",
77
"serverMinVersion": "6.0.0",
88
"url": "https://www.paloaltonetworks.com/cortex",

0 commit comments

Comments
 (0)