fix: address verified review findings (admin-webhooks-keys-1)

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 17:42:51 +02:00
1 parent 0910cf307a
commit b69019fd74
13 files changed
+268 -31

No files matched your search

+13 -1
View File
@@ -5,7 +5,9 @@ package services
import (
"context"
"fmt"
"strconv"
"strings"
gitea "gitea.dev/sdk"
"gitea.dev/tea/internal/transport"
@@ -36,7 +38,8 @@ func (s SSHKeys) List(ctx context.Context, limit, page int) (Page[SSHKey], error
return convertPage(keys, sshKeyFrom), err
}
// View retrieves a public key by ID.
// View retrieves a public key of the account by ID. Gitea also answers for other accounts' keys
// and lets administrators delete them, so a key that belongs to someone else is refused.
func (s SSHKeys) View(ctx context.Context, id int64) (SSHKey, error) {
key, _, err := call(ctx, s.Client, func(ctx context.Context, c *gitea.Client) (*gitea.PublicKey, *gitea.Response, error) {
return c.Users.GetPublicKey(ctx, id)
@@ -44,6 +47,15 @@ func (s SSHKeys) View(ctx context.Context, id int64) (SSHKey, error) {
if err != nil {
return SSHKey{}, Classify(err, "SSH key", strconv.FormatInt(id, 10), "")
}
if key.Owner != nil {
account, err := CurrentAccount(ctx, s.Client)
if err != nil {
return SSHKey{}, err
}
if owner := login(key.Owner); !strings.EqualFold(owner, account) {
return SSHKey{}, fmt.Errorf("SSH key %d belongs to %s, not to %s", id, owner, account)
}
}
return sshKeyFrom(key), nil
}