|
4 | 4 | import requests |
5 | 5 | import re |
6 | 6 | import base64 |
7 | | -import logging |
| 7 | +import logging |
| 8 | +from urllib.parse import unquote |
8 | 9 |
|
9 | 10 | app = Flask("Secured Signal Api") |
10 | 11 |
|
@@ -39,7 +40,7 @@ def fillInVars(obj): |
39 | 40 | for i in range(len(obj)): |
40 | 41 | obj[i] = fillInVars(obj[i]) |
41 | 42 | elif isinstance(obj, str): |
42 | | - matches = re.findall(r"\${(.*?)}", obj) |
| 43 | + matches = re.findall(r"\${(.*?)}", obj) |
43 | 44 | for match in matches: |
44 | 45 | if match in VARIABLES: |
45 | 46 | value = VARIABLES[match] |
@@ -75,15 +76,20 @@ def middlewares(): |
75 | 76 | auth_header = request.headers.get("Authorization", "") |
76 | 77 |
|
77 | 78 | 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: |
80 | 83 | infoLog(f"Client failed Bearer Auth [token: {token}]") |
81 | 84 | 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: |
87 | 93 | infoLog(f"Client failed Basic Auth [user: {username}, pw:{password}]") |
88 | 94 | return UnauthorizedResponse() |
89 | 95 | except Exception as error: |
|
0 commit comments