Skip to content

Commit 92a4a33

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: (22 commits) Use case-insensitive regex for all webpack assets (go-gitea#26867) restrict certificate type for builtin SSH server (go-gitea#26789) feat(API): add secret deletion functionality for repository (go-gitea#26808) Avoid double-unescaping of form value (go-gitea#26853) Move web/api context related testing function into a separate package (go-gitea#26859) Remove some unused CSS styles (go-gitea#26852) [skip ci] Updated translations via Crowdin Minor dashboard tweaks, fix flex-list margins (go-gitea#26829) Update team invitation email link (go-gitea#26550) Redirect from `{repo}/issues/new` to `{repo}/issues/new/choose` when blank issues are disabled (go-gitea#26813) Remove "TODO" tasks from CSS file (go-gitea#26835) User details page (go-gitea#26713) Render code blocks in repo description (go-gitea#26830) Remove joinPaths function (go-gitea#26833) Remove polluted `.ui.right` (go-gitea#26825) Sync tags when adopting repos (go-gitea#26816) rm comment about hugo (go-gitea#26832) Fix filename for .spectral.yaml (go-gitea#26828) [skip ci] Updated translations via Crowdin Check blocklist for emails when adding them to account (go-gitea#26812) ...
2 parents 91a5317 + 327a7ad commit 92a4a33

File tree

111 files changed

+1200
-757
lines changed

Some content is hidden

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

111 files changed

+1200
-757
lines changed

.github/workflows/files-changed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ jobs:
8181
- "Makefile"
8282
- "package.json"
8383
- "package-lock.json"
84-
- ".spectral.yml"
84+
- ".spectral.yaml"

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ If you have questions that are not covered by the documentation, you can get in
121121

122122
We maintain a list of Gitea-related projects at [gitea/awesome-gitea](https://gitea.com/gitea/awesome-gitea).
123123

124-
The Hugo-based documentation theme is hosted at [gitea/theme](https://gitea.com/gitea/theme).
125-
126124
The official Gitea CLI is developed at [gitea/tea](https://gitea.com/gitea/tea).
127125

128126
## Authors

models/user/email_address.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/setting"
1818
"code.gitea.io/gitea/modules/util"
19+
"code.gitea.io/gitea/modules/validation"
1920

2021
"xorm.io/builder"
2122
)
@@ -161,7 +162,17 @@ func ValidateEmail(email string) error {
161162
return ErrEmailInvalid{email}
162163
}
163164

164-
// TODO: add an email allow/block list
165+
// if there is no allow list, then check email against block list
166+
if len(setting.Service.EmailDomainAllowList) == 0 &&
167+
validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) {
168+
return ErrEmailInvalid{email}
169+
}
170+
171+
// if there is an allow list, then check email against allow list
172+
if len(setting.Service.EmailDomainAllowList) > 0 &&
173+
!validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) {
174+
return ErrEmailInvalid{email}
175+
}
165176

166177
return nil
167178
}

modules/context/utils.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,27 @@
44
package context
55

66
import (
7-
"net/url"
87
"strings"
98
"time"
109
)
1110

1211
// GetQueryBeforeSince return parsed time (unix format) from URL query's before and since
1312
func GetQueryBeforeSince(ctx *Base) (before, since int64, err error) {
14-
qCreatedBefore, err := prepareQueryArg(ctx, "before")
13+
before, err = parseFormTime(ctx, "before")
1514
if err != nil {
1615
return 0, 0, err
1716
}
1817

19-
qCreatedSince, err := prepareQueryArg(ctx, "since")
20-
if err != nil {
21-
return 0, 0, err
22-
}
23-
24-
before, err = parseTime(qCreatedBefore)
25-
if err != nil {
26-
return 0, 0, err
27-
}
28-
29-
since, err = parseTime(qCreatedSince)
18+
since, err = parseFormTime(ctx, "since")
3019
if err != nil {
3120
return 0, 0, err
3221
}
3322
return before, since, nil
3423
}
3524

3625
// parseTime parse time and return unix timestamp
37-
func parseTime(value string) (int64, error) {
26+
func parseFormTime(ctx *Base, name string) (int64, error) {
27+
value := strings.TrimSpace(ctx.FormString(name))
3828
if len(value) != 0 {
3929
t, err := time.Parse(time.RFC3339, value)
4030
if err != nil {
@@ -46,10 +36,3 @@ func parseTime(value string) (int64, error) {
4636
}
4737
return 0, nil
4838
}
49-
50-
// prepareQueryArg unescape and trim a query arg
51-
func prepareQueryArg(ctx *Base, name string) (value string, err error) {
52-
value, err = url.PathUnescape(ctx.FormString(name))
53-
value = strings.TrimSpace(value)
54-
return value, err
55-
}

modules/test/context_tests.go renamed to modules/contexttest/context_tests.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright 2017 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
package test
4+
// Package contexttest provides utilities for testing Web/API contexts with models.
5+
package contexttest
56

67
import (
78
gocontext "context"
@@ -22,7 +23,7 @@ import (
2223
"code.gitea.io/gitea/modules/translation"
2324
"code.gitea.io/gitea/modules/web/middleware"
2425

25-
chi "github.com/go-chi/chi/v5"
26+
"github.com/go-chi/chi/v5"
2627
"github.com/stretchr/testify/assert"
2728
)
2829

@@ -40,7 +41,6 @@ func mockRequest(t *testing.T, reqPath string) *http.Request {
4041
}
4142

4243
// MockContext mock context for unit tests
43-
// TODO: move this function to other packages, because it depends on "models" package
4444
func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.ResponseRecorder) {
4545
resp := httptest.NewRecorder()
4646
req := mockRequest(t, reqPath)
@@ -50,15 +50,13 @@ func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.Resp
5050
base.Locale = &translation.MockLocale{}
5151

5252
ctx := context.NewWebContext(base, &MockRender{}, nil)
53-
ctx.Flash = &middleware.Flash{Values: url.Values{}}
5453

5554
chiCtx := chi.NewRouteContext()
5655
ctx.Base.AppendContextValue(chi.RouteCtxKey, chiCtx)
5756
return ctx, resp
5857
}
5958

6059
// MockAPIContext mock context for unit tests
61-
// TODO: move this function to other packages, because it depends on "models" package
6260
func MockAPIContext(t *testing.T, reqPath string) (*context.APIContext, *httptest.ResponseRecorder) {
6361
resp := httptest.NewRecorder()
6462
req := mockRequest(t, reqPath)
@@ -123,7 +121,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) {
123121
}
124122
}
125123

126-
// LoadUser load a user into a test context.
124+
// LoadUser load a user into a test context
127125
func LoadUser(t *testing.T, ctx gocontext.Context, userID int64) {
128126
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
129127
switch ctx := ctx.(type) {

modules/ssh/ssh.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
191191
return false
192192
}
193193

194+
if cert.CertType != gossh.UserCert {
195+
log.Warn("Certificate Rejected: Not a user certificate")
196+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
197+
return false
198+
}
199+
194200
// look for the exact principal
195201
principalLoop:
196202
for _, principal := range cert.ValidPrincipals {

modules/templates/util_render.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri
108108
// Match text that is between back ticks.
109109
var codeMatcher = regexp.MustCompile("`([^`]+)`")
110110

111-
// RenderCodeBlock renders "`…`" as highlighted "<code>" block.
112-
// Intended for issue and PR titles, these containers should have styles for "<code>" elements
111+
// RenderCodeBlock renders "`…`" as highlighted "<code>" block, intended for issue and PR titles
113112
func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
114-
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "<code>$1</code>") // replace with HTML <code> tags
113+
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), `<code class="inline-code-block">$1</code>`) // replace with HTML <code> tags
115114
return template.HTML(htmlWithCodeTags)
116115
}
117116

modules/validation/helpers.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/modules/setting"
13+
14+
"github.com/gobwas/glob"
1315
)
1416

1517
var externalTrackerRegex = regexp.MustCompile(`({?)(?:user|repo|index)+?(}?)`)
@@ -48,6 +50,29 @@ func IsValidSiteURL(uri string) bool {
4850
return false
4951
}
5052

53+
// IsEmailDomainListed checks whether the domain of an email address
54+
// matches a list of domains
55+
func IsEmailDomainListed(globs []glob.Glob, email string) bool {
56+
if len(globs) == 0 {
57+
return false
58+
}
59+
60+
n := strings.LastIndex(email, "@")
61+
if n <= 0 {
62+
return false
63+
}
64+
65+
domain := strings.ToLower(email[n+1:])
66+
67+
for _, g := range globs {
68+
if g.Match(domain) {
69+
return true
70+
}
71+
}
72+
73+
return false
74+
}
75+
5176
// IsAPIURL checks if URL is current Gitea instance API URL
5277
func IsAPIURL(uri string) bool {
5378
return strings.HasPrefix(strings.ToLower(uri), strings.ToLower(setting.AppURL+"api"))

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,7 @@ users.list_status_filter.is_prohibit_login = Prohibit Login
28232823
users.list_status_filter.not_prohibit_login = Allow Login
28242824
users.list_status_filter.is_2fa_enabled = 2FA Enabled
28252825
users.list_status_filter.not_2fa_enabled = 2FA Disabled
2826+
users.details = User Details
28262827

28272828
emails.email_manage_panel = User Email Management
28282829
emails.primary = Primary

0 commit comments

Comments
 (0)