osbot-utils 1.52.0__py3-none-any.whl → 1.53.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
osbot_utils/utils/Http.py CHANGED
@@ -1,15 +1,22 @@
1
1
  import json
2
2
  import os
3
+ import re
3
4
  import socket
4
5
  import ssl
6
+ import unicodedata
5
7
  from time import sleep
6
- from urllib.parse import quote, urljoin, urlparse
8
+ from urllib.parse import quote, urljoin, urlparse, urlunparse
7
9
  from urllib.request import Request, urlopen
8
10
 
11
+ from osbot_utils.utils.Str import html_decode
12
+
13
+ from osbot_utils.utils.Misc import url_decode
14
+
9
15
  from osbot_utils.utils.Files import save_bytes_as_file, file_size, file_bytes, file_open_bytes, file_create
10
16
  from osbot_utils.utils.Python_Logger import Python_Logger
11
17
 
12
- URL_CHECK_HOST_ONLINE = 'https://www.google.com'
18
+ URL_CHECK_HOST_ONLINE = 'https://www.google.com'
19
+ URL_JOIN_SAFE__MAX_ITERATIONS = 5
13
20
 
14
21
  def current_host_offline(url_to_use=URL_CHECK_HOST_ONLINE):
15
22
  return current_host_online(url_to_use=url_to_use) is False
@@ -148,15 +155,34 @@ def url_join_safe(base_path, path=''):
148
155
  if not isinstance(base_path, str) or not isinstance(path, str):
149
156
  return None
150
157
 
151
- if not base_path.endswith('/'): # Ensure that the base path ends with '/'
158
+ max_iterations = URL_JOIN_SAFE__MAX_ITERATIONS
159
+
160
+ path = unicodedata.normalize('NFC', path)
161
+ path_normalised = path
162
+ for _ in range(max_iterations):
163
+ fixed_segments = []
164
+ for segment in path_normalised.split('/'):
165
+ segment_decoded = html_decode(url_decode(segment))
166
+ fixed_segment = re.sub(r'[^a-zA-Z0-9\-_.]+', '-', segment_decoded)
167
+ fixed_segment = fixed_segment.replace("..", "-")
168
+ if fixed_segment:
169
+ fixed_segments.append(fixed_segment)
170
+ path_cleaned = '/'.join(fixed_segments)
171
+
172
+ if path_cleaned == path_normalised:
173
+ break
174
+ path_normalised = path_cleaned
175
+ else:
176
+ return None # If we exit the loop without breaking, return None
177
+
178
+ if not base_path.endswith('/'): # Ensure that the base path ends with '/'
152
179
  base_path += '/'
153
180
 
154
- if path.startswith('/'): # Remove leading '/' from path
155
- path = path[1:]
181
+ if path_normalised.startswith('/'): # Remove leading '/' from path
182
+ path_normalised = path_normalised[1:]
156
183
 
157
- path_quoted = quote(path)
158
- path_normalised = path_quoted.replace("..", "") # Quote the path to encode special characters and prevent directory traversal
159
- joined_path = urljoin(base_path, path_normalised) # Join the base path and normalized path
184
+ path_quoted = quote(path_normalised, safe='/') # Quote the path to encode special characters
185
+ joined_path = urljoin(base_path, path_quoted) # Join the base path and normalized path
160
186
  parsed_base = urlparse(base_path) # Parse and verify the result
161
187
  parsed_joined = urlparse(joined_path)
162
188
 
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.52.0
1
+ v1.53.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.52.0
3
+ Version: 1.53.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  Home-page: https://github.com/owasp-sbot/OSBot-Utils
6
6
  License: MIT
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
22
22
 
23
23
  Powerful Python util methods and classes that simplify common apis and tasks.
24
24
 
25
- ![Current Release](https://img.shields.io/badge/release-v1.52.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.53.0-blue)
26
26
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
27
27
 
28
28
 
@@ -280,7 +280,7 @@ osbot_utils/utils/Env.py,sha256=XMwF5BrtpoPJdOraswAFPrcQ3tRTocjqvA8I61eOCJw,5741
280
280
  osbot_utils/utils/Exceptions.py,sha256=KyOUHkXQ_6jDTq04Xm261dbEZuRidtsM4dgzNwSG8-8,389
281
281
  osbot_utils/utils/Files.py,sha256=7fdqbfFyo6Ow5Repi_dZAzHqGb0XYh6tDALYAy42pBY,22522
282
282
  osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
283
- osbot_utils/utils/Http.py,sha256=YHHHRpy_QtH-Q_jaSuDwWRl-mmKBiC0DzfDew3l7fgg,6079
283
+ osbot_utils/utils/Http.py,sha256=vFvD-xLkkXLTJvmYGourMLoUOfkZx_KBSLmo1RX73jM,7043
284
284
  osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
285
285
  osbot_utils/utils/Json.py,sha256=7COxBlZRnpxtpNqpmzMPYkcKTnCok-s686nT27oiKEQ,6489
286
286
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
@@ -298,8 +298,8 @@ osbot_utils/utils/Toml.py,sha256=SD6IA4-mrtoBXcI0dIGKV9POMQNd6WYKvmDQq7GQ6ZQ,143
298
298
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
299
299
  osbot_utils/utils/Zip.py,sha256=G6Hk_hDcm9yvWzhTKzhT0R_6f0NBIAchHqMxGb3kfh4,14037
300
300
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
301
- osbot_utils/version,sha256=8vEHTopueL8q72Dw7rD-UnsLBahO-qnshWhrIIA_f-A,8
302
- osbot_utils-1.52.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
303
- osbot_utils-1.52.0.dist-info/METADATA,sha256=oAWX7EihUIYgMTuzzWfOEO0z4XKdrRWi-J1ap0ksrlE,1266
304
- osbot_utils-1.52.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
305
- osbot_utils-1.52.0.dist-info/RECORD,,
301
+ osbot_utils/version,sha256=cfLGcb-cU0atx9PN7uRd-7SjRkvlf2gUwCK4UUZZCt8,8
302
+ osbot_utils-1.53.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
303
+ osbot_utils-1.53.0.dist-info/METADATA,sha256=PQqhK7mvfVoonWblVF3oPIdHKqP7CXisueyqZiBVCeE,1266
304
+ osbot_utils-1.53.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
305
+ osbot_utils-1.53.0.dist-info/RECORD,,