Skip to content

Commit aa72bd0

Browse files
committed
added Query Auth
1 parent 121a229 commit aa72bd0

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

app.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import base64
77
import logging
8-
from urllib.parse import unquote
8+
from urllib.parse import unquote, urlencode, parse_qs
99

1010
app = Flask("Secured Signal Api")
1111

@@ -72,6 +72,8 @@ def middlewares():
7272
infoLog(f"Client tried to access Blocked Endpoint [{blockedPath}]")
7373
return Response("Forbidden", 401)
7474

75+
query_string = request.query_string.decode()
76+
7577
if secure:
7678
auth_header = request.headers.get("Authorization", "")
7779

@@ -97,10 +99,24 @@ def middlewares():
9799
except Exception as error:
98100
errorLog(f"Unexpected Error during Basic Auth: {error}")
99101
return UnauthorizedResponse()
102+
elif request.args.get("authorization", None):
103+
token = request.args.get("authorization", "")
104+
105+
token = unquote(token)
106+
107+
if token != API_TOKEN:
108+
infoLog(f"Client failed Query Auth [query: {token}]")
109+
return UnauthorizedResponse()
110+
111+
args = parse_qs(query_string)
112+
113+
args.pop('authorization', None)
114+
query_string = urlencode(args, doseq=True)
100115
else:
101116
infoLog(f"Client did not provide any Auth Method")
102117
return UnauthorizedResponse(True)
103-
118+
119+
g.query_string = query_string
104120

105121
@app.route('/', defaults={'path': ''}, methods=['GET', 'POST', 'PUT'])
106122
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT'])
@@ -116,10 +132,10 @@ def proxy(path):
116132
if "${NUMBER}" in path:
117133
path = path.replace("${NUMBER}", SENDER)
118134

119-
query_string = request.query_string.decode()
135+
query_string = g.query_string
120136

121-
if request.query_string.decode():
122-
query_string= "?" + request.query_string.decode()
137+
if query_string:
138+
query_string = "?" + query_string
123139

124140
targetURL = f"{SIGNAL_API_URL}/{path}{query_string}"
125141

0 commit comments

Comments
 (0)