From 98a8becb2089177e9b8e08b2aca1c993918fd4fb Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 1 Mar 2022 20:40:22 +0100 Subject: [PATCH 1/2] Send 404 on `/{org}.gpg` - Organisation's currently cannot have any GPG/SSH keys, so send 404 status instead of a internal server error. - Resolves #18952 --- routers/web/org/home.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index d07e2993b2058..c1cf7e74718fc 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -5,7 +5,9 @@ package org import ( + "fmt" "net/http" + "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" @@ -23,7 +25,14 @@ const ( // Home show organization home page func Home(ctx *context.Context) { - ctx.SetParams(":org", ctx.Params(":username")) + uname := ctx.Params(":username") + + if strings.HasSuffix(uname, ".keys") || strings.HasSuffix(uname, ".gpg") { + ctx.NotFound("Unimplemented feature", fmt.Errorf("organisations has no keys")) + return + } + + ctx.SetParams(":org", uname) context.HandleOrgAssignment(ctx) if ctx.Written() { return From af5f192a451ca7dfcefd3df2a4173d04dc5e75b9 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 1 Mar 2022 22:03:25 +0100 Subject: [PATCH 2/2] Don't send error --- routers/web/org/home.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index c1cf7e74718fc..fc81ceb719efb 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -5,7 +5,6 @@ package org import ( - "fmt" "net/http" "strings" @@ -28,7 +27,7 @@ func Home(ctx *context.Context) { uname := ctx.Params(":username") if strings.HasSuffix(uname, ".keys") || strings.HasSuffix(uname, ".gpg") { - ctx.NotFound("Unimplemented feature", fmt.Errorf("organisations has no keys")) + ctx.NotFound("", nil) return }