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
+10 -6
Interdiff #0 โ†’ #1
+3 -3
knotserver/git.go
··· 17 17 repoPath, ok := repoPathFromcontext(r.Context()) 18 18 if !ok { 19 19 w.WriteHeader(http.StatusInternalServerError) 20 - w.Write([]byte("Failed to found repository path")) 20 + w.Write([]byte("Failed to find repository path")) 21 21 return 22 22 } 23 23 ··· 51 51 repo, ok := repoPathFromcontext(r.Context()) 52 52 if !ok { 53 53 w.WriteHeader(http.StatusInternalServerError) 54 - w.Write([]byte("Failed to found repository path")) 54 + w.Write([]byte("Failed to find repository path")) 55 55 return 56 56 } 57 57 ··· 96 96 repo, ok := repoPathFromcontext(r.Context()) 97 97 if !ok { 98 98 w.WriteHeader(http.StatusInternalServerError) 99 - w.Write([]byte("Failed to found repository path")) 99 + w.Write([]byte("Failed to find repository path")) 100 100 return 101 101 } 102 102
+7 -3
knotserver/router.go
··· 160 160 // TODO: resolve repository, get repoPath path, ensure repository 161 161 repoPath, err := securejoin.SecureJoin(h.c.Repo.ScanPath, filepath.Join(did, name)) 162 162 if err != nil { 163 - panic("unimplemented") 163 + w.WriteHeader(http.StatusNotFound) 164 + w.Write([]byte("Repository not found")) 165 + return 164 166 } 165 167 166 - exist, err := isDir(filepath.Join(repoPath, ".git")) 168 + exist, err := isDir(repoPath) 167 169 if err != nil { 168 - panic("unimplemented") 170 + w.WriteHeader(http.StatusInternalServerError) 171 + w.Write([]byte("Failed to check repository path")) 172 + return 169 173 } 170 174 if !exist { 171 175 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.