all repos — elgit @ da194b5aa1add000c1925fcb02239ad0e327e2bc

fork of legit: web frontend for git, written in go

extract repo name/path mangling to middleware

Alan Pearce
commit

da194b5aa1add000c1925fcb02239ad0e327e2bc

parent

10cfdcf04c8edac269a776a2d8fb53cc21223e25

1 file changed, 23 insertions(+), 0 deletions(-)

changed files
M routes/handler.goroutes/handler.go
@@ -5,6 +5,7 @@ "fmt"
"io/fs" "log" "net" + "path" "path/filepath" "strconv" "strings"
@@ -113,6 +114,28 @@ return srv
} func (d deps) mountRepoPaths(router *atreugo.Router) { + router.UseBefore(func(rc *atreugo.RequestCtx) error { + category, _ := rc.UserValue("category").(string) + name, _ := rc.UserValue("name").(string) + repoName := path.Join(category, name) + + if d.isNotAllowed(repoName) { + log.Printf("access not allowed: %s", repoName) + + return ErrNotFound + } + path, err := d.GetCleanPath(repoName) + if err != nil { + log.Printf("getcleanpath error: %v", err) + + return ErrNotFound + } + + rc.SetUserValue("repoName", repoName) + rc.SetUserValue("repoPath", path) + + return rc.Next() + }) router.GET("/tree/{ref}/{rest:*}", d.RepoTree) router.GET("/blob/{ref}/{rest:*}", d.FileContent) router.GET("/tree/{ref}/", d.RepoTree)