Skip to content

Commit 2f8e79c

Browse files
committed
Squashed commit of the following:
commit 713bc6c Author: 6543 <6543@obermui.de> Date: Tue Jul 12 20:26:27 2022 +0200 Changelog for 1.16.9 (update) (go-gitea#20341) * Changelog for 1.16.9 (update) * update security section commit 6b7e860 Author: Lunny Xiao <xiaolunwen@gmail.com> Date: Wed Jul 13 01:13:31 2022 +0800 Hide notify mail setting ui if not enabled (go-gitea#20138) (go-gitea#20337) Backport go-gitea#20138 commit 0f89417 Author: Gusted <williamzijl7@hotmail.com> Date: Tue Jul 12 12:52:20 2022 +0000 Add write check for creating Commit status (go-gitea#20332) (go-gitea#20334) - Backport go-gitea#20332 - Add write code checks for creating new commit status - Regression from go-gitea#5314 - Resolves go-gitea#20331 commit 7c80a0b Author: zeripath <art27@cantab.net> Date: Mon Jul 11 10:15:43 2022 +0100 Ensure that drone tags 1.16.x and 1.16 on push to v1.16.x tag (go-gitea#20304) We need pushes to v1.16.9 to create tags to 1.16.9 and 1.16 but not 1 or latest. We have previously adjusted the manifest to remove the latest tag, and have removed auto_tags so that 1 does not get tagged but in doing so we also stopped 1.16 being tagged. So here we just state the that we tag x.yy in addition to x.yyz*. Signed-off-by: Andrew Thornton <art27@cantab.net> commit b42df31 Author: zeripath <art27@cantab.net> Date: Wed Jul 6 02:47:16 2022 +0100 Only show Followers that current user can access (go-gitea#20220) (go-gitea#20253) Backport go-gitea#20220 Users who are following or being followed by a user should only be displayed if the viewing user can see them. Signed-off-by: Andrew Thornton <art27@cantab.net> commit 6162fb0 Author: Gusted <williamzijl7@hotmail.com> Date: Fri Jul 1 17:39:10 2022 +0200 Check for permission when fetching user controlled issues (go-gitea#20133) (go-gitea#20196) * Check if project has the same repository id with issue when assign project to issue * Check if issue's repository id match project's repository id * Add more permission checking * Remove invalid argument * Fix errors * Add generic check * Remove duplicated check * Return error + add check for new issues * Apply suggestions from code review Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: 6543 <6543@obermui.de>
1 parent 0ebe61d commit 2f8e79c

File tree

14 files changed

+155
-49
lines changed

14 files changed

+155
-49
lines changed

.drone.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ steps:
904904
settings:
905905
auto_tag: false
906906
auto_tag_suffix: linux-amd64
907+
tags:
908+
- ${DRONE_TAG##v}-linux-amd64
909+
- ${DRONE_TAG:1:4}-linux-amd64
907910
repo: gitea/gitea
908911
build_args:
909912
- GOPROXY=https://goproxy.io
@@ -922,6 +925,9 @@ steps:
922925
dockerfile: Dockerfile.rootless
923926
auto_tag: false
924927
auto_tag_suffix: linux-amd64-rootless
928+
tags:
929+
- ${DRONE_TAG##v}-linux-amd64-rootless
930+
- ${DRONE_TAG:1:4}-linux-amd64-rootless
925931
repo: gitea/gitea
926932
build_args:
927933
- GOPROXY=https://goproxy.io
@@ -1128,6 +1134,9 @@ steps:
11281134
settings:
11291135
auto_tag: false
11301136
auto_tag_suffix: linux-arm64
1137+
tags:
1138+
- ${DRONE_TAG##v}-linux-arm64
1139+
- ${DRONE_TAG:1:4}-linux-arm64
11311140
repo: gitea/gitea
11321141
build_args:
11331142
- GOPROXY=https://goproxy.io
@@ -1146,6 +1155,9 @@ steps:
11461155
dockerfile: Dockerfile.rootless
11471156
auto_tag: false
11481157
auto_tag_suffix: linux-arm64-rootless
1158+
tags:
1159+
- ${DRONE_TAG##v}-linux-arm64-rootless
1160+
- ${DRONE_TAG:1:4}-linux-arm64-rootless
11491161
repo: gitea/gitea
11501162
build_args:
11511163
- GOPROXY=https://goproxy.io

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ This changelog goes through all the changes that have been made in each release
44
without substantial changes to our git log; to see the highlights of what has
55
been added to each release, please refer to the [blog](https://blog.gitea.io).
66

7-
## [1.16.9](https://github.com/go-gitea/gitea/releases/tag/v1.16.9) - 2022-06-21
7+
## [1.16.9](https://github.com/go-gitea/gitea/releases/tag/v1.16.9) - 2022-07-12
88

9+
* SECURITY
10+
* Add write check for creating Commit status (#20332) (#20334)
11+
* Check for permission when fetching user controlled issues (#20133) (#20196)
912
* BUGFIXES
13+
* Hide notify mail setting ui if not enabled (#20138) (#20337)
14+
* Add write check for creating Commit status (#20332) (#20334)
15+
* Only show Followers that current user can access (#20220) (#20253)
1016
* Release page show all tags in compare dropdown (#20070) (#20071)
1117
* Fix permission check for delete tag (#19985) (#20001)
1218
* Only log non ErrNotExist errors in git.GetNote (#19884) (#19905)

models/issue_milestone.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ func getMilestoneByRepoID(e db.Engine, repoID, id int64) (*Milestone, error) {
116116
return m, nil
117117
}
118118

119+
// HasMilestoneByRepoID returns if the milestone exists in the repository.
120+
func HasMilestoneByRepoID(repoID, id int64) (bool, error) {
121+
return db.GetEngine(db.DefaultContext).ID(id).Where("repo_id=?", repoID).Exist(new(Milestone))
122+
}
123+
119124
// GetMilestoneByRepoID returns the milestone in a repository.
120125
func GetMilestoneByRepoID(repoID, id int64) (*Milestone, error) {
121126
return getMilestoneByRepoID(db.GetEngine(db.DefaultContext), repoID, id)
@@ -251,6 +256,17 @@ func changeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) err
251256
}
252257

253258
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *Issue, oldMilestoneID int64) error {
259+
// Only check if milestone exists if we don't remove it.
260+
if issue.MilestoneID > 0 {
261+
has, err := HasMilestoneByRepoID(issue.RepoID, issue.MilestoneID)
262+
if err != nil {
263+
return fmt.Errorf("HasMilestoneByRepoID: %v", err)
264+
}
265+
if !has {
266+
return fmt.Errorf("HasMilestoneByRepoID: issue doesn't exist")
267+
}
268+
}
269+
254270
if err := updateIssueCols(ctx, issue, "milestone_id"); err != nil {
255271
return err
256272
}

models/user/user.go

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,37 +318,45 @@ func (u *User) GenerateEmailActivateCode(email string) string {
318318
}
319319

320320
// GetUserFollowers returns range of user's followers.
321-
func GetUserFollowers(u *User, listOptions db.ListOptions) ([]*User, error) {
322-
sess := db.GetEngine(db.DefaultContext).
321+
func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error) {
322+
sess := db.GetEngine(ctx).
323+
Select("`user`.*").
324+
Join("LEFT", "follow", "`user`.id=follow.user_id").
323325
Where("follow.follow_id=?", u.ID).
324-
Join("LEFT", "follow", "`user`.id=follow.user_id")
326+
And(isUserVisibleToViewerCond(viewer))
325327

326328
if listOptions.Page != 0 {
327329
sess = db.SetSessionPagination(sess, &listOptions)
328330

329331
users := make([]*User, 0, listOptions.PageSize)
330-
return users, sess.Find(&users)
332+
count, err := sess.FindAndCount(&users)
333+
return users, count, err
331334
}
332335

333336
users := make([]*User, 0, 8)
334-
return users, sess.Find(&users)
337+
count, err := sess.FindAndCount(&users)
338+
return users, count, err
335339
}
336340

337341
// GetUserFollowing returns range of user's following.
338-
func GetUserFollowing(u *User, listOptions db.ListOptions) ([]*User, error) {
342+
func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error) {
339343
sess := db.GetEngine(db.DefaultContext).
344+
Select("`user`.*").
345+
Join("LEFT", "follow", "`user`.id=follow.follow_id").
340346
Where("follow.user_id=?", u.ID).
341-
Join("LEFT", "follow", "`user`.id=follow.follow_id")
347+
And(isUserVisibleToViewerCond(viewer))
342348

343349
if listOptions.Page != 0 {
344350
sess = db.SetSessionPagination(sess, &listOptions)
345351

346352
users := make([]*User, 0, listOptions.PageSize)
347-
return users, sess.Find(&users)
353+
count, err := sess.FindAndCount(&users)
354+
return users, count, err
348355
}
349356

350357
users := make([]*User, 0, 8)
351-
return users, sess.Find(&users)
358+
count, err := sess.FindAndCount(&users)
359+
return users, count, err
352360
}
353361

354362
// NewGitSig generates and returns the signature of given user.
@@ -1233,3 +1241,36 @@ func GetAdminUser() (*User, error) {
12331241

12341242
return &admin, nil
12351243
}
1244+
1245+
func isUserVisibleToViewerCond(viewer *User) builder.Cond {
1246+
if viewer != nil && viewer.IsAdmin {
1247+
return builder.NewCond()
1248+
}
1249+
1250+
if viewer == nil || viewer.IsRestricted {
1251+
return builder.Eq{
1252+
"`user`.visibility": structs.VisibleTypePublic,
1253+
}
1254+
}
1255+
1256+
return builder.Neq{
1257+
"`user`.visibility": structs.VisibleTypePrivate,
1258+
}.Or(
1259+
builder.In("`user`.id",
1260+
builder.
1261+
Select("`follow`.user_id").
1262+
From("follow").
1263+
Where(builder.Eq{"`follow`.follow_id": viewer.ID})),
1264+
builder.In("`user`.id",
1265+
builder.
1266+
Select("`team_user`.uid").
1267+
From("team_user").
1268+
Join("INNER", "`team_user` AS t2", "`team_user`.id = `t2`.id").
1269+
Where(builder.Eq{"`t2`.uid": viewer.ID})),
1270+
builder.In("`user`.id",
1271+
builder.
1272+
Select("`team_user`.uid").
1273+
From("team_user").
1274+
Join("INNER", "`team_user` AS t2", "`team_user`.org_id = `t2`.org_id").
1275+
Where(builder.Eq{"`t2`.uid": viewer.ID})))
1276+
}

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
954954
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(false))
955955
m.Group("/statuses", func() {
956956
m.Combo("/{sha}").Get(repo.GetCommitStatuses).
957-
Post(reqToken(), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
957+
Post(reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
958958
}, reqRepoReader(unit.TypeCode))
959959
m.Group("/commits", func() {
960960
m.Get("", repo.GetAllCommits)

routers/api/v1/repo/pull_review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
883883
return
884884
}
885885

886-
_, err := pull_service.DismissReview(review.ID, msg, ctx.User, isDismiss)
886+
_, err := pull_service.DismissReview(review.ID, ctx.Repo.Repository.ID, msg, ctx.User, isDismiss)
887887
if err != nil {
888888
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
889889
return

routers/api/v1/user/follower.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) {
2424
}
2525

2626
func listUserFollowers(ctx *context.APIContext, u *user_model.User) {
27-
users, err := user_model.GetUserFollowers(u, utils.GetListOptions(ctx))
27+
users, count, err := user_model.GetUserFollowers(ctx, u, ctx.User, utils.GetListOptions(ctx))
2828
if err != nil {
2929
ctx.Error(http.StatusInternalServerError, "GetUserFollowers", err)
3030
return
3131
}
3232

33-
ctx.SetTotalCountHeader(int64(u.NumFollowers))
33+
ctx.SetTotalCountHeader(count)
3434
responseAPIUsers(ctx, users)
3535
}
3636

@@ -90,13 +90,13 @@ func ListFollowers(ctx *context.APIContext) {
9090
}
9191

9292
func listUserFollowing(ctx *context.APIContext, u *user_model.User) {
93-
users, err := user_model.GetUserFollowing(u, utils.GetListOptions(ctx))
93+
users, count, err := user_model.GetUserFollowing(ctx, u, ctx.User, utils.GetListOptions(ctx))
9494
if err != nil {
9595
ctx.Error(http.StatusInternalServerError, "GetUserFollowing", err)
9696
return
9797
}
9898

99-
ctx.SetTotalCountHeader(int64(u.NumFollowing))
99+
ctx.SetTotalCountHeader(count)
100100
responseAPIUsers(ctx, users)
101101
}
102102

routers/web/repo/issue.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,15 @@ const (
5757
issueTemplateTitleKey = "IssueTemplateTitle"
5858
)
5959

60-
var (
61-
// IssueTemplateCandidates issue templates
62-
IssueTemplateCandidates = []string{
63-
"ISSUE_TEMPLATE.md",
64-
"issue_template.md",
65-
".gitea/ISSUE_TEMPLATE.md",
66-
".gitea/issue_template.md",
67-
".github/ISSUE_TEMPLATE.md",
68-
".github/issue_template.md",
69-
}
70-
)
60+
// IssueTemplateCandidates issue templates
61+
var IssueTemplateCandidates = []string{
62+
"ISSUE_TEMPLATE.md",
63+
"issue_template.md",
64+
".gitea/ISSUE_TEMPLATE.md",
65+
".gitea/issue_template.md",
66+
".github/ISSUE_TEMPLATE.md",
67+
".github/issue_template.md",
68+
}
7169

7270
// MustAllowUserComment checks to make sure if an issue is locked.
7371
// If locked and user has permissions to write to the repository,
@@ -253,7 +251,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
253251
}
254252
}
255253

256-
var issueList = models.IssueList(issues)
254+
issueList := models.IssueList(issues)
257255
approvalCounts, err := issueList.GetApprovalCounts()
258256
if err != nil {
259257
ctx.ServerError("ApprovalCounts", err)
@@ -319,8 +317,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
319317
assigneeID = 0 // Reset ID to prevent unexpected selection of assignee.
320318
}
321319

322-
ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] =
323-
issue_service.GetRefEndNamesAndURLs(issues, ctx.Repo.RepoLink)
320+
ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] = issue_service.GetRefEndNamesAndURLs(issues, ctx.Repo.RepoLink)
324321

325322
ctx.Data["ApprovalCounts"] = func(issueID int64, typ string) int64 {
326323
counts, ok := approvalCounts[issueID]
@@ -452,7 +449,6 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
452449
}
453450

454451
func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
455-
456452
var err error
457453

458454
ctx.Data["OpenProjects"], _, err = models.GetProjects(models.ProjectSearchOptions{
@@ -806,7 +802,8 @@ func NewIssue(ctx *context.Context) {
806802
body := ctx.FormString("body")
807803
ctx.Data["BodyQuery"] = body
808804

809-
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects)
805+
isProjectsEnabled := ctx.Repo.CanRead(unit.TypeProjects)
806+
ctx.Data["IsProjectsEnabled"] = isProjectsEnabled
810807
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
811808
upload.AddUploadContext(ctx, "comment")
812809

@@ -822,7 +819,7 @@ func NewIssue(ctx *context.Context) {
822819
}
823820

824821
projectID := ctx.FormInt64("project")
825-
if projectID > 0 {
822+
if projectID > 0 && isProjectsEnabled {
826823
project, err := models.GetProjectByID(projectID)
827824
if err != nil {
828825
log.Error("GetProjectByID: %d: %v", projectID, err)
@@ -1027,6 +1024,12 @@ func NewIssuePost(ctx *context.Context) {
10271024
}
10281025

10291026
if projectID > 0 {
1027+
if !ctx.Repo.CanRead(unit.TypeProjects) {
1028+
// User must also be able to see the project.
1029+
ctx.Error(http.StatusBadRequest, "user hasn't permissions to read projects")
1030+
return
1031+
}
1032+
10301033
if err := models.ChangeProjectAssign(issue, ctx.User, projectID, ctx.FormString("action")); err != nil {
10311034
ctx.ServerError("ChangeProjectAssign", err)
10321035
return
@@ -1723,6 +1726,11 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
17231726
issueUnitEnabled := ctx.Repo.CanRead(unit.TypeIssues)
17241727
prUnitEnabled := ctx.Repo.CanRead(unit.TypePullRequests)
17251728
for _, issue := range issues {
1729+
if issue.RepoID != ctx.Repo.Repository.ID {
1730+
ctx.NotFound("some issue's RepoID is incorrect", errors.New("some issue's RepoID is incorrect"))
1731+
return nil
1732+
}
1733+
17261734
if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled {
17271735
ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
17281736
return nil
@@ -2525,7 +2533,7 @@ func filterXRefComments(ctx *context.Context, issue *models.Issue) error {
25252533
// GetIssueAttachments returns attachments for the issue
25262534
func GetIssueAttachments(ctx *context.Context) {
25272535
issue := GetActionIssue(ctx)
2528-
var attachments = make([]*api.Attachment, len(issue.Attachments))
2536+
attachments := make([]*api.Attachment, len(issue.Attachments))
25292537
for i := 0; i < len(issue.Attachments); i++ {
25302538
attachments[i] = convert.ToReleaseAttachment(issue.Attachments[i])
25312539
}
@@ -2539,7 +2547,7 @@ func GetCommentAttachments(ctx *context.Context) {
25392547
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
25402548
return
25412549
}
2542-
var attachments = make([]*api.Attachment, 0)
2550+
attachments := make([]*api.Attachment, 0)
25432551
if comment.Type == models.CommentTypeComment {
25442552
if err := comment.LoadAttachments(); err != nil {
25452553
ctx.ServerError("LoadAttachments", err)
@@ -2684,7 +2692,7 @@ func handleTeamMentions(ctx *context.Context) {
26842692
var isAdmin bool
26852693
var err error
26862694
var teams []*models.Team
2687-
var org = models.OrgFromUser(ctx.Repo.Owner)
2695+
org := models.OrgFromUser(ctx.Repo.Owner)
26882696
// Admin has super access.
26892697
if ctx.User.IsAdmin {
26902698
isAdmin = true

routers/web/repo/projects.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package repo
66

77
import (
8+
"errors"
89
"fmt"
910
"net/http"
1011
"net/url"
@@ -532,7 +533,6 @@ func EditProjectBoard(ctx *context.Context) {
532533

533534
// SetDefaultProjectBoard set default board for uncategorized issues/pulls
534535
func SetDefaultProjectBoard(ctx *context.Context) {
535-
536536
project, board := checkProjectBoardChangePermissions(ctx)
537537
if ctx.Written() {
538538
return
@@ -632,10 +632,17 @@ func MoveIssues(ctx *context.Context) {
632632
}
633633

634634
if len(movedIssues) != len(form.Issues) {
635-
ctx.ServerError("IssuesNotFound", err)
635+
ctx.ServerError("some issues do not exist", errors.New("some issues do not exist"))
636636
return
637637
}
638638

639+
for _, issue := range movedIssues {
640+
if issue.RepoID != project.RepoID {
641+
ctx.ServerError("Some issue's repoID is not equal to project's repoID", errors.New("Some issue's repoID is not equal to project's repoID"))
642+
return
643+
}
644+
}
645+
639646
if err = models.MoveIssuesOnProjectBoard(board, sortedIssueIDs, project.ID); err != nil {
640647
ctx.ServerError("MoveIssuesOnProjectBoard", err)
641648
return

0 commit comments

Comments
 (0)