Skip to content

Commit e31304a

Browse files
#188414493 Refactor: Fix substring sanitization (#26)
* Fix Substring Sanitzation - Fix [URL substring sanitization](https://github.com/Moesif/moesifpythonrequest/security/code-scanning/1) - Bump version - Update moesifapi version req. - Update .gitignore * Address URL substring sanitization CWE-20 * Refactor: Bump moesifapi-python version to 1.5.3 Refactor: Bump moesifapi-python version to 1.5.3 --------- Co-authored-by: Dylan Frankcom <dylanfrankcom@icloud.com>
1 parent 6fb5854 commit e31304a

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,5 @@ fabric.properties
202202
# modules.xml
203203
# .idea/misc.xml
204204
# *.ipr
205+
/Pipfile
206+
/Pipfile.lock

moesifpythonrequest/utility_function/utility_function.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
# Import libraries
22
from moesifapi.moesif_api_client import APIHelper
33
from datetime import datetime
4-
4+
from urllib.parse import urlparse
55

66
class UtilityFunction():
77
# Function to get the current time
88
def get_current_time(self):
99
return datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3]
1010

11+
# Function to check if the allowed url is valid
12+
def is_valid_url(url, allowed_hosts):
13+
try:
14+
parsed_url = urlparse(url)
15+
return parsed_url.netloc.endswith('moesif.net')
16+
except:
17+
return False
18+
1119
# Function to check if the event is to Moesif
1220
def is_moesif(self, request_headers, url):
1321
if request_headers and isinstance(request_headers, dict):
1422
if request_headers.get('X-Moesif-SDK', None) is not None or request_headers.get('X-Moesif-Application-Id', None) is not None:
1523
return True
1624

17-
if url and 'moesif.net' in url:
18-
return True
19-
20-
return False
25+
return is_valid_url(url)
2126

2227
# Function to mask the body
2328
def mask_body(self, body, masks):

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
requests
2-
moesifapi==1.4.2
2+
moesifapi==1.5.3

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Versions should comply with PEP440. For a discussion on single-sourcing
2929
# the version across setup.py and the project code, see
3030
# https://packaging.python.org/en/latest/single_source_version.html
31-
version='0.3.3',
31+
version='0.3.4',
3232

3333
description='Moesif Python request',
3434
long_description=long_description,

0 commit comments

Comments
 (0)