diff options
author | Gusted <gusted@noreply.codeberg.org> | 2024-04-06 14:21:35 +0200 |
---|---|---|
committer | Gusted <gusted@noreply.codeberg.org> | 2024-04-06 14:21:35 +0200 |
commit | d5fd40821e7778f0ab8ad62d8b4c25e56c0046dc (patch) | |
tree | 2ed144b7fc3b86f8fa96fea3cd40e80c1f772f49 /routers | |
parent | Merge pull request '[PORT] Refactor dropzone (#30232)' (#3048) from earl-warr... (diff) | |
parent | fix: cleanup webfinger URI parsing (diff) | |
download | forgejo-d5fd40821e7778f0ab8ad62d8b4c25e56c0046dc.tar.xz forgejo-d5fd40821e7778f0ab8ad62d8b4c25e56c0046dc.zip |
Merge pull request 'feat: extend webfinger to respond to profile page URIs' (#2883) from realaravinth/forgejo:cb-2870 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2883
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/webfinger.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index e4b2aacce8..099f6236a6 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -64,6 +64,63 @@ 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 + } + + p := strings.Trim(resource.Path, "/") + if len(p) == 0 { + ctx.Error(http.StatusNotFound) + return + } + + parts := strings.Split(p, "/") + + switch len(parts) { + case 1: // user + u, err = user_model.GetUserByName(ctx, parts[0]) + case 2: // repository + ctx.Error(http.StatusNotFound) + return + + case 3: + switch parts[2] { + case "issues": + ctx.Error(http.StatusNotFound) + return + + case "pulls": + ctx.Error(http.StatusNotFound) + return + + case "projects": + ctx.Error(http.StatusNotFound) + return + + default: + ctx.Error(http.StatusNotFound) + return + + } + case 4: + //nolint:gocritic + if parts[3] == "teams" { + ctx.Error(http.StatusNotFound) + return + + } else { + ctx.Error(http.StatusNotFound) + return + } + + default: + ctx.Error(http.StatusNotFound) + return + + } + default: ctx.Error(http.StatusBadRequest) return |