summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2023-03-23 18:21:59 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2023-03-23 18:21:59 +0300
commite1e1498c97c929821c3b84ff7dd1753fe3180ce4 (patch)
tree2c4544b623cfec4474c5d1e4f0388b3f6b99d017
parentd978dcc025da82176a6824fd596a545f431aa999 (diff)
downloadstatic-wm-e1e1498c97c929821c3b84ff7dd1753fe3180ce4.tar.gz
static-wm-e1e1498c97c929821c3b84ff7dd1753fe3180ce4.zip
fix: add check for empty source host
-rw-r--r--main.go3
-rw-r--r--main_test.go1
2 files changed, 3 insertions, 1 deletions
diff --git a/main.go b/main.go
index 41f8334..366ebde 100644
--- a/main.go
+++ b/main.go
@@ -21,11 +21,12 @@ type endpoint struct {
// ServeHTTP is http.Handler implementation.
func (ep endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
source, err := url.Parse(r.PostFormValue("source"))
- if err != nil {
+ if err != nil || source.Host == "" {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(errSrcInvalid))
return
}
+
if source.Scheme != "http" && source.Scheme != "https" {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(errInvalidScheme))
diff --git a/main_test.go b/main_test.go
index e88c5b7..48ba1e9 100644
--- a/main_test.go
+++ b/main_test.go
@@ -19,6 +19,7 @@ func TestSyncRejection(t *testing.T) {
expect string
}{
{"invalid source", "https||:example.org/somewhere", "my.site/part/target", errSrcInvalid},
+ {"empty source", "http://", "https://my.site/part/target", errSrcInvalid},
{"target no accepted", "https://example.org/somewhere", "wrong.site/tgt", errTgtNotAccepted},
{"wrong source scheme", "ftp://example.org/somewhere", "http://my.site/part/tgt", errInvalidScheme},
{"wrong target scheme", "http://example.org/somewhere", "ssh://my.site/part/tgt", errInvalidScheme},