From 4793720c20f7e47078526f2ae7dd7979df12b73e Mon Sep 17 00:00:00 2001 From: "icyphox.sh" Date: Wed, 16 Apr 2025 17:00:46 +0000 Subject: [PATCH] appview: state: verify if commit is a valid hash before fetching Fixes a crash when viewing a single commit, and possibly appending something like `.patch` to the end of it. The `result` from the knotserver is nil and then leads to a nil pointer deref later. --- appview/state/repo.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/appview/state/repo.go b/appview/state/repo.go index 908c2a2..22bafee 100644 --- a/appview/state/repo.go +++ b/appview/state/repo.go @@ -21,6 +21,7 @@ import ( "github.com/bluesky-social/indigo/atproto/syntax" securejoin "github.com/cyphar/filepath-securejoin" "github.com/go-chi/chi/v5" + "github.com/go-git/go-git/v5/plumbing" "tangled.sh/tangled.sh/core/api/tangled" "tangled.sh/tangled.sh/core/appview/auth" "tangled.sh/tangled.sh/core/appview/db" @@ -248,6 +249,12 @@ func (s *State) RepoCommit(w http.ResponseWriter, r *http.Request) { if !s.config.Dev { protocol = "https" } + + if !plumbing.IsHash(ref) { + s.pages.Error404(w) + return + } + resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/commit/%s", protocol, f.Knot, f.OwnerDid(), f.RepoName, ref)) if err != nil { log.Println("failed to reach knotserver", err) -- knotmirror 0.0.1