fix: add missing checks to several handlers and models (#39839)

Several handlers and model helpers skipped checks that their siblings
already perform.

- Only match principal keys when looking up SSH certificate principals
- Return no attachments for an unsaved issue instead of every issue-less
one
- Reject issue and comment attachments when adding release attachments
- Share one permission check for editing, deleting and reacting to issue
content and for comment attachments between the web UI and the API,
refusing them on locked issues for users who can't write
- Reject issue edits, deletion and label changes in archived
repositories via the API
- Apply cross-origin protection to the repository topics endpoint
- Return 404 for the repositories tab of individual users and respect
profile visibility for the heatmap

Fixes: https://github.com/go-gitea/gitea/issues/39226
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: bircni <bircni@icloud.com>
This commit is contained in:
authored and GitHub committed 2026-10-18 06:29:49 -07:00
1 parent 1031e34987
commit ae17c14cff
28 files changed
+290 -221

No files matched your search

+5
View File
@@ -262,6 +262,11 @@ func testAPIEditIssue(t *testing.T) {
assert.Equal(t, int64(0), int64(issueAfter.DeadlineUnix))
assert.Equal(t, body, issueAfter.Content)
assert.Equal(t, title, issueAfter.Title)
token = getUserToken(t, "user30", auth_model.AccessTokenScopeWriteIssue)
req = NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user30/repo51/issues/1", api.EditIssueOption{Title: title}).AddTokenAuth(token)
MakeRequest(t, req, http.StatusLocked)
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 14, Title: "issue in archived repo"})
}
func testAPISearchIssues(t *testing.T) {
+6
View File
@@ -34,6 +34,12 @@ func TestHeatmapEndpoints(t *testing.T) {
assert.Positive(t, result["totalContributions"])
})
t.Run("PrivateUserProfileAnonymous", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/user31/-/heatmap")
MakeRequest(t, req, http.StatusNotFound)
})
t.Run("OrgDashboard", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/org/org3/dashboard/-/heatmap")
+9
View File
@@ -381,6 +381,15 @@ func TestIssueReaction(t *testing.T) {
"content": "eyes",
})
session.MakeRequest(t, req, http.StatusOK)
assert.NoError(t, issues_model.UpdateIssueCols(t.Context(), &issues_model.Issue{ID: 1, IsLocked: true}, "is_locked"))
readerSession := loginUser(t, "user4")
req = NewRequestWithValues(t, "POST", "/user2/repo1/issues/1/reactions/react", map[string]string{"content": "eyes"})
readerSession.MakeRequest(t, req, http.StatusForbidden)
req = NewRequestWithValues(t, "POST", "/user2/repo1/comments/2/reactions/react", map[string]string{"content": "eyes"})
readerSession.MakeRequest(t, req, http.StatusForbidden)
req = NewRequestWithValues(t, "POST", "/user2/repo1/comments/2/reactions/react", map[string]string{"content": "eyes"})
session.MakeRequest(t, req, http.StatusOK)
}
func TestIssueCrossReference(t *testing.T) {
+13
View File
@@ -14,6 +14,19 @@ import (
"github.com/stretchr/testify/assert"
)
func TestRepoTopicsPostRejectsCrossOrigin(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
req := NewRequestWithValues(t, "POST", "/user2/repo1/topics", map[string]string{"topics": "cross"}).
SetHeader("Sec-Fetch-Site", "cross-site")
session.MakeRequest(t, req, http.StatusForbidden)
req = NewRequestWithValues(t, "POST", "/user2/repo1/topics", map[string]string{"topics": "same"}).
SetHeader("Sec-Fetch-Site", "same-origin")
session.MakeRequest(t, req, http.StatusOK)
}
func TestTopicSearch(t *testing.T) {
defer tests.PrepareTestEnv(t)()
searchURL, _ := url.Parse("/explore/topics/search")
+3
View File
@@ -41,6 +41,9 @@ func testViewUser(t *testing.T) {
req := NewRequest(t, "GET", "/user2")
MakeRequest(t, req, http.StatusOK)
req = NewRequest(t, "GET", "/user2/-/repositories")
MakeRequest(t, req, http.StatusNotFound)
req = NewRequest(t, "GET", "/user2.keys")
resp := MakeRequest(t, req, http.StatusOK)
assert.Equal(t, `# Gitea isn't a key server. The keys are exported as the user uploaded and might not have been fully verified.