55import re
66import base64
77import logging
8- from urllib .parse import unquote
8+ from urllib .parse import unquote , urlencode , parse_qs
99
1010app = 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