Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6bf8415

Browse files
committed
Silent bug fix (.encode() is not safe for base64 encoding because of whitespaces)
1 parent 22907d5 commit 6bf8415

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/utils/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from lib.core.common import getSafeExString
2424
from lib.core.common import saveConfig
2525
from lib.core.common import unArrayizeValue
26+
from lib.core.convert import base64encode
2627
from lib.core.convert import hexencode
2728
from lib.core.convert import dejsonize
2829
from lib.core.convert import jsonize
@@ -654,7 +655,7 @@ def download(taskid, target, filename):
654655
logger.debug("[%s] Retrieved content of file %s" % (taskid, target))
655656
with open(path, 'rb') as inf:
656657
file_content = inf.read()
657-
return jsonize({"success": True, "file": file_content.encode("base64")})
658+
return jsonize({"success": True, "file": base64encode(file_content)})
658659
else:
659660
logger.warning("[%s] File does not exist %s" % (taskid, target))
660661
return jsonize({"success": False, "message": "File does not exist"})
@@ -722,7 +723,7 @@ def _client(url, options=None):
722723
headers = {"Content-Type": "application/json"}
723724

724725
if DataStore.username or DataStore.password:
725-
headers["Authorization"] = "Basic %s" % ("%s:%s" % (DataStore.username or "", DataStore.password or "")).encode("base64").strip()
726+
headers["Authorization"] = "Basic %s" % base64encode("%s:%s" % (DataStore.username or "", DataStore.password or ""))
726727

727728
req = urllib2.Request(url, data, headers)
728729
response = urllib2.urlopen(req)

0 commit comments

Comments
 (0)