Skip to content

Commit 7498e13

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Use base32 for 2FA scratch token (go-gitea#18384) [skip ci] Updated translations via Crowdin Fix broken oauth2 authentication source edit page (go-gitea#18412) Prevent deadlocks in persistable channel pause test (go-gitea#18410) Bump golangci-lint version (go-gitea#18411) Unexport git.GlobalCommandArgs (go-gitea#18376)
2 parents 0579c7b + 49dd906 commit 7498e13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+191
-252
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ COMMA := ,
2727
XGO_VERSION := go-1.17.x
2828
MIN_GO_VERSION := 001016000
2929
MIN_NODE_VERSION := 012017000
30-
MIN_GOLANGCI_LINT_VERSION := 001043000
30+
MIN_GOLANGCI_LINT_VERSION := 001044000
3131

3232
DOCKER_IMAGE ?= gitea/gitea
3333
DOCKER_TAG ?= latest

integrations/git_clone_wiki_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestRepoCloneWiki(t *testing.T) {
4141
u, _ = url.Parse(r)
4242
u.User = url.UserPassword("user2", userPassword)
4343
t.Run("Clone", func(t *testing.T) {
44-
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstPath, allowLFSFilters(), git.CloneRepoOptions{}))
44+
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstPath, git.AllowLFSFiltersArgs(), git.CloneRepoOptions{}))
4545
assertFileEqual(t, filepath.Join(dstPath, "Home.md"), []byte("# Home page\n\nThis is the home page!\n"))
4646
assertFileExist(t, filepath.Join(dstPath, "Page-With-Image.md"))
4747
assertFileExist(t, filepath.Join(dstPath, "Page-With-Spaced-Name.md"))

integrations/git_helper_for_declarative_test.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"path"
1515
"path/filepath"
1616
"strconv"
17-
"strings"
1817
"testing"
1918
"time"
2019

@@ -60,21 +59,6 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
6059
return &u2
6160
}
6261

63-
func allowLFSFilters() []string {
64-
// Now here we should explicitly allow lfs filters to run
65-
filteredLFSGlobalArgs := make([]string, len(git.GlobalCommandArgs))
66-
j := 0
67-
for _, arg := range git.GlobalCommandArgs {
68-
if strings.Contains(arg, "lfs") {
69-
j--
70-
} else {
71-
filteredLFSGlobalArgs[j] = arg
72-
j++
73-
}
74-
}
75-
return filteredLFSGlobalArgs[:j]
76-
}
77-
7862
func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) {
7963
if len(prepare) == 0 || prepare[0] {
8064
defer prepareTestEnv(t, 1)()
@@ -115,7 +99,7 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
11599

116100
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
117101
return func(t *testing.T) {
118-
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{}))
102+
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, git.AllowLFSFiltersArgs(), git.CloneRepoOptions{}))
119103
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
120104
assert.NoError(t, err)
121105
assert.True(t, exist)
@@ -124,7 +108,7 @@ func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
124108

125109
func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
126110
return func(t *testing.T) {
127-
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{
111+
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, git.AllowLFSFiltersArgs(), git.CloneRepoOptions{
128112
Filter: "blob:none",
129113
}))
130114
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
@@ -197,7 +181,7 @@ func doGitCreateBranch(dstPath, branch string) func(*testing.T) {
197181

198182
func doGitCheckoutBranch(dstPath string, args ...string) func(*testing.T) {
199183
return func(t *testing.T) {
200-
_, err := git.NewCommandNoGlobals(append(append(allowLFSFilters(), "checkout"), args...)...).RunInDir(dstPath)
184+
_, err := git.NewCommandNoGlobals(append(append(git.AllowLFSFiltersArgs(), "checkout"), args...)...).RunInDir(dstPath)
201185
assert.NoError(t, err)
202186
}
203187
}
@@ -211,7 +195,7 @@ func doGitMerge(dstPath string, args ...string) func(*testing.T) {
211195

212196
func doGitPull(dstPath string, args ...string) func(*testing.T) {
213197
return func(t *testing.T) {
214-
_, err := git.NewCommandNoGlobals(append(append(allowLFSFilters(), "pull"), args...)...).RunInDir(dstPath)
198+
_, err := git.NewCommandNoGlobals(append(append(git.AllowLFSFiltersArgs(), "pull"), args...)...).RunInDir(dstPath)
215199
assert.NoError(t, err)
216200
}
217201
}

integrations/git_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
167167
err = git.AddChanges(dstPath, false, ".gitattributes")
168168
assert.NoError(t, err)
169169

170-
err = git.CommitChangesWithArgs(dstPath, allowLFSFilters(), git.CommitChangesOptions{
170+
err = git.CommitChangesWithArgs(dstPath, git.AllowLFSFiltersArgs(), git.CommitChangesOptions{
171171
Committer: &git.Signature{
172172
Email: "user2@example.com",
173173
Name: "User Two",
@@ -346,7 +346,7 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
346346

347347
// Commit
348348
// Now here we should explicitly allow lfs filters to run
349-
globalArgs := allowLFSFilters()
349+
globalArgs := git.AllowLFSFiltersArgs()
350350
err = git.AddChangesWithArgs(repoPath, globalArgs, false, filepath.Base(tmpFile.Name()))
351351
if err != nil {
352352
return "", err

models/auth/twofactor.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto/md5"
99
"crypto/sha256"
1010
"crypto/subtle"
11+
"encoding/base32"
1112
"encoding/base64"
1213
"fmt"
1314

@@ -58,11 +59,14 @@ func init() {
5859

5960
// GenerateScratchToken recreates the scratch token the user is using.
6061
func (t *TwoFactor) GenerateScratchToken() (string, error) {
61-
token, err := util.RandomString(8)
62+
tokenBytes, err := util.CryptoRandomBytes(6)
6263
if err != nil {
6364
return "", err
6465
}
65-
t.ScratchSalt, _ = util.RandomString(10)
66+
// these chars are specially chosen, avoid ambiguous chars like `0`, `O`, `1`, `I`.
67+
const base32Chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
68+
token := base32.NewEncoding(base32Chars).WithPadding(base32.NoPadding).EncodeToString(tokenBytes)
69+
t.ScratchSalt, _ = util.CryptoRandomString(10)
6670
t.ScratchHash = HashToken(token, t.ScratchSalt)
6771
return token, nil
6872
}

models/migrations/v71.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func addScratchHash(x *xorm.Engine) error {
5353

5454
for _, tfa := range tfas {
5555
// generate salt
56-
salt, err := util.RandomString(10)
56+
salt, err := util.CryptoRandomString(10)
5757
if err != nil {
5858
return err
5959
}

models/migrations/v85.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func hashAppToken(x *xorm.Engine) error {
6565

6666
for _, token := range tokens {
6767
// generate salt
68-
salt, err := util.RandomString(10)
68+
salt, err := util.CryptoRandomString(10)
6969
if err != nil {
7070
return err
7171
}

models/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func init() {
6262

6363
// NewAccessToken creates new access token.
6464
func NewAccessToken(t *AccessToken) error {
65-
salt, err := util.RandomString(10)
65+
salt, err := util.CryptoRandomString(10)
6666
if err != nil {
6767
return err
6868
}

models/user/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ const SaltByteLength = 16
533533

534534
// GetUserSalt returns a random user salt token.
535535
func GetUserSalt() (string, error) {
536-
rBytes, err := util.RandomBytes(SaltByteLength)
536+
rBytes, err := util.CryptoRandomBytes(SaltByteLength)
537537
if err != nil {
538538
return "", err
539539
}

modules/generate/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewJwtSecretBase64() (string, error) {
6060

6161
// NewSecretKey generate a new value intended to be used by SECRET_KEY.
6262
func NewSecretKey() (string, error) {
63-
secretKey, err := util.RandomString(64)
63+
secretKey, err := util.CryptoRandomString(64)
6464
if err != nil {
6565
return "", err
6666
}

0 commit comments

Comments
 (0)