summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAravinth Manivannan <realaravinth@batsense.net>2024-03-24 07:07:01 +0100
committerEarl Warren <earl-warren@noreply.codeberg.org>2024-04-04 18:52:25 +0200
commitfc31f145078e3c22d7a0aa9de2bca77f6d503469 (patch)
treece8aba98dfa799ac209cf32628bb821b6b658916
parentMerge pull request '[BUG] Fix crash in issue forms' (#3012) from gusted/forge... (diff)
downloadforgejo-fc31f145078e3c22d7a0aa9de2bca77f6d503469.tar.xz
forgejo-fc31f145078e3c22d7a0aa9de2bca77f6d503469.zip
feat: extend webfinger to respond to profile page URIs
-rw-r--r--routers/web/webfinger.go13
-rw-r--r--tests/integration/webfinger_test.go12
2 files changed, 25 insertions, 0 deletions
diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go
index e4b2aacce8..c620059ec1 100644
--- a/routers/web/webfinger.go
+++ b/routers/web/webfinger.go
@@ -64,6 +64,19 @@ func WebfingerQuery(ctx *context.Context) {
if u != nil && u.KeepEmailPrivate {
err = user_model.ErrUserNotExist{}
}
+ case "https", "http":
+ if resource.Host != appURL.Host {
+ ctx.Error(http.StatusBadRequest)
+ return
+ }
+
+ parts := strings.Split(resource.Path, "/")
+ if len(parts) < 2 { // fragment[0] is empty space, fragment[1] may be username
+ ctx.Error(http.StatusBadRequest)
+ return
+ }
+
+ u, err = user_model.GetUserByName(ctx, parts[1])
default:
ctx.Error(http.StatusBadRequest)
return
diff --git a/tests/integration/webfinger_test.go b/tests/integration/webfinger_test.go
index 55fb211779..cdc7d94ebb 100644
--- a/tests/integration/webfinger_test.go
+++ b/tests/integration/webfinger_test.go
@@ -66,4 +66,16 @@ func TestWebfinger(t *testing.T) {
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=mailto:%s", user.Email))
MakeRequest(t, req, http.StatusNotFound)
+
+ req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=http://%s/%s/foo", appURL.Host, user.Name))
+ session.MakeRequest(t, req, http.StatusOK)
+
+ req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=https://%s/%s", appURL.Host, user.Name))
+ session.MakeRequest(t, req, http.StatusOK)
+
+ req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=http://%s", appURL.Host))
+ MakeRequest(t, req, http.StatusBadRequest)
+
+ req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=http://%s/%s/foo", "example.com", user.Name))
+ MakeRequest(t, req, http.StatusBadRequest)
}