@@ -131,18 +131,24 @@ func (api *API) SetupRoutes() {
131131 return
132132 }
133133
134- log .Debug ().Interface ("proxy" , proxy .Proxy ).Msg ("Got proxy" )
134+ // Check if the request is coming from a browser (tools like curl/bruno use */* and they don't include the text/html)
135+ isBrowser := strings .Contains (c .Request .Header .Get ("Accept" ), "text/html" )
136+
137+ if isBrowser {
138+ log .Debug ().Msg ("Request is most likely coming from a browser" )
139+ } else {
140+ log .Debug ().Msg ("Request is most likely not coming from a browser" )
141+ }
135142
136- // Check if using basic auth
137- _ , _ , basicAuth := c .Request .BasicAuth ()
143+ log .Debug ().Interface ("proxy" , proxy .Proxy ).Msg ("Got proxy" )
138144
139145 // Check if auth is enabled
140146 authEnabled , authEnabledErr := api .Auth .AuthEnabled (c )
141147
142148 // Handle error
143149 if authEnabledErr != nil {
144- // Return 500 if nginx is the proxy or if the request is using basic auth
145- if proxy .Proxy == "nginx" || basicAuth {
150+ // Return 500 if nginx is the proxy or if the request is not coming from a browser
151+ if proxy .Proxy == "nginx" || ! isBrowser {
146152 log .Error ().Err (authEnabledErr ).Msg ("Failed to check if auth is enabled" )
147153 c .JSON (500 , gin.H {
148154 "status" : 500 ,
@@ -186,8 +192,8 @@ func (api *API) SetupRoutes() {
186192
187193 // Check if there was an error
188194 if appAllowedErr != nil {
189- // Return 500 if nginx is the proxy or if the request is using basic auth
190- if proxy .Proxy == "nginx" || basicAuth {
195+ // Return 500 if nginx is the proxy or if the request is not coming from a browser
196+ if proxy .Proxy == "nginx" || ! isBrowser {
191197 log .Error ().Err (appAllowedErr ).Msg ("Failed to check if app is allowed" )
192198 c .JSON (500 , gin.H {
193199 "status" : 500 ,
@@ -208,9 +214,11 @@ func (api *API) SetupRoutes() {
208214 if ! appAllowed {
209215 log .Warn ().Str ("username" , userContext .Username ).Str ("host" , host ).Msg ("User not allowed" )
210216
211- // Return 401 if nginx is the proxy or if the request is using an Authorization header
212- if proxy .Proxy == "nginx" || basicAuth {
213- c .Header ("WWW-Authenticate" , "Basic realm=\" tinyauth\" " )
217+ // Set WWW-Authenticate header
218+ c .Header ("WWW-Authenticate" , "Basic realm=\" tinyauth\" " )
219+
220+ // Return 401 if nginx is the proxy or if the request is not coming from a browser
221+ if proxy .Proxy == "nginx" || ! isBrowser {
214222 c .JSON (401 , gin.H {
215223 "status" : 401 ,
216224 "message" : "Unauthorized" ,
@@ -252,9 +260,11 @@ func (api *API) SetupRoutes() {
252260 // The user is not logged in
253261 log .Debug ().Msg ("Unauthorized" )
254262
255- // Return 401 if nginx is the proxy or if the request is using an Authorization header
256- if proxy .Proxy == "nginx" || basicAuth {
257- c .Header ("WWW-Authenticate" , "Basic realm=\" tinyauth\" " )
263+ // Set www-authenticate header
264+ c .Header ("WWW-Authenticate" , "Basic realm=\" tinyauth\" " )
265+
266+ // Return 401 if nginx is the proxy or if the request is not coming from a browser
267+ if proxy .Proxy == "nginx" || ! isBrowser {
258268 c .JSON (401 , gin.H {
259269 "status" : 401 ,
260270 "message" : "Unauthorized" ,
0 commit comments