Skip to content

Commit ce0a87b

Browse files
committed
Improve base64 decoding safety in byte responses
1 parent b69ff55 commit ce0a87b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

async_tls_client/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
__title__ = "async_tls_client"
88
__description__ = "Asyncio fork of Python-TLS-Client with updated dependencies"
9-
__version__ = "1.0.10"
9+
__version__ = "1.1"
1010
__author__ = "Diprog (fork), Florian Zager (original)"
1111
__license__ = "MIT"

async_tls_client/response.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ def build_response(res: Union[dict, list], res_cookies: RequestsCookieJar) -> Re
7272
response.headers = response_headers
7373
# Add cookies
7474
response.cookies = res_cookies
75+
76+
# Decode the byte-response (base64 format)
77+
try:
78+
data_part = res["body"].split(',', 1)[1]
79+
except IndexError:
80+
import logging
81+
logging.warning("Invalid base64 response format")
82+
data_part = res["body"]
7583
# Add response body
76-
response.text = base64.b64decode(res["body"].split(',')[1]).decode(errors='ignore')
84+
response.text = base64.b64decode(data_part).decode(errors='ignore')
7785
# Add response content (bytes)
78-
response._content = base64.b64decode(res["body"].split(',')[1])
86+
response._content = base64.b64decode(data_part)
7987
return response

0 commit comments

Comments
 (0)