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

Commit

Permalink
Ensure only alphanumerics in generated config file name
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lundin committed Oct 12, 2019
1 parent 8fae238 commit db46cbe
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"path"
"regexp"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -43,6 +44,8 @@ var (
wgDNS = kingpin.Flag("wg-dns", "WireGuard client DNS server (optional)").Default("").String()

devUIServer = kingpin.Flag("dev-ui-server", "Developer mode: If specified, proxy all static assets to this endpoint").String()

filenameRe = regexp.MustCompile("[^a-zA-Z0-9]+")
)

type Server struct {
Expand Down Expand Up @@ -455,7 +458,7 @@ Endpoint = %s
}

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

0 comments on commit db46cbe

Please sign in to comment.