Skip to content

Commit dbeea34

Browse files
update repo service to check that GroupID is owned by the repo owner when creating a new repository
1 parent 2914cd5 commit dbeea34

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

services/repository/create.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package repository
55

66
import (
77
"bytes"
8+
group_model "code.gitea.io/gitea/models/group"
89
"context"
910
"fmt"
1011
"os"
@@ -228,6 +229,24 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
228229
if opts.ObjectFormatName == "" {
229230
opts.ObjectFormatName = git.Sha1ObjectFormat.Name()
230231
}
232+
if opts.GroupID < 0 {
233+
opts.GroupID = 0
234+
}
235+
236+
// ensure that the parent group is owned by same user
237+
if opts.GroupID > 0 {
238+
newGroup, err := group_model.GetGroupByID(ctx, opts.GroupID)
239+
if err != nil {
240+
if group_model.IsErrGroupNotExist(err) {
241+
opts.GroupID = 0
242+
} else {
243+
return nil, err
244+
}
245+
}
246+
if newGroup.OwnerID != owner.ID {
247+
return nil, fmt.Errorf("group[%d] is not owned by user[%d]", newGroup.ID, owner.ID)
248+
}
249+
}
231250

232251
repo := &repo_model.Repository{
233252
OwnerID: owner.ID,

0 commit comments

Comments
 (0)