Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
adding security cookie attributes (#1832)
Browse files Browse the repository at this point in the history
Adds cookie settings (httpOnly and secure)
  • Loading branch information
paganotoni authored Nov 13, 2019
1 parent aa4fcdf commit 1baaa78
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@ func optionsWithDefaults(opts Options) Options {

if opts.SessionStore == nil {
secret := envy.Get("SESSION_SECRET", "")

if secret == "" && (opts.Env == "development" || opts.Env == "test") {
secret = "buffalo-secret"
}

// In production a SESSION_SECRET must be set!
if secret == "" {
if opts.Env == "development" || opts.Env == "test" {
secret = "buffalo-secret"
} else {
opts.Logger.Warn("Unless you set SESSION_SECRET env variable, your session storage is not protected!")
}
opts.Logger.Warn("Unless you set SESSION_SECRET env variable, your session storage is not protected!")
}
opts.SessionStore = sessions.NewCookieStore([]byte(secret))

cookieStore := sessions.NewCookieStore([]byte(secret))
//Cookie secure attributes, see: https://www.owasp.org/index.php/Testing_for_cookies_attributes_(OTG-SESS-002)
cookieStore.Options.HttpOnly = true
cookieStore.Options.Secure = true

opts.SessionStore = cookieStore
}
if opts.Worker == nil {
w := worker.NewSimpleWithContext(opts.Context)
Expand Down

0 comments on commit 1baaa78

Please sign in to comment.