Skip to content

Commit a179b31

Browse files
routers/private: fix push-on-create being incorrectly triggered
The code here checks if the repo being requested doesn't exist. If it doesn't, then a write operation might create it. But a read operation doesn't make any sense, and should error out. So simply check the access mode. I assume this was the intent here, but only checked for one "verb" instead, while there exist other read-only verbs as well. And ofc more can be introduced in the future ;) Possibly some write verbs don't make sense as well (presumably those that only add stuff incrementally to existing repos)?
1 parent f528df9 commit a179b31

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

routers/private/serv.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,15 @@ func ServCommand(ctx *context.PrivateContext) {
136136
if err != nil {
137137
if repo_model.IsErrRepoNotExist(err) {
138138
repoExist = false
139-
for _, verb := range ctx.FormStrings("verb") {
140-
if verb == "git-upload-pack" {
141-
// User is fetching/cloning a non-existent repository
142-
log.Warn("Failed authentication attempt (cannot find repository: %s/%s) from %s", results.OwnerName, results.RepoName, ctx.RemoteAddr())
143-
ctx.JSON(http.StatusNotFound, private.Response{
144-
UserMsg: fmt.Sprintf("Cannot find repository: %s/%s", results.OwnerName, results.RepoName),
145-
})
146-
return
147-
}
139+
if mode == perm.AccessModeRead {
140+
// User is fetching/cloning a non-existent repository
141+
log.Warn("Failed authentication attempt (cannot find repository: %s/%s) from %s", results.OwnerName, results.RepoName, ctx.RemoteAddr())
142+
ctx.JSON(http.StatusNotFound, private.Response{
143+
UserMsg: fmt.Sprintf("Cannot find repository: %s/%s", results.OwnerName, results.RepoName),
144+
})
145+
return
148146
}
147+
// else fallthrough (push-to-create may kick in below)
149148
} else {
150149
log.Error("Unable to get repository: %s/%s Error: %v", results.OwnerName, results.RepoName, err)
151150
ctx.JSON(http.StatusInternalServerError, private.Response{

0 commit comments

Comments
 (0)