aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-11-26 07:21:41 +0800
committerGitHub <noreply@github.com>2023-11-26 07:21:41 +0800
commitdfd511faf35fef68557e53763f9b06e5a139565d (patch)
tree79deaf19cd581543d1ad282a3f8ea46c7f411d76 /routers/web/repo
parent41b2d0be931dcac7d372efb0f8207fcb8379fce1 (diff)
downloadgitea-dfd511faf35fef68557e53763f9b06e5a139565d.tar.gz
gitea-dfd511faf35fef68557e53763f9b06e5a139565d.zip
Fix comment permissions (#28213) (#28217)
backport #28213 This PR will fix some missed checks for private repositories' data on web routes and API routes.
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/issue.go30
-rw-r--r--routers/web/repo/issue_content_history.go2
-rw-r--r--routers/web/repo/projects.go2
-rw-r--r--routers/web/repo/release.go37
4 files changed, 58 insertions, 13 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index f629a90476..99f3500c6f 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -2968,6 +2968,11 @@ func UpdateCommentContent(ctx *context.Context) {
return
}
+ if comment.Issue.RepoID != ctx.Repo.Repository.ID {
+ ctx.NotFound("CompareRepoID", issues_model.ErrCommentNotExist{})
+ return
+ }
+
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
ctx.Error(http.StatusForbidden)
return
@@ -3034,6 +3039,11 @@ func DeleteComment(ctx *context.Context) {
return
}
+ if comment.Issue.RepoID != ctx.Repo.Repository.ID {
+ ctx.NotFound("CompareRepoID", issues_model.ErrCommentNotExist{})
+ return
+ }
+
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
ctx.Error(http.StatusForbidden)
return
@@ -3160,6 +3170,11 @@ func ChangeCommentReaction(ctx *context.Context) {
return
}
+ if comment.Issue.RepoID != ctx.Repo.Repository.ID {
+ ctx.NotFound("CompareRepoID", issues_model.ErrCommentNotExist{})
+ return
+ }
+
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull)) {
if log.IsTrace() {
if ctx.IsSigned {
@@ -3303,6 +3318,21 @@ func GetCommentAttachments(ctx *context.Context) {
return
}
+ if err := comment.LoadIssue(ctx); err != nil {
+ ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
+ return
+ }
+
+ if comment.Issue.RepoID != ctx.Repo.Repository.ID {
+ ctx.NotFound("CompareRepoID", issues_model.ErrCommentNotExist{})
+ return
+ }
+
+ if !ctx.Repo.Permission.CanReadIssuesOrPulls(comment.Issue.IsPull) {
+ ctx.NotFound("CanReadIssuesOrPulls", issues_model.ErrCommentNotExist{})
+ return
+ }
+
if !comment.Type.HasAttachmentSupport() {
ctx.ServerError("GetCommentAttachments", fmt.Errorf("comment type %v does not support attachments", comment.Type))
return
diff --git a/routers/web/repo/issue_content_history.go b/routers/web/repo/issue_content_history.go
index 3dd7725c21..b6345e434c 100644
--- a/routers/web/repo/issue_content_history.go
+++ b/routers/web/repo/issue_content_history.go
@@ -118,7 +118,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
}
historyID := ctx.FormInt64("history_id")
- history, prevHistory, err := issues_model.GetIssueContentHistoryAndPrev(ctx, historyID)
+ history, prevHistory, err := issues_model.GetIssueContentHistoryAndPrev(ctx, issue.ID, historyID)
if err != nil {
ctx.JSON(http.StatusNotFound, map[string]any{
"message": "Can not find the content history",
diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go
index 1574c90c02..67a71a64cb 100644
--- a/routers/web/repo/projects.go
+++ b/routers/web/repo/projects.go
@@ -467,7 +467,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
return
}
- project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
+ project, err := project_model.GetProjectForRepoByID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", nil)
diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go
index 8dc78079e2..44622c5eb3 100644
--- a/routers/web/repo/release.go
+++ b/routers/web/repo/release.go
@@ -592,7 +592,31 @@ func DeleteTag(ctx *context.Context) {
}
func deleteReleaseOrTag(ctx *context.Context, isDelTag bool) {
- if err := releaseservice.DeleteReleaseByID(ctx, ctx.FormInt64("id"), ctx.Doer, isDelTag); err != nil {
+ redirect := func() {
+ if isDelTag {
+ ctx.JSON(http.StatusOK, map[string]any{
+ "redirect": ctx.Repo.RepoLink + "/tags",
+ })
+ return
+ }
+
+ ctx.JSON(http.StatusOK, map[string]any{
+ "redirect": ctx.Repo.RepoLink + "/releases",
+ })
+ }
+
+ rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, ctx.FormInt64("id"))
+ if err != nil {
+ if repo_model.IsErrReleaseNotExist(err) {
+ ctx.NotFound("GetReleaseForRepoByID", err)
+ } else {
+ ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
+ redirect()
+ }
+ return
+ }
+
+ if err := releaseservice.DeleteReleaseByID(ctx, ctx.Repo.Repository, rel, ctx.Doer, isDelTag); err != nil {
if models.IsErrProtectedTagName(err) {
ctx.Flash.Error(ctx.Tr("repo.release.tag_name_protected"))
} else {
@@ -606,14 +630,5 @@ func deleteReleaseOrTag(ctx *context.Context, isDelTag bool) {
}
}
- if isDelTag {
- ctx.JSON(http.StatusOK, map[string]any{
- "redirect": ctx.Repo.RepoLink + "/tags",
- })
- return
- }
-
- ctx.JSON(http.StatusOK, map[string]any{
- "redirect": ctx.Repo.RepoLink + "/releases",
- })
+ redirect()
}