Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit db46cbe

Browse files
author
Daniel Lundin
committed
Ensure only alphanumerics in generated config file name
1 parent 8fae238 commit db46cbe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

server.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"os"
1313
"path"
14+
"regexp"
1415
"strconv"
1516
"strings"
1617
"sync"
@@ -43,6 +44,8 @@ var (
4344
wgDNS = kingpin.Flag("wg-dns", "WireGuard client DNS server (optional)").Default("").String()
4445

4546
devUIServer = kingpin.Flag("dev-ui-server", "Developer mode: If specified, proxy all static assets to this endpoint").String()
47+
48+
filenameRe = regexp.MustCompile("[^a-zA-Z0-9]+")
4649
)
4750

4851
type Server struct {
@@ -455,7 +458,7 @@ Endpoint = %s
455458
}
456459

457460
if format == "config" {
458-
filename := fmt.Sprintf("%s.conf", client.Name)
461+
filename := fmt.Sprintf("%s.conf", filenameRe.ReplaceAllString(client.Name, "_"))
459462
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename))
460463
w.Header().Set("Content-Type", "application/config")
461464
w.WriteHeader(http.StatusOK)

0 commit comments

Comments
 (0)