Description
The limit query parameter validation in ValidateParameters / validatePagination only checks limit > maxPaginationLimit but does not reject limit <= 0. When limit=0 is passed:
strconv.Atoi("0") returns 0
0 > 100 is false → validation passes
- MongoDB's
SetLimit(0) means "no limit" → returns all documents
- API responds 200 with all results instead of 400
Similarly, negative values like limit=-1 and page=0 or page=-1 pass validation.
Affected Endpoints
This is in the shared pkg/net/http/httputils.go validatePagination function, so it affects all list endpoints across Ledger and CRM.
Location
pkg/net/http/httputils.go, function validatePagination (line ~330)
Expected Behavior
limit <= 0 → HTTP 400 with structured error
page <= 0 → HTTP 400 with structured error
Suggested Fix
Add a lower bound check in validatePagination:
if limit <= 0 {
return "", pkg.ValidateBusinessError(constant.ErrInvalidQueryParameter, "", "limit")
}
And add page validation (currently not validated at all):
// in ValidateParameters, after the for loop:
if page <= 0 {
return nil, pkg.ValidateBusinessError(constant.ErrInvalidQueryParameter, "", "page")
}
Description
The
limitquery parameter validation inValidateParameters/validatePaginationonly checkslimit > maxPaginationLimitbut does not rejectlimit <= 0. Whenlimit=0is passed:strconv.Atoi("0")returns 00 > 100is false → validation passesSetLimit(0)means "no limit" → returns all documentsSimilarly, negative values like
limit=-1andpage=0orpage=-1pass validation.Affected Endpoints
This is in the shared
pkg/net/http/httputils.govalidatePaginationfunction, so it affects all list endpoints across Ledger and CRM.Location
pkg/net/http/httputils.go, functionvalidatePagination(line ~330)Expected Behavior
limit <= 0→ HTTP 400 with structured errorpage <= 0→ HTTP 400 with structured errorSuggested Fix
Add a lower bound check in
validatePagination:And add
pagevalidation (currently not validated at all):