Skip to content

Commit 206a031

Browse files
authored
Ensure that feeds are appropriately restricted (#10018)
* Always limit results by what is accessible to the user * Change signature of AccessibleRepoIDsQuery * Ensure that user with ID <= 0 is handled * Update models/repo_list.go
1 parent 797e6f8 commit 206a031

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

models/action.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
312312
}
313313

314314
cond = cond.And(builder.In("repo_id", repoIDs))
315-
} else if opts.Actor != nil {
316-
cond = cond.And(builder.In("repo_id", opts.Actor.AccessibleRepoIDsQuery()))
315+
} else {
316+
cond = cond.And(builder.In("repo_id", AccessibleRepoIDsQuery(opts.Actor)))
317317
}
318318

319319
cond = cond.And(builder.Eq{"user_id": opts.RequestedUser.ID})

models/repo_list.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
319319
func accessibleRepositoryCondition(user *User) builder.Cond {
320320
var cond = builder.NewCond()
321321

322-
if user == nil || !user.IsRestricted {
322+
if user == nil || !user.IsRestricted || user.ID <= 0 {
323323
orgVisibilityLimit := []structs.VisibleType{structs.VisibleTypePrivate}
324-
if user == nil {
324+
if user == nil || user.ID <= 0 {
325325
orgVisibilityLimit = append(orgVisibilityLimit, structs.VisibleTypeLimited)
326326
}
327327
// 1. Be able to see all non-private repositories that either:
@@ -363,7 +363,8 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
363363
}
364364

365365
// AccessibleRepoIDsQuery queries accessible repository ids. Usable as a subquery wherever repo ids need to be filtered.
366-
func (user *User) AccessibleRepoIDsQuery() *builder.Builder {
366+
func AccessibleRepoIDsQuery(user *User) *builder.Builder {
367+
// NB: Please note this code needs to still work if user is nil
367368
return builder.Select("id").From("repository").Where(accessibleRepositoryCondition(user))
368369
}
369370

0 commit comments

Comments
 (0)