mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-14 01:11:55 +02:00
Addresses a batch of privately reported security issues, grouped by
area:
- **SSRF** - migration PR-patch/asset fetches, OAuth2 avatar & OpenID
discovery, pull-mirror URL re-validation, and the outbound proxy path.
- **Access-token scope** - prevent scope escalation on token creation;
keep public-only tokens confined (feeds, packages, Actions listings,
star/watch lists, limited/private owners).
- **Access control / disclosure** - go-get default-branch leak, webhook
authorization-header leak, watch clearing on private transitions,
label/attachment scoping.
- **Denial of service** - input bounds for npm dist-tags, Debian control
files, Arch file lists, and SSH keys.
### 📌 Attention for site admins
Not breaking - existing configs keep working - but two changes are worth
a look:
- **New SSRF protection** Outbound requests (migrations, OAuth2 avatars,
OpenID discovery, pull mirrors, proxy path) are now validated against
the allow/block host lists. If your instance legitimately reaches
internal hosts, you may need to add them to
`[security].ALLOWED_HOST_LIST` (and the relevant `ALLOW_LOCALNETWORKS`
settings).
- **Deprecation** `[webhook].ALLOWED_HOST_LIST` is deprecated and will
be removed in a future release. Use `[security].ALLOWED_HOST_LIST`
instead; the old key still works for now.
---------
Co-authored-by: TheFox0x7 <thefox0x7@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
142 lines
5.2 KiB
Go
142 lines
5.2 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issues_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dev/models/db"
|
|
issues_model "gitea.dev/models/issues"
|
|
repo_model "gitea.dev/models/repo"
|
|
"gitea.dev/models/unittest"
|
|
user_model "gitea.dev/models/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCreateComment(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{})
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
|
|
now := time.Now().Unix()
|
|
comment, err := issues_model.CreateComment(t.Context(), &issues_model.CreateCommentOptions{
|
|
Type: issues_model.CommentTypeComment,
|
|
Doer: doer,
|
|
Repo: repo,
|
|
Issue: issue,
|
|
Content: "Hello",
|
|
})
|
|
assert.NoError(t, err)
|
|
then := time.Now().Unix()
|
|
|
|
assert.Equal(t, issues_model.CommentTypeComment, comment.Type)
|
|
assert.Equal(t, "Hello", comment.Content)
|
|
assert.Equal(t, issue.ID, comment.IssueID)
|
|
assert.Equal(t, doer.ID, comment.PosterID)
|
|
unittest.AssertInt64InRange(t, now, then, int64(comment.CreatedUnix))
|
|
unittest.AssertExistsAndLoadBean(t, comment) // assert actually added to DB
|
|
|
|
updatedIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue.ID})
|
|
unittest.AssertInt64InRange(t, now, then, int64(updatedIssue.UpdatedUnix))
|
|
}
|
|
|
|
func TestLoadAssigneeUserAndTeam_DeletedTeamBecomesGhostTeam(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 15})
|
|
comment := &issues_model.Comment{
|
|
Type: issues_model.CommentTypeAssignees,
|
|
IssueID: issue.ID,
|
|
AssigneeTeamID: 999999, // non-existing team ID
|
|
}
|
|
assert.NoError(t, comment.LoadAssigneeUserAndTeam(t.Context()))
|
|
assert.NotNil(t, comment.AssigneeTeam)
|
|
assert.EqualValues(t, -1, comment.AssigneeTeam.ID)
|
|
}
|
|
|
|
func Test_UpdateCommentAttachment(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 1})
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID})
|
|
attachment := repo_model.Attachment{
|
|
RepoID: issue.RepoID, // must match the comment's repo, else the cross-repo guard rejects it
|
|
Name: "test.txt",
|
|
}
|
|
assert.NoError(t, db.Insert(t.Context(), &attachment))
|
|
|
|
err := issues_model.UpdateCommentAttachments(t.Context(), comment, []string{attachment.UUID})
|
|
assert.NoError(t, err)
|
|
|
|
attachment2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: attachment.ID})
|
|
assert.Equal(t, attachment.Name, attachment2.Name)
|
|
assert.Equal(t, comment.ID, attachment2.CommentID)
|
|
assert.Equal(t, comment.IssueID, attachment2.IssueID)
|
|
}
|
|
|
|
func TestFetchCodeComments(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
res, err := issues_model.FetchCodeComments(t.Context(), issue, user, false)
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, res, "README.md")
|
|
assert.Contains(t, res["README.md"], int64(4))
|
|
assert.Len(t, res["README.md"][4], 1)
|
|
assert.Equal(t, int64(4), res["README.md"][4][0].ID)
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
res, err = issues_model.FetchCodeComments(t.Context(), issue, user2, false)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, res, 1)
|
|
}
|
|
|
|
func TestAsCommentType(t *testing.T) {
|
|
assert.Equal(t, issues_model.CommentTypeComment, issues_model.CommentType(0))
|
|
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType(""))
|
|
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType("nonsense"))
|
|
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
|
|
assert.Equal(t, issues_model.CommentTypePRUnScheduledToAutoMerge, issues_model.AsCommentType("pull_cancel_scheduled_merge"))
|
|
}
|
|
|
|
func TestMigrate_InsertIssueComments(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
|
|
_ = issue.LoadRepo(t.Context())
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID})
|
|
reaction := &issues_model.Reaction{
|
|
Type: "heart",
|
|
UserID: owner.ID,
|
|
}
|
|
|
|
comment := &issues_model.Comment{
|
|
PosterID: owner.ID,
|
|
Poster: owner,
|
|
IssueID: issue.ID,
|
|
Issue: issue,
|
|
Reactions: []*issues_model.Reaction{reaction},
|
|
}
|
|
|
|
err := issues_model.InsertIssueComments(t.Context(), []*issues_model.Comment{comment})
|
|
assert.NoError(t, err)
|
|
|
|
issueModified := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
|
|
assert.Equal(t, issue.NumComments+1, issueModified.NumComments)
|
|
|
|
unittest.CheckConsistencyFor(t, &issues_model.Issue{})
|
|
}
|
|
|
|
func Test_UpdateIssueNumComments(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
issue2 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
|
|
assert.NoError(t, issues_model.UpdateIssueNumComments(t.Context(), issue2.ID))
|
|
issue2 = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
assert.Equal(t, 1, issue2.NumComments)
|
|
}
|