aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-11-13 10:51:32 +0800
committerGitHub <noreply@github.com>2020-11-13 10:51:32 +0800
commitda0460dea092194fb6af68e73e1e992d84b552aa (patch)
tree7d8a94aa3271ae79d67bf8bcc62b70f94b80c2c2
parent480efbdb96e4092493ec1e3683b2ab688ac95096 (diff)
downloadgitea-da0460dea092194fb6af68e73e1e992d84b552aa.tar.gz
gitea-da0460dea092194fb6af68e73e1e992d84b552aa.zip
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>
-rw-r--r--routers/private/serv.go36
-rw-r--r--routers/repo/http.go9
2 files changed, 44 insertions, 1 deletions
diff --git a/routers/private/serv.go b/routers/private/serv.go
index d5b5fcc8f7..eba431785b 100644
--- a/routers/private/serv.go
+++ b/routers/private/serv.go
@@ -61,6 +61,12 @@ func ServNoCommand(ctx *macaron.Context) {
})
return
}
+ if !user.IsActive || user.ProhibitLogin {
+ ctx.JSON(http.StatusForbidden, map[string]interface{}{
+ "err": "Your account is disabled.",
+ })
+ return
+ }
results.Owner = user
}
ctx.JSON(http.StatusOK, &results)
@@ -98,9 +104,28 @@ func ServCommand(ctx *macaron.Context) {
results.RepoName = repoName[:len(repoName)-5]
}
+ owner, err := models.GetUserByName(results.OwnerName)
+ if err != nil {
+ log.Error("Unable to get repository owner: %s/%s Error: %v", results.OwnerName, results.RepoName, err)
+ ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
+ "results": results,
+ "type": "InternalServerError",
+ "err": fmt.Sprintf("Unable to get repository owner: %s/%s %v", results.OwnerName, results.RepoName, err),
+ })
+ return
+ }
+ if !owner.IsActive {
+ ctx.JSON(http.StatusForbidden, map[string]interface{}{
+ "results": results,
+ "type": "ForbiddenError",
+ "err": "Repository cannot be accessed, you could retry it later",
+ })
+ return
+ }
+
// Now get the Repository and set the results section
repoExist := true
- repo, err := models.GetRepositoryByOwnerAndName(results.OwnerName, results.RepoName)
+ repo, err := models.GetRepositoryByName(owner.ID, results.RepoName)
if err != nil {
if models.IsErrRepoNotExist(err) {
repoExist = false
@@ -127,6 +152,7 @@ func ServCommand(ctx *macaron.Context) {
}
if repoExist {
+ repo.Owner = owner
repo.OwnerName = ownerName
results.RepoID = repo.ID
@@ -238,6 +264,14 @@ func ServCommand(ctx *macaron.Context) {
})
return
}
+
+ if !user.IsActive || user.ProhibitLogin {
+ ctx.JSON(http.StatusForbidden, map[string]interface{}{
+ "err": "Your account is disabled.",
+ })
+ return
+ }
+
results.UserName = user.Name
}
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 1eec033882..8cb4827f48 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -104,6 +104,10 @@ func HTTP(ctx *context.Context) {
ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err)
return
}
+ if !owner.IsActive {
+ ctx.HandleText(http.StatusForbidden, "Repository cannot be accessed. You cannot push or open issues/pull-requests.")
+ return
+ }
repoExist := true
repo, err := models.GetRepositoryByName(owner.ID, reponame)
@@ -243,6 +247,11 @@ func HTTP(ctx *context.Context) {
}
}
+ if !authUser.IsActive || authUser.ProhibitLogin {
+ ctx.HandleText(http.StatusForbidden, "Your account is disabled.")
+ return
+ }
+
if repoExist {
perm, err := models.GetUserRepoPermission(repo, authUser)
if err != nil {