Skip to content

Commit bf9a63b

Browse files
authored
unquote token / basic auth
1 parent 608be58 commit bf9a63b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

app.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import requests
55
import re
66
import base64
7-
import logging
7+
import logging
8+
from urllib.parse import unquote
89

910
app = Flask("Secured Signal Api")
1011

@@ -39,7 +40,7 @@ def fillInVars(obj):
3940
for i in range(len(obj)):
4041
obj[i] = fillInVars(obj[i])
4142
elif isinstance(obj, str):
42-
matches = re.findall(r"\${(.*?)}", obj)
43+
matches = re.findall(r"\${(.*?)}", obj)
4344
for match in matches:
4445
if match in VARIABLES:
4546
value = VARIABLES[match]
@@ -75,15 +76,20 @@ def middlewares():
7576
auth_header = request.headers.get("Authorization", "")
7677

7778
if auth_header.startswith("Bearer "):
78-
token = auth_header.split(" ", 1)[1]
79-
if token != API_TOKEN:
79+
token = auth_header.split(" ", 1)[1]
80+
81+
token = unquote(token)
82+
if token != API_TOKEN:
8083
infoLog(f"Client failed Bearer Auth [token: {token}]")
8184
return UnauthorizedResponse()
82-
elif auth_header.startswith("Basic "):
83-
try:
84-
decoded = base64.b64decode(auth_header.split(" ", 1)[1]).decode()
85-
username, password = decoded.split(":", 1)
86-
if username != "api" or password != API_TOKEN:
85+
elif auth_header.startswith("Basic "):
86+
try:
87+
decoded = base64.b64decode(auth_header.split(" ", 1)[1]).decode()
88+
username, password = decoded.split(":", 1)
89+
90+
username = unquote(username)
91+
password = unquote(password)
92+
if username != "api" or password != API_TOKEN:
8793
infoLog(f"Client failed Basic Auth [user: {username}, pw:{password}]")
8894
return UnauthorizedResponse()
8995
except Exception as error:

0 commit comments

Comments
 (0)