Skip to content

Commit

Permalink
Adds session cookie name option (#23)
Browse files Browse the repository at this point in the history
* Fixes #22
  • Loading branch information
amorey authored Feb 29, 2024
1 parent 57026d5 commit dff87fa
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/cmd/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Config struct {

// cookie options
Cookie struct {
Name string
Path string
Domain string
MaxAge int `mapstructure:"max-age"`
Expand Down Expand Up @@ -91,6 +92,7 @@ func DefaultConfig() Config {
cfg.Namespace = ""

cfg.Session.Secret = ""
cfg.Session.Cookie.Name = "session"
cfg.Session.Cookie.Path = "/"
cfg.Session.Cookie.Domain = ""
cfg.Session.Cookie.MaxAge = 36400 * 30
Expand Down
1 change: 1 addition & 0 deletions backend/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func main() {
appCfg.Namespace = cfg.Namespace
appCfg.AccessLogEnabled = cfg.Logging.AccessLogEnabled
appCfg.Session.Secret = cfg.Session.Secret
appCfg.Session.Cookie.Name = cfg.Session.Cookie.Name
appCfg.Session.Cookie.Path = cfg.Session.Cookie.Path
appCfg.Session.Cookie.Domain = cfg.Session.Cookie.Domain
appCfg.Session.Cookie.MaxAge = cfg.Session.Cookie.MaxAge
Expand Down
1 change: 1 addition & 0 deletions backend/hack/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kube-config: ${HOME}/.kube/config
session:
secret: REPLACEME
cookie:
name: mysession
path: /
max-age: 2592000
secure: false
Expand Down
2 changes: 2 additions & 0 deletions backend/internal/ginapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Config struct {

// cookie options
Cookie struct {
Name string
Path string
Domain string
MaxAge int
Expand Down Expand Up @@ -74,6 +75,7 @@ func DefaultConfig() Config {
cfg.AccessLogEnabled = true

cfg.Session.Secret = ""
cfg.Session.Cookie.Name = "session"
cfg.Session.Cookie.Path = "/"
cfg.Session.Cookie.Domain = ""
cfg.Session.Cookie.MaxAge = 36400 * 30
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/ginapp/ginapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewGinApp(config Config) (*GinApp, error) {
HttpOnly: config.Session.Cookie.HttpOnly,
SameSite: config.Session.Cookie.SameSite,
})
dynamicRoutes.Use(sessions.Sessions("session", sessionStore))
dynamicRoutes.Use(sessions.Sessions(config.Session.Cookie.Name, sessionStore))

// https://security.stackexchange.com/questions/147554/security-headers-for-a-web-api
// https://observatory.mozilla.org/faq/
Expand Down
1 change: 1 addition & 0 deletions backend/internal/ginapp/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func NewTestConfig() *Config {
cfg := Config{}
cfg.AccessLogEnabled = false
cfg.Session.Secret = "TESTSESSIONSECRET"
cfg.Session.Cookie.Name = "session"
cfg.CSRF.Enabled = false
cfg.CSRF.Secret = "TESTCSRFSECRET"
return &cfg
Expand Down

0 comments on commit dff87fa

Please sign in to comment.