diff options
author | Aravinth Manivannan <realaravinth@batsense.net> | 2024-04-01 17:58:56 +0200 |
---|---|---|
committer | Earl Warren <earl-warren@noreply.codeberg.org> | 2024-04-04 18:52:25 +0200 |
commit | 8273f8b756d6727b802bbb294e5494fb8b3e9ee3 (patch) | |
tree | 73352b7c298ea1b87b9d0dc3bea6b80f0d89d7de | |
parent | fix: respond with 404 when webfingered with non-actor URIs (diff) | |
download | forgejo-8273f8b756d6727b802bbb294e5494fb8b3e9ee3.tar.xz forgejo-8273f8b756d6727b802bbb294e5494fb8b3e9ee3.zip |
feat: improve URI parsing in webfinger endpoint
-rw-r--r-- | routers/web/webfinger.go | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index c620059ec1..2eced4f05f 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -70,13 +70,57 @@ func WebfingerQuery(ctx *context.Context) { return } - parts := strings.Split(resource.Path, "/") - if len(parts) < 2 { // fragment[0] is empty space, fragment[1] may be username - ctx.Error(http.StatusBadRequest) + p, _ := strings.CutPrefix(resource.Path, "/") + p, _ = strings.CutSuffix(p, "/") + if len(p) == 0 { + ctx.Error(http.StatusNotFound) return } - u, err = user_model.GetUserByName(ctx, parts[1]) + 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: + // 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 |