Monorepo for Tangled tangled.org

knotserver/git: reject requests to unknown repos #1169

merged opened by boltless.me targeting master from sl/lvnwqspuwzom
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mh5rm2se5o22
-1
Interdiff #1 โ†’ #2
knotserver/git.go

This file has not been changed.

-1
knotserver/router.go
··· 157 157 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 158 158 did := chi.URLParam(r, "did") 159 159 name := chi.URLParam(r, "name") 160 - // TODO: resolve repository, get repoPath path, ensure repository 161 160 repoPath, err := securejoin.SecureJoin(h.c.Repo.ScanPath, filepath.Join(did, name)) 162 161 if err != nil { 163 162 w.WriteHeader(http.StatusNotFound)

History

3 rounds 5 comments
sign up or login to add to the discussion
1 commit
expand
knotserver/git: reject requests to unknown repos
3/3 success
expand
expand 2 comments

tested and now it works as expected

before#

% git clone https://knot.tngl.boltless.dev/did:plc:cqojjfqu74dcdde3ql3imdjf/whatever
Cloning into 'whatever'...
fatal: protocol error: bad line length character: fail

after#

% git clone https://knot.tngl.boltless.dev/did:plc:cqojjfqu74dcdde3ql3imdjf/whatever
Cloning into 'whatever'...
remote: Repository not found
fatal: repository 'https://knot.tngl.boltless.dev/did:plc:cqojjfqu74dcdde3ql3imdjf/whatever/' not found
pull request successfully merged
1 commit
expand
knotserver/git: reject requests to unknown repos
3/3 success
expand
expand 0 comments
1 commit
expand
knotserver/git: reject requests to unknown repos
expand 3 comments

This solves the fatal: protocol error: bad line length character: fail bug while git clone over http.

Most cases, that error happens when target repository is not found. So I added a middleware resolveRepo to check the repository existence first and resolve its absolute path at one place.

knotserver/git.go:54: the text here can be "Failed to find repository path"

knotserver/git.go:99: likewise here

knotserver/router.go:168: why not handle th error as 500 here?

knotserver/router.go:166: do we know for sure that the repo path will include .git? none of the paths on my knot include this.

Ah right. I forgot to update after minimum PoC. Sorry for the incomplete PR.

I resubmitted. Unfortunately couldn't test it right now, but it should work fine.