Skip to content
Snippets Groups Projects
Commit 43eb2d5f authored by Bolke de Bruin's avatar Bolke de Bruin
Browse files

Make session length configurable

parent 2abf83f0
No related branches found
No related tags found
Loading
......@@ -45,6 +45,7 @@ type ServerConfig struct {
SessionKey string `koanf:"sessionkey"`
SessionEncryptionKey string `koanf:"sessionencryptionkey"`
SessionStore string `koanf:"sessionstore"`
MaxSessionLength int `koanf:"maxsessionlength"`
SendBuf int `koanf:"sendbuf"`
ReceiveBuf int `koanf:"receivebuf"`
Tls string `koanf:"tls"`
......
......@@ -94,7 +94,11 @@ func main() {
security.Hosts = conf.Server.Hosts
// init session store
web.InitStore([]byte(conf.Server.SessionKey), []byte(conf.Server.SessionEncryptionKey), conf.Server.SessionStore)
web.InitStore([]byte(conf.Server.SessionKey),
[]byte(conf.Server.SessionEncryptionKey),
conf.Server.SessionStore,
conf.Server.MaxSessionLength,
)
// configure web backend
w := &web.Config{
......
......@@ -17,7 +17,7 @@ const (
var sessionStore sessions.Store
func InitStore(sessionKey []byte, encryptionKey []byte, storeType string) {
func InitStore(sessionKey []byte, encryptionKey []byte, storeType string, maxLength int) {
if len(sessionKey) < 32 {
log.Fatal("Session key too small")
}
......@@ -30,8 +30,11 @@ func InitStore(sessionKey []byte, encryptionKey []byte, storeType string) {
fs := sessions.NewFilesystemStore(os.TempDir(), sessionKey, encryptionKey)
// set max length
log.Printf("Setting maximum session storage to %d bytes", maxSessionLength)
fs.MaxLength(maxSessionLength)
if maxLength == 0 {
maxLength = maxSessionLength
}
log.Printf("Setting maximum session storage to %d bytes", maxLength)
fs.MaxLength(maxLength)
sessionStore = fs
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment