Skip to content

Commit e483a40

Browse files
authored
Merge branch 'main' into restore-squash-merge-default-comment
2 parents 6f8f839 + 889dea8 commit e483a40

File tree

24 files changed

+572
-118
lines changed

24 files changed

+572
-118
lines changed

CHANGELOG.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,56 @@ 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.14.3](https://github.com/go-gitea/gitea/releases/tag/v1.14.3) - 2021-06-18
8+
9+
* SECURITY
10+
* Encrypt migration credentials at rest (#15895) (#16187)
11+
* Only check access tokens if they are likely to be tokens (#16164) (#16171)
12+
* Add missing SameSite settings for the i_like_gitea cookie (#16037) (#16039)
13+
* Fix setting of SameSite on cookies (#15989) (#15991)
14+
* API
15+
* Repository object only count releases as releases (#16184) (#16190)
16+
* EditOrg respect RepoAdminChangeTeamAccess option (#16184) (#16190)
17+
* Fix overly strict edit pr permissions (#15900) (#16081)
18+
* BUGFIXES
19+
* Run processors on whole of text (#16155) (#16185)
20+
* Class `issue-keyword` is being incorrectly stripped off spans (#16163) (#16172)
21+
* Fix language switch for install page (#16043) (#16128)
22+
* Fix bug on getIssueIDsByRepoID (#16119) (#16124)
23+
* Set self-adjusting deadline for connection writing (#16068) (#16123)
24+
* Fix http path bug (#16117) (#16120)
25+
* Fix data URI scramble (#16098) (#16118)
26+
* Merge all deleteBranch as one function and also fix bug when delete branch don't close related PRs (#16067) (#16097)
27+
* git migration: don't prompt interactively for clone credentials (#15902) (#16082)
28+
* Fix case change in ownernames (#16045) (#16050)
29+
* Don't manipulate input params in email notification (#16011) (#16033)
30+
* Remove branch URL before IssueRefURL (#15968) (#15970)
31+
* Fix layout of milestone view (#15927) (#15940)
32+
* GitHub Migration, migrate draft releases too (#15884) (#15888)
33+
* Close the gitrepo when deleting the repository (#15876) (#15887)
34+
* Upgrade xorm to v1.1.0 (#15869) (#15885)
35+
* Fix blame row height alignment (#15863) (#15883)
36+
* Fix error message when saving generated LOCAL_ROOT_URL config (#15880) (#15882)
37+
* Backport Fix LFS commit finder not working (#15856) (#15874)
38+
* Stop calling WriteHeader in Write (#15862) (#15873)
39+
* Add timeout to writing to responses (#15831) (#15872)
40+
* Return go-get info on subdirs (#15642) (#15871)
41+
* Restore PAM user autocreation functionality (#15825) (#15867)
42+
* Fix truncate utf8 string (#15828) (#15854)
43+
* Fix bound address/port for caddy's certmagic library (#15758) (#15848)
44+
* Upgrade unrolled/render to v1.1.1 (#15845) (#15846)
45+
* Queue manager FlushAll can loop rapidly - add delay (#15733) (#15840)
46+
* Tagger can be empty, as can Commit and Author - tolerate this (#15835) (#15839)
47+
* Set autocomplete off on branches selector (#15809) (#15833)
48+
* Add missing error to Doctor log (#15813) (#15824)
49+
* Move restore repo to internal router and invoke from command to avoid open the same db file or queues files (#15790) (#15816)
50+
* ENHANCEMENTS
51+
* Removable media support to snap package (#16136) (#16138)
52+
* Move sans-serif fallback font higher than emoji fonts (#15855) (#15892)
53+
* DOCKER
54+
* Only write config in environment-to-ini if there are changes (#15861) (#15868)
55+
* Only offer hostcertificates if they exist (#15849) (#15853)
56+
757
## [1.14.2](https://github.com/go-gitea/gitea/releases/tag/v1.14.2) - 2021-05-09
858

959
* API

cmd/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func runGenerateInternalToken(c *cli.Context) error {
7171
}
7272

7373
func runGenerateLfsJwtSecret(c *cli.Context) error {
74-
JWTSecretBase64, err := generate.NewJwtSecret()
74+
JWTSecretBase64, err := generate.NewJwtSecretBase64()
7575
if err != nil {
7676
return err
7777
}

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,9 @@ NB: You must have `DISABLE_ROUTER_LOG` set to `false` for this option to take ef
859859
- `ACCESS_TOKEN_EXPIRATION_TIME`: **3600**: Lifetime of an OAuth2 access token in seconds
860860
- `REFRESH_TOKEN_EXPIRATION_TIME`: **730**: Lifetime of an OAuth2 refresh token in hours
861861
- `INVALIDATE_REFRESH_TOKENS`: **false**: Check if refresh token has already been used
862-
- `JWT_SECRET`: **\<empty\>**: OAuth2 authentication secret for access and refresh tokens, change this a unique string.
862+
- `JWT_SIGNING_ALGORITHM`: **RS256**: Algorithm used to sign OAuth2 tokens. Valid values: \[`HS256`, `HS384`, `HS512`, `RS256`, `RS384`, `RS512`, `ES256`, `ES384`, `ES512`\]
863+
- `JWT_SECRET`: **\<empty\>**: OAuth2 authentication secret for access and refresh tokens, change this to a unique string. This setting is only needed if `JWT_SIGNING_ALGORITHM` is set to `HS256`, `HS384` or `HS512`.
864+
- `JWT_SIGNING_PRIVATE_KEY_FILE`: **jwt/private.pem**: Private key file path used to sign OAuth2 tokens. The path is relative to `CUSTOM_PATH`. This setting is only needed if `JWT_SIGNING_ALGORITHM` is set to `RS256`, `RS384`, `RS512`, `ES256`, `ES384` or `ES512`. The file must contain a RSA or ECDSA private key in the PKCS8 format.
863865
- `MAX_TOKEN_LENGTH`: **32767**: Maximum length of token/cookie to accept from OAuth2 provider
864866

865867
## i18n (`i18n`)

docs/content/doc/developers/oauth2-provider.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ Gitea supports acting as an OAuth2 provider to allow third party applications to
2323

2424
## Endpoints
2525

26-
| Endpoint | URL |
27-
| ---------------------- | --------------------------- |
28-
| Authorization Endpoint | `/login/oauth/authorize` |
29-
| Access Token Endpoint | `/login/oauth/access_token` |
26+
| Endpoint | URL |
27+
| ------------------------ | ----------------------------------- |
28+
| OpenID Connect Discovery | `/.well-known/openid-configuration` |
29+
| Authorization Endpoint | `/login/oauth/authorize` |
30+
| Access Token Endpoint | `/login/oauth/access_token` |
31+
| OpenID Connect UserInfo | `/login/oauth/userinfo` |
32+
| JSON Web Key Set | `/login/oauth/keys` |
3033

3134
## Supported OAuth2 Grants
3235

integrations/api_repo_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func TestAPIViewRepo(t *testing.T) {
223223
DecodeJSON(t, resp, &repo)
224224
assert.EqualValues(t, 1, repo.ID)
225225
assert.EqualValues(t, "repo1", repo.Name)
226-
assert.EqualValues(t, 3, repo.Releases)
226+
assert.EqualValues(t, 2, repo.Releases)
227227
assert.EqualValues(t, 1, repo.OpenIssues)
228228
assert.EqualValues(t, 3, repo.OpenPulls)
229229

@@ -466,7 +466,7 @@ func TestAPIRepoTransfer(t *testing.T) {
466466
session := loginUser(t, user.Name)
467467
token := getTokenForLoggedInUser(t, session)
468468
repoName := "moveME"
469-
repo := new(models.Repository)
469+
apiRepo := new(api.Repository)
470470
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/user/repos?token=%s", token), &api.CreateRepoOption{
471471
Name: repoName,
472472
Description: "repo move around",
@@ -475,12 +475,12 @@ func TestAPIRepoTransfer(t *testing.T) {
475475
AutoInit: true,
476476
})
477477
resp := session.MakeRequest(t, req, http.StatusCreated)
478-
DecodeJSON(t, resp, repo)
478+
DecodeJSON(t, resp, apiRepo)
479479

480480
//start testing
481481
for _, testCase := range testCases {
482482
user = models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
483-
repo = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repo.ID}).(*models.Repository)
483+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: apiRepo.ID}).(*models.Repository)
484484
session = loginUser(t, user.Name)
485485
token = getTokenForLoggedInUser(t, session)
486486
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer?token=%s", repo.OwnerName, repo.Name, token), &api.TransferRepoOption{
@@ -491,7 +491,7 @@ func TestAPIRepoTransfer(t *testing.T) {
491491
}
492492

493493
//cleanup
494-
repo = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repo.ID}).(*models.Repository)
494+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: apiRepo.ID}).(*models.Repository)
495495
_ = models.DeleteRepository(user, repo.OwnerID, repo.ID)
496496
}
497497

integrations/org_count_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
114114
Name: username,
115115
}).(*models.User)
116116

117-
user.GetOrganizations(&models.SearchOrganizationsOptions{All: true})
117+
orgs, err := models.GetOrgsByUserID(user.ID, true)
118+
assert.NoError(t, err)
118119

119120
calcOrgCounts := map[string]int{}
120121

121-
for _, org := range user.Orgs {
122+
for _, org := range orgs {
122123
calcOrgCounts[org.LowerName] = org.NumRepos
123124
count, ok := canonicalCounts[org.LowerName]
124125
if ok {

models/oauth2.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func GetActiveOAuth2Providers() ([]string, map[string]OAuth2Provider, error) {
132132

133133
// InitOAuth2 initialize the OAuth2 lib and register all active OAuth2 providers in the library
134134
func InitOAuth2() error {
135+
if err := oauth2.InitSigningKey(); err != nil {
136+
return err
137+
}
135138
if err := oauth2.Init(x); err != nil {
136139
return err
137140
}

models/oauth2_application.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"strings"
1313
"time"
1414

15+
"code.gitea.io/gitea/modules/auth/oauth2"
1516
"code.gitea.io/gitea/modules/secret"
16-
"code.gitea.io/gitea/modules/setting"
1717
"code.gitea.io/gitea/modules/timeutil"
1818
"code.gitea.io/gitea/modules/util"
1919

@@ -540,10 +540,10 @@ type OAuth2Token struct {
540540
// ParseOAuth2Token parses a singed jwt string
541541
func ParseOAuth2Token(jwtToken string) (*OAuth2Token, error) {
542542
parsedToken, err := jwt.ParseWithClaims(jwtToken, &OAuth2Token{}, func(token *jwt.Token) (interface{}, error) {
543-
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
543+
if token.Method == nil || token.Method.Alg() != oauth2.DefaultSigningKey.SigningMethod().Alg() {
544544
return nil, fmt.Errorf("unexpected signing algo: %v", token.Header["alg"])
545545
}
546-
return setting.OAuth2.JWTSecretBytes, nil
546+
return oauth2.DefaultSigningKey.VerifyKey(), nil
547547
})
548548
if err != nil {
549549
return nil, err
@@ -559,8 +559,9 @@ func ParseOAuth2Token(jwtToken string) (*OAuth2Token, error) {
559559
// SignToken signs the token with the JWT secret
560560
func (token *OAuth2Token) SignToken() (string, error) {
561561
token.IssuedAt = time.Now().Unix()
562-
jwtToken := jwt.NewWithClaims(jwt.SigningMethodHS512, token)
563-
return jwtToken.SignedString(setting.OAuth2.JWTSecretBytes)
562+
jwtToken := jwt.NewWithClaims(oauth2.DefaultSigningKey.SigningMethod(), token)
563+
oauth2.DefaultSigningKey.PreProcessToken(jwtToken)
564+
return jwtToken.SignedString(oauth2.DefaultSigningKey.SignKey())
564565
}
565566

566567
// OIDCToken represents an OpenID Connect id_token
@@ -583,8 +584,9 @@ type OIDCToken struct {
583584
}
584585

585586
// SignToken signs an id_token with the (symmetric) client secret key
586-
func (token *OIDCToken) SignToken(clientSecret string) (string, error) {
587+
func (token *OIDCToken) SignToken(signingKey oauth2.JWTSigningKey) (string, error) {
587588
token.IssuedAt = time.Now().Unix()
588-
jwtToken := jwt.NewWithClaims(jwt.SigningMethodHS256, token)
589-
return jwtToken.SignedString([]byte(clientSecret))
589+
jwtToken := jwt.NewWithClaims(signingKey.SigningMethod(), token)
590+
signingKey.PreProcessToken(jwtToken)
591+
return jwtToken.SignedString(signingKey.SignKey())
590592
}

models/user.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ type User struct {
112112
LoginName string
113113
Type UserType
114114
OwnedOrgs []*User `xorm:"-"`
115-
Orgs []*User `xorm:"-"`
116115
Repos []*Repository `xorm:"-"`
117116
Location string
118117
Website string
@@ -603,58 +602,6 @@ func (u *User) GetOwnedOrganizations() (err error) {
603602
return err
604603
}
605604

606-
// GetOrganizations returns paginated organizations that user belongs to.
607-
// TODO: does not respect All and show orgs you privately participate
608-
func (u *User) GetOrganizations(opts *SearchOrganizationsOptions) error {
609-
sess := x.NewSession()
610-
defer sess.Close()
611-
612-
schema, err := x.TableInfo(new(User))
613-
if err != nil {
614-
return err
615-
}
616-
groupByCols := &strings.Builder{}
617-
for _, col := range schema.Columns() {
618-
fmt.Fprintf(groupByCols, "`%s`.%s,", schema.Name, col.Name)
619-
}
620-
groupByStr := groupByCols.String()
621-
groupByStr = groupByStr[0 : len(groupByStr)-1]
622-
623-
sess.Select("`user`.*, count(repo_id) as org_count").
624-
Table("user").
625-
Join("INNER", "org_user", "`org_user`.org_id=`user`.id").
626-
Join("LEFT", builder.
627-
Select("id as repo_id, owner_id as repo_owner_id").
628-
From("repository").
629-
Where(accessibleRepositoryCondition(u)), "`repository`.repo_owner_id = `org_user`.org_id").
630-
And("`org_user`.uid=?", u.ID).
631-
GroupBy(groupByStr)
632-
if opts.PageSize != 0 {
633-
sess = opts.setSessionPagination(sess)
634-
}
635-
type OrgCount struct {
636-
User `xorm:"extends"`
637-
OrgCount int
638-
}
639-
orgCounts := make([]*OrgCount, 0, 10)
640-
641-
if err := sess.
642-
Asc("`user`.name").
643-
Find(&orgCounts); err != nil {
644-
return err
645-
}
646-
647-
orgs := make([]*User, len(orgCounts))
648-
for i, orgCount := range orgCounts {
649-
orgCount.User.NumRepos = orgCount.OrgCount
650-
orgs[i] = &orgCount.User
651-
}
652-
653-
u.Orgs = orgs
654-
655-
return nil
656-
}
657-
658605
// DisplayName returns full name if it's not empty,
659606
// returns username otherwise.
660607
func (u *User) DisplayName() string {

0 commit comments

Comments
 (0)