mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 16:34:58 +02:00
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:
28 files changed
+290
-221
No files matched your search
@@ -199,7 +199,7 @@ func SearchPrincipalKey(ctx context.Context, principalKey string) (*PublicKey, e
|
||||
// In the future, the existing principal keys should be migrated to use the fingerprint ("principal:{name}") instead of the content
|
||||
key := new(PublicKey)
|
||||
has, err := db.GetEngine(ctx).
|
||||
Where("content = ?", principalKey).
|
||||
Where("content = ? AND type = ?", principalKey, KeyTypePrincipal).
|
||||
Get(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -12,11 +12,13 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
"github.com/42wim/sshsig"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_SSHParsePublicKey(t *testing.T) {
|
||||
@@ -481,6 +483,20 @@ func TestPublicKeysAreExternallyManaged(t *testing.T) {
|
||||
assert.False(t, externals[0])
|
||||
}
|
||||
|
||||
func TestSearchPrincipalKeyIgnoresOtherKeyTypes(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
userKey := unittest.AssertExistsAndLoadBean(t, &PublicKey{ID: 1})
|
||||
|
||||
_, err := SearchPrincipalKey(t.Context(), userKey.Content)
|
||||
assert.True(t, IsErrKeyNotExist(err))
|
||||
|
||||
principal := &PublicKey{OwnerID: 1, Name: userKey.Content, Content: userKey.Content, Type: KeyTypePrincipal}
|
||||
require.NoError(t, db.Insert(t.Context(), principal))
|
||||
key, err := SearchPrincipalKey(t.Context(), userKey.Content)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, principal.ID, key.ID)
|
||||
}
|
||||
|
||||
// TestCheckPublicKeyStringOversized tests if oversized SSH2 public key strings are rejected before triggering costly operations.
|
||||
func TestCheckPublicKeyStringOversized(t *testing.T) {
|
||||
_, err := parseKeyString(strings.Repeat("a", maxKeyContentBytes+1))
|
||||
|
||||
Reference in new issue
Block a user