44 _ "embed"
55 "fmt"
66 "github.com/TUM-Dev/meldeplattform/pkg/i18n"
7+ "github.com/TUM-Dev/meldeplattform/pkg/middleware"
78 "github.com/TUM-Dev/meldeplattform/pkg/model"
89 "github.com/gin-gonic/gin"
910 "gorm.io/gorm"
@@ -32,12 +33,15 @@ func NewApp() *App {
3233 }
3334 a .i18n = i
3435 a .engine .Use (gin .Logger (), gin .Recovery ())
36+ a .engine .Use (middleware .SecurityHeaders ())
3537 _ = a .engine .SetTrustedProxies (nil )
3638
3739 err = a .initCfg ()
3840 if err != nil {
3941 panic (fmt .Errorf ("init config: %v" , err ))
4042 }
43+ // Set secure cookie flag based on production mode
44+ middleware .SetSecureCookies (a .config .Mode == "prod" )
4145 if a .config .Mode == "prod" {
4246 // strip clientip from requests:
4347 a .engine .Use (func (c * gin.Context ) {
@@ -58,7 +62,8 @@ func (a *App) Run() error {
5862
5963func (a * App ) setLang (c * gin.Context ) {
6064 reqLang := c .Request .URL .Query ().Get ("lang" )
61- c .SetCookie ("lang" , reqLang , 60 * 60 * 24 * 365 , "/" , "" , false , true )
65+ secure := a .config .Mode == "prod"
66+ c .SetCookie ("lang" , reqLang , 60 * 60 * 24 * 365 , "/" , "" , secure , true )
6267 c .Redirect (http .StatusFound , "/" )
6368}
6469
0 commit comments