fix: set random session secret if not set (#417)

This commit is contained in:
Khanh Ngo 2023-08-11 11:48:51 +02:00 committed by GitHub
parent 364a43e3dc
commit b55543f424
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -38,7 +38,7 @@ var (
flagSendgridApiKey string flagSendgridApiKey string
flagEmailFrom string flagEmailFrom string
flagEmailFromName string = "WireGuard UI" flagEmailFromName string = "WireGuard UI"
flagSessionSecret string flagSessionSecret string = util.RandomString(32)
flagWgConfTemplate string flagWgConfTemplate string
flagBasePath string flagBasePath string
) )

View file

@ -9,6 +9,7 @@ import (
"io" "io"
"io/fs" "io/fs"
"io/ioutil" "io/ioutil"
"math/rand"
"net" "net"
"os" "os"
"path" "path"
@ -529,3 +530,13 @@ func UpdateHashes(db store.IStore) error {
clientServerHashes.Client, clientServerHashes.Server = GetCurrentHash(db) clientServerHashes.Client, clientServerHashes.Server = GetCurrentHash(db)
return db.SaveHashes(clientServerHashes) return db.SaveHashes(clientServerHashes)
} }
func RandomString(length int) string {
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}