From 44dff6fdd039f12f40571a49dd3dc63f61265635 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 6 Jul 2020 15:59:00 +0300 Subject: [PATCH] Auth: Fix POST request failures with anonymous access (#26049) Macaron context.QueryBool() seems to modify the request context that causes the POST and PUT requests to fail with: "http: proxy error: net/http: HTTP/1.x transport connection broken: http: ContentLength=333 with Body length 0" --- pkg/middleware/auth.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/middleware/auth.go b/pkg/middleware/auth.go index cf6aa4f2314..e26d8e12e3a 100644 --- a/pkg/middleware/auth.go +++ b/pkg/middleware/auth.go @@ -2,6 +2,7 @@ package middleware import ( "net/url" + "strconv" "strings" macaron "gopkg.in/macaron.v1" @@ -87,7 +88,13 @@ func RoleAuth(roles ...models.RoleType) macaron.Handler { func Auth(options *AuthOptions) macaron.Handler { return func(c *models.ReqContext) { - forceLogin := c.AllowAnonymous && c.QueryBool("forceLogin") + forceLogin := false + if c.AllowAnonymous { + forceLoginParam, err := strconv.ParseBool(c.Req.URL.Query().Get("forceLogin")) + if err == nil { + forceLogin = forceLoginParam + } + } requireLogin := !c.AllowAnonymous || forceLogin if !c.IsSignedIn && options.ReqSignedIn && requireLogin { notAuthorized(c)