query unescape and pretty url finger licks Pass orig through url.QueryUnescape to prevent comparison fail. Also adds support for comparing with pretty URLs correctly. Also also, send the avatar URL in webfinger response for maximum vanity.
Anirudh Oppiliappan x@icyphox.sh
Wed, 14 Feb 2024 12:58:28 +0200
1 files changed,
21 insertions(+),
2 deletions(-)
jump to
M
web.go
→
web.go
@@ -29,6 +29,7 @@ "net/url"
"os" "os/signal" "path" + "path/filepath" "regexp" "sort" "strconv"@@ -2312,12 +2313,20 @@
var oldfingers = cache.New(cache.Options{Filler: func(orig string) ([]byte, bool) { if strings.HasPrefix(orig, "acct:") { orig = orig[5:] + } else { + orig, _ = url.QueryUnescape(orig) } + name := orig idx := strings.LastIndexByte(name, '/') if idx != -1 { + url := fmt.Sprintf("https://%s/%s/%s", serverName, "u", name) name = name[idx+1:] - if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig { + if strings.HasPrefix(name, "@") { + url = fmt.Sprintf("https://%s/%s", serverName, name) + name = name[1:] + } + if url != orig { ilog.Printf("foreign request rejected") name = "" }@@ -2349,7 +2358,17 @@ l2 := junk.New()
l2["rel"] = "http://webfinger.net/rel/profile-page" l2["type"] = "text/html" l2["href"] = pretty - j["links"] = []junk.Junk{l, l2} + l3 := junk.New() + l3["rel"] = "http://webfinger.net/rel/avatar" + + ext := filepath.Ext(user.Options.Avatar) + if ext[1:] == "jpg" { + l3["type"] = "image/jpeg" + } else if ext[1:] == "png" { + l3["type"] = "image/png" + } + l3["href"] = user.Options.Avatar + j["links"] = []junk.Junk{l, l2, l3} return j.ToBytes(), true }})