Skip to content

Commit

Permalink
security: clean path before uploading blocklists
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Dec 14, 2024
1 parent 012bd39 commit f5c3020
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -105,6 +106,7 @@ func updateBlockCache(blockCache *MemoryBlockCache, sourceDirs []string) error {
logger.Debugf("loading blocked domains from %d locations...\n", len(sourceDirs))

for _, dir := range sourceDirs {
dir = filepath.Clean(dir)
if _, err := os.Stat(dir); os.IsNotExist(err) {
logger.Errorf("directory %s not found, skipping\n", dir)
continue
Expand Down Expand Up @@ -133,7 +135,7 @@ func updateBlockCache(blockCache *MemoryBlockCache, sourceDirs []string) error {
}

func parseHostFile(fileName string, blockCache *MemoryBlockCache) error {
file, err := os.Open(fileName)
file, err := os.Open(path.Clean(fileName))
if err != nil {
return fmt.Errorf("error opening file: %s", err)
}
Expand Down

0 comments on commit f5c3020

Please sign in to comment.