From 443c7cf6332510446914a816a590ecaf699b2edc Mon Sep 17 00:00:00 2001 From: Liran Cohen Date: Wed, 18 Jan 2023 17:44:32 +0000 Subject: [PATCH] trim trailing slash from expected and found relay URL, clean up --- nip42/nip42.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/nip42/nip42.go b/nip42/nip42.go index 8cdae9f..58016fa 100644 --- a/nip42/nip42.go +++ b/nip42/nip42.go @@ -2,6 +2,7 @@ package nip42 import ( "net/url" + "strings" "time" "github.com/nbd-wtf/go-nostr" @@ -41,16 +42,20 @@ func ValidateAuthEvent(event *nostr.Event, challenge string, relayURL string) (p return "", false } - expected, err1 := url.Parse(relayURL) - found, err2 := url.Parse(event.Tags.GetFirst([]string{"relay", ""}).Value()) - if err1 != nil || err2 != nil { + expected, err := url.Parse(strings.TrimSuffix(relayURL, "/")) + if err != nil { + return "", false + } + + found, err := url.Parse(strings.TrimSuffix(event.Tags.GetFirst([]string{"relay", ""}).Value(), "/")) + if err != nil { + return "", false + } + + if expected.Scheme != found.Scheme || + expected.Host != found.Host || + expected.Path != found.Path { return "", false - } else { - if expected.Scheme != found.Scheme || - expected.Host != found.Host || - expected.Path != found.Path { - return "", false - } } return event.PubKey, true