fix(referrer): apply default page size when request has no pagination#3023
Draft
waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
Draft
fix(referrer): apply default page size when request has no pagination#3023waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
Conversation
The ReferrerService.DiscoverPrivate and DiscoverPublicShared endpoints were unbounded when clients sent an empty request. The helper referrerPaginationOptsFromProto returned (nil, nil) for a nil pagination field, and the data layer interpreted nil CursorOptions as "return every reference". A container image that had been attested many times would accumulate hundreds of SBOMs/SARIF referrers, all returned in a single response. Apply the existing defaultReferrerPageSize (20) whenever no pagination is supplied or the limit is zero. Clients that already send pagination are unaffected. The CLI already sends a non-nil pagination request with a default limit of 20, so no client-side change is needed. Fixes: chainloop-dev#2890 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2890.
The
ReferrerService.DiscoverPrivateandDiscoverPublicSharedendpoints return an unbounded number of direct references (SBOMs, SARIF reports, …) when a client sends an empty pagination field. A container image that is attested repeatedly accumulates these references over time, so a single call can return hundreds of items.Root cause
referrerPaginationOptsFromProtoinapp/controlplane/internal/service/referrer.goreturned(nil, nil)whenever the request's pagination was nil, and the data layer treatednil *CursorOptionsas "skip pagination entirely":```go
// app/controlplane/pkg/data/referrer.go (unchanged)
if p != nil {
q = q.Limit(p.Limit + 1)
// …
}
```
This was intentional "backward compatibility" per the helper's comment, but it is the bug the issue describes.
Fix
Always return
*pagination.CursorOptionswith the existingdefaultReferrerPageSize = 20:Limit: 0→ default page sizeLimit: N→ honored as-is (still capped at 100 by the proto validation rule)The biz-layer traversal is still bounded by
maxTraverseLevels = 1(app/controlplane/pkg/data/referrer.go:196), so level-0 refs are now bounded and nothing deeper needs a change.Client impact
app/cli/cmd/referrer_discover.goalready sends a non-nil pagination request withDefaultLimit: 20.pagination.limitexplicitly (up to 100) or page through withpagination.cursor. This is a behavior change but it is the fix the issue asks for.Test plan
go test ./internal/service/... -run TestReferrerPaginationOptsFromProto -v— 5 subtests covering nil / empty / zero / explicit / boundary limitgo test ./internal/service/...— full service package passesgo vet ./internal/service/...cleangofmt -lclean