cerca

lean forum software (pmc local branch)
Log | Files | Refs | README | LICENSE

commit 68576596f839f039c7b1b53817ce84e927659d90
parent b56815205d3ae007f5e0f9417d25e6ba5d7f0bc3
Author: cblgh <cblgh@cblgh.org>
Date:   Mon, 17 Jan 2022 19:44:38 +0100

process input allowlist & only store host

Diffstat:
Mrun.go | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/run.go b/run.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "net/url" "os" "strings" @@ -15,10 +16,15 @@ func readAllowlist(location string) []string { data, err := os.ReadFile(location) ed.Check(err, "read file") list := strings.Split(strings.TrimSpace(string(data)), "\n") - for i, fullpath := range list { - list[i] = strings.TrimPrefix(strings.TrimPrefix(fullpath, "https://"), "http://") + var processed []string + for _, fullpath := range list { + u, err := url.Parse(fullpath) + if err != nil { + continue + } + processed = append(processed, u.Host) } - return list + return processed } func complain(msg string) {