Skip to content

Commit 59899cf

Browse files
committed
Merge remote-tracking branch 'main/release/v1.16' into codeberg-1.16
2 parents 1bc0fe7 + bab7d88 commit 59899cf

40 files changed

+466
-178
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@ 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.5](https://github.com/go-gitea/gitea/releases/tag/1.16.5) - 2022-03-23
8+
9+
* BREAKING
10+
* Bump to build with go1.18 (#19120 et al) (#19127)
11+
* SECURITY
12+
* Prevent redirect to Host (2) (#19175) (#19186)
13+
* Try to prevent autolinking of displaynames by email readers (#19169) (#19183)
14+
* Clean paths when looking in Storage (#19124) (#19179)
15+
* Do not send notification emails to inactive users (#19131) (#19139)
16+
* Do not send activation email if manual confirm is set (#19119) (#19122)
17+
* ENHANCEMENTS
18+
* Use the new/choose link for New Issue on project page (#19172) (#19176)
19+
* BUGFIXES
20+
* Fix showing issues in your repositories (#18916) (#19191)
21+
* Fix compare link in active feeds for new branch (#19149) (#19185)
22+
* Redirect .wiki/* ui link to /wiki (#18831) (#19184)
23+
* Ensure deploy keys with write access can push (#19010) (#19182)
24+
* Ensure that setting.LocalURL always has a trailing slash (#19171) (#19177)
25+
* Cleanup protected branches when deleting users & teams (#19158) (#19174)
26+
* Use IterateBufferSize whilst querying repositories during adoption check (#19140) (#19160)
27+
* Fix NPE /repos/issues/search when not signed in (#19154) (#19155)
28+
* Use custom favicon when viewing static files if it exists (#19130) (#19152)
29+
* Fix the editor height in review box (#19003) (#19147)
30+
* Ensure isSSH is set whenever DISABLE_HTTP_GIT is set (#19028) (#19146)
31+
* Fix wrong scopes caused by empty scope input (#19029) (#19145)
32+
* Make migrations SKIP_TLS_VERIFY apply to git too (#19132) (#19141)
33+
* Handle email address not exist (#19089) (#19121)
34+
* MISC
35+
* Update json-iterator to allow compilation with go1.18 (#18644) (#19100)
36+
* Update golang.org/x/crypto (#19097) (#19098)
37+
738
## [1.16.4](https://github.com/go-gitea/gitea/releases/tag/v1.16.4) - 2022-03-14
839

940
* SECURITY

cmd/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Gitea or set your environment appropriately.`, "")
185185
reponame := os.Getenv(models.EnvRepoName)
186186
userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
187187
prID, _ := strconv.ParseInt(os.Getenv(models.EnvPRID), 10, 64)
188-
isDeployKey, _ := strconv.ParseBool(os.Getenv(models.EnvIsDeployKey))
188+
deployKeyID, _ := strconv.ParseInt(os.Getenv(models.EnvDeployKeyID), 10, 64)
189189

190190
hookOptions := private.HookOptions{
191191
UserID: userID,
@@ -194,7 +194,7 @@ Gitea or set your environment appropriately.`, "")
194194
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
195195
GitPushOptions: pushOptions(),
196196
PullRequestID: prID,
197-
IsDeployKey: isDeployKey,
197+
DeployKeyID: deployKeyID,
198198
}
199199

200200
scanner := bufio.NewScanner(os.Stdin)

cmd/serv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func runServ(c *cli.Context) error {
243243
os.Setenv(models.EnvPusherID, strconv.FormatInt(results.UserID, 10))
244244
os.Setenv(models.EnvRepoID, strconv.FormatInt(results.RepoID, 10))
245245
os.Setenv(models.EnvPRID, fmt.Sprintf("%d", 0))
246-
os.Setenv(models.EnvIsDeployKey, fmt.Sprintf("%t", results.IsDeployKey))
246+
os.Setenv(models.EnvDeployKeyID, fmt.Sprintf("%d", results.DeployKeyID))
247247
os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
248248
os.Setenv(models.EnvAppURL, setting.AppURL)
249249

integrations/api_private_serv_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestAPIPrivateServ(t *testing.T) {
4747
results, err := private.ServCommand(ctx, 1, "user2", "repo1", perm.AccessModeWrite, "git-upload-pack", "")
4848
assert.NoError(t, err)
4949
assert.False(t, results.IsWiki)
50-
assert.False(t, results.IsDeployKey)
50+
assert.Zero(t, results.DeployKeyID)
5151
assert.Equal(t, int64(1), results.KeyID)
5252
assert.Equal(t, "user2@localhost", results.KeyName)
5353
assert.Equal(t, "user2", results.UserName)
@@ -70,7 +70,7 @@ func TestAPIPrivateServ(t *testing.T) {
7070
results, err = private.ServCommand(ctx, 1, "user15", "big_test_public_1", perm.AccessModeRead, "git-upload-pack", "")
7171
assert.NoError(t, err)
7272
assert.False(t, results.IsWiki)
73-
assert.False(t, results.IsDeployKey)
73+
assert.Zero(t, results.DeployKeyID)
7474
assert.Equal(t, int64(1), results.KeyID)
7575
assert.Equal(t, "user2@localhost", results.KeyName)
7676
assert.Equal(t, "user2", results.UserName)
@@ -92,7 +92,7 @@ func TestAPIPrivateServ(t *testing.T) {
9292
results, err = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_1", perm.AccessModeRead, "git-upload-pack", "")
9393
assert.NoError(t, err)
9494
assert.False(t, results.IsWiki)
95-
assert.True(t, results.IsDeployKey)
95+
assert.NotZero(t, results.DeployKeyID)
9696
assert.Equal(t, deployKey.KeyID, results.KeyID)
9797
assert.Equal(t, "test-deploy", results.KeyName)
9898
assert.Equal(t, "user15", results.UserName)
@@ -129,7 +129,7 @@ func TestAPIPrivateServ(t *testing.T) {
129129
results, err = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_2", perm.AccessModeRead, "git-upload-pack", "")
130130
assert.NoError(t, err)
131131
assert.False(t, results.IsWiki)
132-
assert.True(t, results.IsDeployKey)
132+
assert.NotZero(t, results.DeployKeyID)
133133
assert.Equal(t, deployKey.KeyID, results.KeyID)
134134
assert.Equal(t, "test-deploy", results.KeyName)
135135
assert.Equal(t, "user15", results.UserName)
@@ -142,7 +142,7 @@ func TestAPIPrivateServ(t *testing.T) {
142142
results, err = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_2", perm.AccessModeWrite, "git-upload-pack", "")
143143
assert.NoError(t, err)
144144
assert.False(t, results.IsWiki)
145-
assert.True(t, results.IsDeployKey)
145+
assert.NotZero(t, results.DeployKeyID)
146146
assert.Equal(t, deployKey.KeyID, results.KeyID)
147147
assert.Equal(t, "test-deploy", results.KeyName)
148148
assert.Equal(t, "user15", results.UserName)

models/asymkey/ssh_key_deploy.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (key *DeployKey) GetContent() error {
5858
return nil
5959
}
6060

61-
// IsReadOnly checks if the key can only be used for read operations
61+
// IsReadOnly checks if the key can only be used for read operations, used by template
6262
func (key *DeployKey) IsReadOnly() bool {
6363
return key.Mode == perm.AccessModeRead
6464
}
@@ -203,12 +203,6 @@ func UpdateDeployKeyCols(key *DeployKey, cols ...string) error {
203203
return err
204204
}
205205

206-
// UpdateDeployKey updates deploy key information.
207-
func UpdateDeployKey(key *DeployKey) error {
208-
_, err := db.GetEngine(db.DefaultContext).ID(key.ID).AllCols().Update(key)
209-
return err
210-
}
211-
212206
// ListDeployKeysOptions are options for ListDeployKeys
213207
type ListDeployKeysOptions struct {
214208
db.ListOptions

models/helper_environment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const (
2323
EnvPusherName = "GITEA_PUSHER_NAME"
2424
EnvPusherEmail = "GITEA_PUSHER_EMAIL"
2525
EnvPusherID = "GITEA_PUSHER_ID"
26-
EnvKeyID = "GITEA_KEY_ID"
27-
EnvIsDeployKey = "GITEA_IS_DEPLOY_KEY"
26+
EnvKeyID = "GITEA_KEY_ID" // public key ID
27+
EnvDeployKeyID = "GITEA_DEPLOY_KEY_ID"
2828
EnvPRID = "GITEA_PR_ID"
2929
EnvIsInternal = "GITEA_INTERNAL_PUSH"
3030
EnvAppURL = "GITEA_ROOT_URL"

models/issue.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ const (
15601560
FilterModeCreate
15611561
FilterModeMention
15621562
FilterModeReviewRequested
1563+
FilterModeYourRepositories
15631564
)
15641565

15651566
func parseCountResult(results []map[string][]byte) int64 {
@@ -1704,6 +1705,7 @@ type UserIssueStatsOptions struct {
17041705
IssueIDs []int64
17051706
IsArchived util.OptionalBool
17061707
LabelIDs []int64
1708+
RepoCond builder.Cond
17071709
Org *Organization
17081710
Team *Team
17091711
}
@@ -1721,6 +1723,9 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
17211723
if len(opts.IssueIDs) > 0 {
17221724
cond = cond.And(builder.In("issue.id", opts.IssueIDs))
17231725
}
1726+
if opts.RepoCond != nil {
1727+
cond = cond.And(opts.RepoCond)
1728+
}
17241729

17251730
if opts.UserID > 0 {
17261731
cond = cond.And(issuePullAccessibleRepoCond("issue.repo_id", opts.UserID, opts.Org, opts.Team, opts.IsPull))
@@ -1742,7 +1747,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
17421747
}
17431748

17441749
switch opts.FilterMode {
1745-
case FilterModeAll:
1750+
case FilterModeAll, FilterModeYourRepositories:
17461751
stats.OpenCount, err = sess(cond).
17471752
And("issue.is_closed = ?", false).
17481753
Count(new(Issue))

models/org_team.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
user_model "code.gitea.io/gitea/models/user"
2020
"code.gitea.io/gitea/modules/log"
2121
"code.gitea.io/gitea/modules/setting"
22+
"code.gitea.io/gitea/modules/util"
2223

2324
"xorm.io/builder"
2425
)
@@ -776,8 +777,45 @@ func DeleteTeam(t *Team) error {
776777
return err
777778
}
778779

779-
if err := t.removeAllRepositories(ctx); err != nil {
780-
return err
780+
// update branch protections
781+
{
782+
protections := make([]*ProtectedBranch, 0, 10)
783+
err := sess.In("repo_id",
784+
builder.Select("id").From("repository").Where(builder.Eq{"owner_id": t.OrgID})).
785+
Find(&protections)
786+
if err != nil {
787+
return fmt.Errorf("findProtectedBranches: %v", err)
788+
}
789+
for _, p := range protections {
790+
var matched1, matched2, matched3 bool
791+
if len(p.WhitelistTeamIDs) != 0 {
792+
p.WhitelistTeamIDs, matched1 = util.RemoveIDFromList(
793+
p.WhitelistTeamIDs, t.ID)
794+
}
795+
if len(p.ApprovalsWhitelistTeamIDs) != 0 {
796+
p.ApprovalsWhitelistTeamIDs, matched2 = util.RemoveIDFromList(
797+
p.ApprovalsWhitelistTeamIDs, t.ID)
798+
}
799+
if len(p.MergeWhitelistTeamIDs) != 0 {
800+
p.MergeWhitelistTeamIDs, matched3 = util.RemoveIDFromList(
801+
p.MergeWhitelistTeamIDs, t.ID)
802+
}
803+
if matched1 || matched2 || matched3 {
804+
if _, err = sess.ID(p.ID).Cols(
805+
"whitelist_team_i_ds",
806+
"merge_whitelist_team_i_ds",
807+
"approvals_whitelist_team_i_ds",
808+
).Update(p); err != nil {
809+
return fmt.Errorf("updateProtectedBranches: %v", err)
810+
}
811+
}
812+
}
813+
}
814+
815+
if !t.IncludesAllRepositories {
816+
if err := t.removeAllRepositories(ctx); err != nil {
817+
return err
818+
}
781819
}
782820

783821
// Delete team-user.

models/user.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
user_model "code.gitea.io/gitea/models/user"
1919
"code.gitea.io/gitea/modules/setting"
2020
"code.gitea.io/gitea/modules/structs"
21+
"code.gitea.io/gitea/modules/util"
2122

2223
"xorm.io/builder"
2324
)
@@ -130,6 +131,50 @@ func DeleteUser(ctx context.Context, u *user_model.User) (err error) {
130131
}
131132
}
132133

134+
// ***** START: Branch Protections *****
135+
{
136+
const batchSize = 50
137+
for start := 0; ; start += batchSize {
138+
protections := make([]*ProtectedBranch, 0, batchSize)
139+
// @perf: We can't filter on DB side by u.ID, as those IDs are serialized as JSON strings.
140+
// We could filter down with `WHERE repo_id IN (reposWithPushPermission(u))`,
141+
// though that query will be quite complex and tricky to maintain (compare `getRepoAssignees()`).
142+
// Also, as we didn't update branch protections when removing entries from `access` table,
143+
// it's safer to iterate all protected branches.
144+
if err = e.Limit(batchSize, start).Find(&protections); err != nil {
145+
return fmt.Errorf("findProtectedBranches: %v", err)
146+
}
147+
if len(protections) == 0 {
148+
break
149+
}
150+
for _, p := range protections {
151+
var matched1, matched2, matched3 bool
152+
if len(p.WhitelistUserIDs) != 0 {
153+
p.WhitelistUserIDs, matched1 = util.RemoveIDFromList(
154+
p.WhitelistUserIDs, u.ID)
155+
}
156+
if len(p.ApprovalsWhitelistUserIDs) != 0 {
157+
p.ApprovalsWhitelistUserIDs, matched2 = util.RemoveIDFromList(
158+
p.ApprovalsWhitelistUserIDs, u.ID)
159+
}
160+
if len(p.MergeWhitelistUserIDs) != 0 {
161+
p.MergeWhitelistUserIDs, matched3 = util.RemoveIDFromList(
162+
p.MergeWhitelistUserIDs, u.ID)
163+
}
164+
if matched1 || matched2 || matched3 {
165+
if _, err = e.ID(p.ID).Cols(
166+
"whitelist_user_i_ds",
167+
"merge_whitelist_user_i_ds",
168+
"approvals_whitelist_user_i_ds",
169+
).Update(p); err != nil {
170+
return fmt.Errorf("updateProtectedBranches: %v", err)
171+
}
172+
}
173+
}
174+
}
175+
}
176+
// ***** END: Branch Protections *****
177+
133178
// ***** START: PublicKey *****
134179
if _, err = e.Delete(&asymkey_model.PublicKey{OwnerID: u.ID}); err != nil {
135180
return fmt.Errorf("deletePublicKeys: %v", err)

modules/context/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ func (ctx *Context) RedirectToFirst(location ...string) {
181181
continue
182182
}
183183

184+
// Unfortunately browsers consider a redirect Location with preceding "//" and "/\" as meaning redirect to "http(s)://REST_OF_PATH"
185+
// Therefore we should ignore these redirect locations to prevent open redirects
186+
if len(loc) > 1 && loc[0] == '/' && (loc[1] == '/' || loc[1] == '\\') {
187+
continue
188+
}
189+
184190
u, err := url.Parse(loc)
185191
if err != nil || ((u.Scheme != "" || u.Host != "") && !strings.HasPrefix(strings.ToLower(loc), strings.ToLower(setting.AppURL))) {
186192
continue

0 commit comments

Comments
 (0)