Skip to content

Commit da0460d

Browse files
lunnyzeripath
andauthored
Prevent git operations for inactive users (#13527) (#13537)
* prevent git operations for inactive users * Some fixes * Deny push to the repositories which's owner is inactive * deny operations also when user is ProhibitLogin Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
1 parent 480efbd commit da0460d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

routers/private/serv.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func ServNoCommand(ctx *macaron.Context) {
6161
})
6262
return
6363
}
64+
if !user.IsActive || user.ProhibitLogin {
65+
ctx.JSON(http.StatusForbidden, map[string]interface{}{
66+
"err": "Your account is disabled.",
67+
})
68+
return
69+
}
6470
results.Owner = user
6571
}
6672
ctx.JSON(http.StatusOK, &results)
@@ -98,9 +104,28 @@ func ServCommand(ctx *macaron.Context) {
98104
results.RepoName = repoName[:len(repoName)-5]
99105
}
100106

107+
owner, err := models.GetUserByName(results.OwnerName)
108+
if err != nil {
109+
log.Error("Unable to get repository owner: %s/%s Error: %v", results.OwnerName, results.RepoName, err)
110+
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
111+
"results": results,
112+
"type": "InternalServerError",
113+
"err": fmt.Sprintf("Unable to get repository owner: %s/%s %v", results.OwnerName, results.RepoName, err),
114+
})
115+
return
116+
}
117+
if !owner.IsActive {
118+
ctx.JSON(http.StatusForbidden, map[string]interface{}{
119+
"results": results,
120+
"type": "ForbiddenError",
121+
"err": "Repository cannot be accessed, you could retry it later",
122+
})
123+
return
124+
}
125+
101126
// Now get the Repository and set the results section
102127
repoExist := true
103-
repo, err := models.GetRepositoryByOwnerAndName(results.OwnerName, results.RepoName)
128+
repo, err := models.GetRepositoryByName(owner.ID, results.RepoName)
104129
if err != nil {
105130
if models.IsErrRepoNotExist(err) {
106131
repoExist = false
@@ -127,6 +152,7 @@ func ServCommand(ctx *macaron.Context) {
127152
}
128153

129154
if repoExist {
155+
repo.Owner = owner
130156
repo.OwnerName = ownerName
131157
results.RepoID = repo.ID
132158

@@ -238,6 +264,14 @@ func ServCommand(ctx *macaron.Context) {
238264
})
239265
return
240266
}
267+
268+
if !user.IsActive || user.ProhibitLogin {
269+
ctx.JSON(http.StatusForbidden, map[string]interface{}{
270+
"err": "Your account is disabled.",
271+
})
272+
return
273+
}
274+
241275
results.UserName = user.Name
242276
}
243277

routers/repo/http.go

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ func HTTP(ctx *context.Context) {
104104
ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err)
105105
return
106106
}
107+
if !owner.IsActive {
108+
ctx.HandleText(http.StatusForbidden, "Repository cannot be accessed. You cannot push or open issues/pull-requests.")
109+
return
110+
}
107111

108112
repoExist := true
109113
repo, err := models.GetRepositoryByName(owner.ID, reponame)
@@ -243,6 +247,11 @@ func HTTP(ctx *context.Context) {
243247
}
244248
}
245249

250+
if !authUser.IsActive || authUser.ProhibitLogin {
251+
ctx.HandleText(http.StatusForbidden, "Your account is disabled.")
252+
return
253+
}
254+
246255
if repoExist {
247256
perm, err := models.GetUserRepoPermission(repo, authUser)
248257
if err != nil {

0 commit comments

Comments
 (0)