Merge pull request 'Set Secure flag on session cookie for HTTPS' (#37) from fix/session-secure-flag into main
Reviewed-on: https://git.ts.mattnite.net/mattnite/forgejo-tickets/pulls/37
This commit is contained in:
commit
a0fa170a40
|
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ func main() {
|
|||
log.Info().Str("bot_login", forgejoClient.BotLogin).Msg("forgejo bot login initialized")
|
||||
}
|
||||
|
||||
sessionStore := auth.NewPGStore(db, []byte(cfg.SessionSecret))
|
||||
sessionStore := auth.NewPGStore(db, strings.HasPrefix(cfg.BaseURL, "https"), []byte(cfg.SessionSecret))
|
||||
authService := auth.NewService(db, sessionStore, emailClient)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ type PGStore struct {
|
|||
options *sessions.Options
|
||||
}
|
||||
|
||||
func NewPGStore(db *gorm.DB, keyPairs ...[]byte) *PGStore {
|
||||
func NewPGStore(db *gorm.DB, secure bool, keyPairs ...[]byte) *PGStore {
|
||||
return &PGStore{
|
||||
db: db,
|
||||
codecs: securecookie.CodecsFromPairs(keyPairs...),
|
||||
|
|
@ -36,6 +36,7 @@ func NewPGStore(db *gorm.DB, keyPairs ...[]byte) *PGStore {
|
|||
Path: "/",
|
||||
MaxAge: sessionMaxAge,
|
||||
HttpOnly: true,
|
||||
Secure: secure,
|
||||
SameSite: http.SameSiteLaxMode,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue