Skip to content

Commit e9e9165

Browse files
committed
Security pass
1 parent a201c4d commit e9e9165

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

internal/discord/client_maprando.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"os"
1313
"path/filepath"
14+
"regexp"
1415
"strconv"
1516
"strings"
1617
"sync"
@@ -368,6 +369,12 @@ func (c *MapRandoClient) Unlock(seedName string, presetName string) error {
368369
}
369370

370371
func (c *MapRandoClient) unlockAt(baseURL string, seedName string) error {
372+
// Security: strictly validate the seedName to prevent path traversal
373+
var validSeedRegex = regexp.MustCompile(`^[a-zA-Z0-9_\-]+$`)
374+
if !validSeedRegex.MatchString(seedName) {
375+
return fmt.Errorf("invalid seed name format: strictly alphanumeric and dashes allowed")
376+
}
377+
371378
data := url.Values{}
372379
data.Set("spoiler_token", c.spoilerToken)
373380

internal/discord/cmd_maprando.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log/slog"
66
"math"
77
"os"
8-
"regexp"
98
"strings"
109

1110
"github.com/bwmarrin/discordgo"
@@ -247,13 +246,6 @@ func MapRandoUnlockCommand(randoClient *MapRandoClient) (*discordgo.ApplicationC
247246

248247
seedName := strings.TrimSpace(options[0].StringValue())
249248

250-
// Input validation: ensure the seed name is strictly alphanumeric/dashes
251-
var validSeedRegex = regexp.MustCompile(`^[a-zA-Z0-9_\-]+$`)
252-
if !validSeedRegex.MatchString(seedName) {
253-
respondError(s, i, "Invalid seed name. Only alphanumeric characters, dashes, and underscores are allowed.")
254-
return
255-
}
256-
257249
err := randoClient.Unlock(seedName, "")
258250
if err != nil {
259251
slog.Error("Failed to unlock seed", "error", err, "seed", seedName)

0 commit comments

Comments
 (0)