Skip to content

Commit fbbff63

Browse files
committed
fix(storage): clamp non-positive entry query limits to the maximum
WithLimit ignored a zero limit, so /v1/entries?limit=0 produced a query without a SQL LIMIT and returned every matching entry, bypassing the 1000-entry cap. The official API client sends limit=0 for any filter with an unset Limit field, making unbounded queries easy to trigger. Clamp non-positive values to the maximum in both WithLimit and WithLimitAndMaximum so every caller (REST API, Google Reader) stays bounded, as intended by 0909323.
1 parent c342187 commit fbbff63

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

internal/storage/entry_query_builder.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,19 @@ func (e *EntryQueryBuilder) WithSorting(column, direction string) *EntryQueryBui
199199
return e
200200
}
201201

202-
// WithLimit set the limit.
202+
// WithLimit sets the limit. A non-positive limit is clamped to
203+
// model.MaxEntryLimit so callers cannot request an unbounded result set.
203204
func (e *EntryQueryBuilder) WithLimit(limit int) *EntryQueryBuilder {
204-
if limit > 0 {
205-
e.limit = min(limit, model.MaxEntryLimit)
206-
}
207-
return e
205+
return e.WithLimitAndMaximum(limit, model.MaxEntryLimit)
208206
}
209207

210208
// WithLimitAndMaximum sets the limit, capped at the given maximum.
209+
// A non-positive limit is clamped to the maximum.
211210
func (e *EntryQueryBuilder) WithLimitAndMaximum(limit, maximum int) *EntryQueryBuilder {
212-
if limit > 0 {
213-
e.limit = min(limit, maximum)
211+
if limit <= 0 || limit > maximum {
212+
limit = maximum
214213
}
214+
e.limit = limit
215215
return e
216216
}
217217

0 commit comments

Comments
 (0)