Skip to content

Commit ee0097f

Browse files
lunnyzeripath
andauthored
Prevent git operations for inactive users (#13527) (#13536)
* 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 122f8f8 commit ee0097f

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

routers/private/serv.go

+35-10
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

@@ -217,15 +243,6 @@ func ServCommand(ctx *macaron.Context) {
217243
// so for now use the owner of the repository
218244
results.UserName = results.OwnerName
219245
results.UserID = repo.OwnerID
220-
if err = repo.GetOwner(); err != nil {
221-
log.Error("Unable to get owner for repo %-v. Error: %v", repo, err)
222-
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
223-
"results": results,
224-
"type": "InternalServerError",
225-
"err": fmt.Sprintf("Unable to get owner for repo: %s/%s.", results.OwnerName, results.RepoName),
226-
})
227-
return
228-
}
229246
if !repo.Owner.KeepEmailPrivate {
230247
results.UserEmail = repo.Owner.Email
231248
}
@@ -250,6 +267,14 @@ func ServCommand(ctx *macaron.Context) {
250267
})
251268
return
252269
}
270+
271+
if !user.IsActive || user.ProhibitLogin {
272+
ctx.JSON(http.StatusForbidden, map[string]interface{}{
273+
"err": "Your account is disabled.",
274+
})
275+
return
276+
}
277+
253278
results.UserName = user.Name
254279
if !user.KeepEmailPrivate {
255280
results.UserEmail = user.Email

routers/repo/http.go

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

109113
repoExist := true
110114
repo, err := models.GetRepositoryByName(owner.ID, reponame)
@@ -244,6 +248,11 @@ func HTTP(ctx *context.Context) {
244248
}
245249
}
246250

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

0 commit comments

Comments
 (0)