Open platform to collect and prioritize feedback
enhancement: force secure cookies when running on HTTPS (#455)
Guilherme Oenningf0091fad7cef
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.goindex 624da4919..641d204e4 100644--- a/app/pkg/web/context.go+++ b/app/pkg/web/context.go@@ -312,6 +312,7 @@ func (ctx *Context) AddCookie(name, value string, expires time.Time) {HttpOnly: true,Path: "/",Expires: expires,+ Secure: ctx.Request.IsSecure,})}@@ -323,6 +324,7 @@ func (ctx *Context) RemoveCookie(name string) {HttpOnly: true,MaxAge: -1,Expires: time.Now().Add(-100 * time.Hour),+ Secure: ctx.Request.IsSecure,})}diff --git a/app/pkg/web/oauth.go b/app/pkg/web/oauth.goindex 465e79f8a..dc2116ad4 100644--- a/app/pkg/web/oauth.go+++ b/app/pkg/web/oauth.go@@ -130,7 +130,6 @@ func (s *OAuthService) GetProfile(provider string, code string) (*oauth.UserProf//ParseProfileResponse parses profile response into UserProfile modelfunc (s *OAuthService) ParseProfileResponse(body string, config *models.OAuthConfig) (*oauth.UserProfile, error) {query := jsonq.New(body)- println(body)profile := &oauth.UserProfile{ID: strings.TrimSpace(query.String(config.JSONUserIDPath)),Name: strings.TrimSpace(query.String(config.JSONNamePath)),diff --git a/app/pkg/web/request.go b/app/pkg/web/request.goindex 78917a636..163d08d5e 100644--- a/app/pkg/web/request.go+++ b/app/pkg/web/request.go@@ -14,6 +14,7 @@ type Request struct {Method stringContentLength int64Body string+ IsSecure boolURL *url.URL}@@ -49,6 +50,7 @@ func WrapRequest(request *http.Request) Request {ContentLength: request.ContentLength,Body: string(bodyBytes),URL: u,+ IsSecure: protocol == "https",}}diff --git a/app/pkg/web/request_test.go b/app/pkg/web/request_test.goindex 413427a08..2140f8721 100644--- a/app/pkg/web/request_test.go+++ b/app/pkg/web/request_test.go@@ -1,6 +1,7 @@package web_testimport (+ "crypto/tls""net/http""testing"@@ -28,6 +29,7 @@ func TestRequest_Basic(t *testing.T) {Expect(req.URL.Scheme).Equals("http")Expect(req.URL.RequestURI()).Equals("/")Expect(req.URL.String()).Equals("http://helloworld.com")+ Expect(req.IsSecure).Equals(false)}func TestRequest_WithPort(t *testing.T) {@@ -72,6 +74,7 @@ func TestRequest_BehindTLSTerminationProxy(t *testing.T) {Expect(req.Method).Equals("GET")Expect(req.URL.Hostname()).Equals("feedback.mycompany.com")Expect(req.URL.Scheme).Equals("https")+ Expect(req.IsSecure).Equals(true)}func TestRequest_FullURL(t *testing.T) {@@ -79,13 +82,15 @@ func TestRequest_FullURL(t *testing.T) {req := web.WrapRequest(&http.Request{+ TLS: &tls.ConnectionState{},Host: "demo.test.fider.io",RequestURI: "/echo?value=Jon",},)- Expect(req.URL.String()).Equals("http://demo.test.fider.io/echo?value=Jon")+ Expect(req.URL.String()).Equals("https://demo.test.fider.io/echo?value=Jon")Expect(req.URL.Path).Equals("/echo")Expect(req.URL.Query().Get("value")).Equals("Jon")Expect(req.URL.RequestURI()).Equals("/echo?value=Jon")+ Expect(req.IsSecure).Equals(true)}diff --git a/app/pkg/web/util/webutil.go b/app/pkg/web/util/webutil.goindex 165e57adb..1afb9b0e9 100644--- a/app/pkg/web/util/webutil.go+++ b/app/pkg/web/util/webutil.go@@ -48,6 +48,7 @@ func SetSignUpAuthCookie(ctx web.Context, user *models.User) {HttpOnly: true,Path: "/",Expires: time.Now().Add(5 * time.Minute),+ Secure: ctx.Request.IsSecure,})}@@ -62,6 +63,7 @@ func GetSignUpAuthCookie(ctx web.Context) string {HttpOnly: true,MaxAge: -1,Expires: time.Now().Add(-100 * time.Hour),+ Secure: ctx.Request.IsSecure,})return cookie.Value}