Skip to content

Commit

Permalink
fix: set random session secret if not set (ngoduykhanh#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoduykhanh authored Aug 11, 2023
1 parent 364a43e commit b55543f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
flagSendgridApiKey string
flagEmailFrom string
flagEmailFromName string = "WireGuard UI"
flagSessionSecret string
flagSessionSecret string = util.RandomString(32)
flagWgConfTemplate string
flagBasePath string
)
Expand Down
11 changes: 11 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"io/fs"
"io/ioutil"
"math/rand"
"net"
"os"
"path"
Expand Down Expand Up @@ -529,3 +530,13 @@ func UpdateHashes(db store.IStore) error {
clientServerHashes.Client, clientServerHashes.Server = GetCurrentHash(db)
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)
}

0 comments on commit b55543f

Please sign in to comment.