Skip to content

Commit a4f3690

Browse files
Merge branch 'main' into refactor-migration-test
2 parents 1e6c526 + 65c6acc commit a4f3690

Some content is hidden

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

44 files changed

+17794
-15364
lines changed

.drone.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ steps:
6565

6666
- name: checks-backend
6767
pull: always
68-
image: golang:1.16
68+
image: golang:1.17
6969
commands:
7070
- make checks-backend
7171
depends_on: [lint-backend]
@@ -93,7 +93,7 @@ steps:
9393
depends_on: [checks-backend]
9494

9595
- name: build-backend-arm64
96-
image: golang:1.16
96+
image: golang:1.17
9797
environment:
9898
GO111MODULE: on
9999
GOPROXY: off
@@ -106,7 +106,7 @@ steps:
106106
depends_on: [checks-backend]
107107

108108
- name: build-backend-windows
109-
image: golang:1.16
109+
image: golang:1.17
110110
environment:
111111
GO111MODULE: on
112112
GOPROXY: off
@@ -118,7 +118,7 @@ steps:
118118
depends_on: [checks-backend]
119119

120120
- name: build-backend-386
121-
image: golang:1.16
121+
image: golang:1.17
122122
environment:
123123
GO111MODULE: on
124124
GOPROXY: off
@@ -193,7 +193,7 @@ steps:
193193

194194
- name: build
195195
pull: always
196-
image: golang:1.16
196+
image: golang:1.17
197197
commands:
198198
- make backend
199199
environment:
@@ -208,7 +208,7 @@ steps:
208208
- git update-ref refs/heads/tag_test ${DRONE_COMMIT_SHA}
209209

210210
- name: unit-test
211-
image: golang:1.16
211+
image: golang:1.17
212212
commands:
213213
- make unit-test-coverage test-check
214214
environment:
@@ -218,7 +218,7 @@ steps:
218218
from_secret: github_read_token
219219

220220
- name: unit-test-race
221-
image: golang:1.16
221+
image: golang:1.17
222222
commands:
223223
- make test-backend
224224
environment:
@@ -230,7 +230,7 @@ steps:
230230

231231
- name: unit-test-gogit
232232
pull: always
233-
image: golang:1.16
233+
image: golang:1.17
234234
commands:
235235
- make unit-test-coverage test-check
236236
environment:
@@ -277,7 +277,7 @@ steps:
277277
- build
278278

279279
- name: generate-coverage
280-
image: golang:1.16
280+
image: golang:1.17
281281
commands:
282282
- make coverage
283283
environment:
@@ -351,7 +351,7 @@ steps:
351351

352352
- name: build
353353
pull: always
354-
image: golang:1.16
354+
image: golang:1.17
355355
commands:
356356
- make backend
357357
environment:
@@ -463,7 +463,7 @@ trigger:
463463

464464
steps:
465465
- name: download
466-
image: golang:1.16
466+
image: golang:1.17
467467
commands:
468468
- timeout -s ABRT 40m make generate-license generate-gitignore
469469

.eslintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ rules:
125125
import/no-deprecated: [0]
126126
import/no-dynamic-require: [0]
127127
import/no-extraneous-dependencies: [2]
128+
import/no-import-module-exports: [0]
128129
import/no-internal-modules: [0]
129130
import/no-mutable-exports: [2]
130131
import/no-named-as-default-member: [0]
@@ -133,6 +134,7 @@ rules:
133134
import/no-named-export: [0]
134135
import/no-namespace: [0]
135136
import/no-nodejs-modules: [0]
137+
import/no-relative-packages: [0]
136138
import/no-relative-parent-imports: [0]
137139
import/no-restricted-paths: [0]
138140
import/no-self-import: [2]
@@ -365,6 +367,7 @@ rules:
365367
unicorn/no-abusive-eslint-disable: [0]
366368
unicorn/no-array-for-each: [0]
367369
unicorn/no-array-instanceof: [0]
370+
unicorn/no-array-method-this-argument: [2]
368371
unicorn/no-array-push-push: [2]
369372
unicorn/no-console-spaces: [0]
370373
unicorn/no-document-cookie: [2]
@@ -385,6 +388,8 @@ rules:
385388
unicorn/no-unreadable-array-destructuring: [0]
386389
unicorn/no-unsafe-regex: [0]
387390
unicorn/no-unused-properties: [2]
391+
unicorn/no-useless-length-check: [2]
392+
unicorn/no-useless-spread: [2]
388393
unicorn/no-useless-undefined: [0]
389394
unicorn/no-zero-fractions: [2]
390395
unicorn/number-literal-case: [0]
@@ -395,6 +400,7 @@ rules:
395400
unicorn/prefer-array-flat: [2]
396401
unicorn/prefer-array-index-of: [2]
397402
unicorn/prefer-array-some: [2]
403+
unicorn/prefer-at: [0]
398404
unicorn/prefer-dataset: [2]
399405
unicorn/prefer-date-now: [2]
400406
unicorn/prefer-default-parameters: [0]
@@ -408,7 +414,10 @@ rules:
408414
unicorn/prefer-node-protocol: [0]
409415
unicorn/prefer-node-remove: [0]
410416
unicorn/prefer-number-properties: [0]
417+
unicorn/prefer-object-from-entries: [2]
418+
unicorn/prefer-object-has-own: [0]
411419
unicorn/prefer-optional-catch-binding: [2]
420+
unicorn/prefer-prototype-methods: [0]
412421
unicorn/prefer-query-selector: [0]
413422
unicorn/prefer-reflect-apply: [0]
414423
unicorn/prefer-regexp-test: [2]
@@ -420,9 +429,13 @@ rules:
420429
unicorn/prefer-switch: [0]
421430
unicorn/prefer-ternary: [0]
422431
unicorn/prefer-text-content: [2]
432+
unicorn/prefer-top-level-await: [0]
423433
unicorn/prefer-trim-start-end: [2]
424434
unicorn/prefer-type-error: [0]
425435
unicorn/prevent-abbreviations: [0]
436+
unicorn/require-array-join-separator: [2]
437+
unicorn/require-number-to-fixed-digits-argument: [2]
438+
unicorn/require-post-message-target-origin: [0]
426439
unicorn/string-content: [0]
427440
unicorn/throw-new-error: [2]
428441
use-isnan: [2]

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
###################################
33
#Build stage
4-
FROM golang:1.16-alpine3.13 AS build-env
4+
FROM golang:1.17-alpine3.13 AS build-env
55

66
ARG GOPROXY
77
ENV GOPROXY ${GOPROXY:-direct}

Dockerfile.rootless

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
###################################
33
#Build stage
4-
FROM golang:1.16-alpine3.13 AS build-env
4+
FROM golang:1.17-alpine3.13 AS build-env
55

66
ARG GOPROXY
77
ENV GOPROXY ${GOPROXY:-direct}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SHASUM ?= shasum -a 256
2424
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
2525
COMMA := ,
2626

27-
XGO_VERSION := go-1.16.x
27+
XGO_VERSION := go-1.17.x
2828
MIN_GO_VERSION := 001016000
2929
MIN_NODE_VERSION := 012017000
3030

build/generate-svg.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fastGlob from 'fast-glob';
2-
import {optimize, extendDefaultPlugins} from 'svgo';
2+
import {optimize} from 'svgo';
33
import {resolve, parse, dirname} from 'path';
44
import fs from 'fs';
55
import {fileURLToPath} from 'url';
@@ -26,18 +26,13 @@ async function processFile(file, {prefix, fullName} = {}) {
2626
}
2727

2828
const {data} = optimize(await readFile(file, 'utf8'), {
29-
plugins: extendDefaultPlugins([
30-
'removeXMLNS',
31-
'removeDimensions',
32-
{
33-
name: 'addClassesToSVGElement',
34-
params: {classNames: ['svg', name]},
35-
},
36-
{
37-
name: 'addAttributesToSVGElement',
38-
params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]},
39-
},
40-
]),
29+
plugins: [
30+
{name: 'preset-default'},
31+
{name: 'removeXMLNS'},
32+
{name: 'removeDimensions'},
33+
{name: 'addClassesToSVGElement', params: {classNames: ['svg', name]}},
34+
{name: 'addAttributesToSVGElement', params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]}},
35+
],
4136
});
4237
await writeFile(resolve(outputDir, `${name}.svg`), data);
4338
}

custom/conf/app.example.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ INTERNAL_TOKEN=
378378
;;
379379
;; Validate against https://haveibeenpwned.com/Passwords to see if a password has been exposed
380380
;PASSWORD_CHECK_PWN = false
381+
;;
382+
;; Cache successful token hashes. API tokens are stored in the DB as pbkdf2 hashes however, this means that there is a potentially significant hashing load when there are multiple API operations.
383+
;; This cache will store the successfully hashed tokens in a LRU cache as a balance between performance and security.
384+
;SUCCESSFUL_TOKENS_CACHE_SIZE = 20
381385

382386
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
383387
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ params:
2020
website: https://docs.gitea.io
2121
version: 1.14.6
2222
minGoVersion: 1.16
23-
goVersion: 1.16
23+
goVersion: 1.17
2424
minNodeVersion: 12.17
2525

2626
outputs:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ relation to port exhaustion.
441441
- spec - use one or more special characters as ``!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~``
442442
- off - do not check password complexity
443443
- `PASSWORD_CHECK_PWN`: **false**: Check [HaveIBeenPwned](https://haveibeenpwned.com/Passwords) to see if a password has been exposed.
444+
- `SUCCESSFUL_TOKENS_CACHE_SIZE`: **20**: Cache successful token hashes. API tokens are stored in the DB as pbkdf2 hashes however, this means that there is a potentially significant hashing load when there are multiple API operations. This cache will store the successfully hashed tokens in a LRU cache as a balance between performance and security.
444445

445446
## OpenID (`openid`)
446447

jest.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
export default {
2+
rootDir: 'web_src',
23
setupFilesAfterEnv: ['jest-extended'],
4+
testEnvironment: 'jsdom',
5+
testMatch: ['<rootDir>/**/*.test.js'],
36
testTimeout: 20000,
4-
rootDir: 'web_src',
5-
testMatch: [
6-
'<rootDir>/**/*.test.js',
7-
],
87
transform: {},
98
verbose: false,
109
};

models/models.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
// Needed for the MySQL driver
1919
_ "github.com/go-sql-driver/mysql"
20+
lru "github.com/hashicorp/golang-lru"
2021
"xorm.io/xorm"
2122
"xorm.io/xorm/names"
2223
"xorm.io/xorm/schemas"
@@ -234,6 +235,15 @@ func NewEngine(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err e
234235
return fmt.Errorf("sync database struct error: %v", err)
235236
}
236237

238+
if setting.SuccessfulTokensCacheSize > 0 {
239+
successfulAccessTokenCache, err = lru.New(setting.SuccessfulTokensCacheSize)
240+
if err != nil {
241+
return fmt.Errorf("unable to allocate AccessToken cache: %v", err)
242+
}
243+
} else {
244+
successfulAccessTokenCache = nil
245+
}
246+
237247
return nil
238248
}
239249

models/token.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import (
1414
"code.gitea.io/gitea/modules/util"
1515

1616
gouuid "github.com/google/uuid"
17+
lru "github.com/hashicorp/golang-lru"
1718
)
1819

20+
var successfulAccessTokenCache *lru.Cache
21+
1922
// AccessToken represents a personal access token.
2023
type AccessToken struct {
2124
ID int64 `xorm:"pk autoincr"`
@@ -52,6 +55,21 @@ func NewAccessToken(t *AccessToken) error {
5255
return err
5356
}
5457

58+
func getAccessTokenIDFromCache(token string) int64 {
59+
if successfulAccessTokenCache == nil {
60+
return 0
61+
}
62+
tInterface, ok := successfulAccessTokenCache.Get(token)
63+
if !ok {
64+
return 0
65+
}
66+
t, ok := tInterface.(int64)
67+
if !ok {
68+
return 0
69+
}
70+
return t
71+
}
72+
5573
// GetAccessTokenBySHA returns access token by given token value
5674
func GetAccessTokenBySHA(token string) (*AccessToken, error) {
5775
if token == "" {
@@ -66,17 +84,38 @@ func GetAccessTokenBySHA(token string) (*AccessToken, error) {
6684
return nil, ErrAccessTokenNotExist{token}
6785
}
6886
}
69-
var tokens []AccessToken
87+
7088
lastEight := token[len(token)-8:]
89+
90+
if id := getAccessTokenIDFromCache(token); id > 0 {
91+
token := &AccessToken{
92+
TokenLastEight: lastEight,
93+
}
94+
// Re-get the token from the db in case it has been deleted in the intervening period
95+
has, err := x.ID(id).Get(token)
96+
if err != nil {
97+
return nil, err
98+
}
99+
if has {
100+
return token, nil
101+
}
102+
successfulAccessTokenCache.Remove(token)
103+
}
104+
105+
var tokens []AccessToken
71106
err := x.Table(&AccessToken{}).Where("token_last_eight = ?", lastEight).Find(&tokens)
72107
if err != nil {
73108
return nil, err
74109
} else if len(tokens) == 0 {
75110
return nil, ErrAccessTokenNotExist{token}
76111
}
112+
77113
for _, t := range tokens {
78114
tempHash := hashToken(token, t.TokenSalt)
79115
if subtle.ConstantTimeCompare([]byte(t.TokenHash), []byte(tempHash)) == 1 {
116+
if successfulAccessTokenCache != nil {
117+
successfulAccessTokenCache.Add(token, t.ID)
118+
}
80119
return &t, nil
81120
}
82121
}

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ var (
189189
PasswordComplexity []string
190190
PasswordHashAlgo string
191191
PasswordCheckPwn bool
192+
SuccessfulTokensCacheSize int
192193

193194
// UI settings
194195
UI = struct {
@@ -840,6 +841,7 @@ func NewContext() {
840841
PasswordHashAlgo = sec.Key("PASSWORD_HASH_ALGO").MustString("pbkdf2")
841842
CSRFCookieHTTPOnly = sec.Key("CSRF_COOKIE_HTTP_ONLY").MustBool(true)
842843
PasswordCheckPwn = sec.Key("PASSWORD_CHECK_PWN").MustBool(false)
844+
SuccessfulTokensCacheSize = sec.Key("SUCCESSFUL_TOKENS_CACHE_SIZE").MustInt(20)
843845

844846
InternalToken = loadInternalToken(sec)
845847

options/locale/locale_ja-JP.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,7 @@ auths.allowed_domains=許可するドメイン
24322432
auths.allowed_domains_helper=すべてのドメインを許可する場合は空のままにします。 複数のドメインはカンマ(',')で区切ります。
24332433
auths.skip_tls_verify=TLS検証を省略
24342434
auths.force_smtps=強制的にSMTPSにする
2435+
auths.force_smtps_helper=ポート465ではSMTPSが常に使用されます。 これを指定すると、他のポートでもSMTPSの使用を強制します。 (指定しない場合は、ホストがサポートしていればSTARTTLSが使用されます。)
24352436
auths.helo_hostname=HELOホストネーム
24362437
auths.helo_hostname_helper=HELOで送られるホスト名。現在のホスト名で送信する場合は空白にします。
24372438
auths.disable_helo=HELOを無効にする

0 commit comments

Comments
 (0)