Skip to content

Commit

Permalink
Make sure limit and offset parameters are non-negative
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed May 3, 2022
1 parent 458b3c5 commit 951e56d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,15 @@ const addMiddlewareProperties = (req, res, next) => {
// Limit for pagination
const defaultLimit = 100
req.query.limit = parseInt(req.query.limit)
req.query.limit = req.query.limit || defaultLimit // Math.min(defaultLimit, req.query.limit || defaultLimit)
if (isNaN(req.query.limit) || req.query.limit < 0) {
req.query.limit = defaultLimit
}
// Offset for pagination
const defaultOffset = 0
req.query.offset = parseInt(req.query.offset)
req.query.offset = req.query.offset || defaultOffset
if (isNaN(req.query.offset) || req.query.offset < 0) {
req.query.offset = defaultOffset
}
// Bulk option for POST endpoints
req.query.bulk = req.query.bulk === "true" || req.query.bulk === "1"
}
Expand Down

0 comments on commit 951e56d

Please sign in to comment.