Skip to content

Commit b55543f

Browse files
authored
fix: set random session secret if not set (ngoduykhanh#417)
1 parent 364a43e commit b55543f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var (
3838
flagSendgridApiKey string
3939
flagEmailFrom string
4040
flagEmailFromName string = "WireGuard UI"
41-
flagSessionSecret string
41+
flagSessionSecret string = util.RandomString(32)
4242
flagWgConfTemplate string
4343
flagBasePath string
4444
)

util/util.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"io/fs"
1111
"io/ioutil"
12+
"math/rand"
1213
"net"
1314
"os"
1415
"path"
@@ -529,3 +530,13 @@ func UpdateHashes(db store.IStore) error {
529530
clientServerHashes.Client, clientServerHashes.Server = GetCurrentHash(db)
530531
return db.SaveHashes(clientServerHashes)
531532
}
533+
534+
func RandomString(length int) string {
535+
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))
536+
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
537+
b := make([]byte, length)
538+
for i := range b {
539+
b[i] = charset[seededRand.Intn(len(charset))]
540+
}
541+
return string(b)
542+
}

0 commit comments

Comments
 (0)