Cursor Pagination (fromId) & NoSQL Injection Fix
Version: 1.6.0 Date: 2026-03-04
Goal: Fix broken cursor-based pagination and close a NoSQL injection vulnerability in the query filter middleware.
Solution: Rewrite filterEntitiesFromId with proper ObjectId-based sorting and comparison, add limit support. Harden createFilterEntities with key whitelisting and operator sanitization.
Features:
- Cursor pagination now sorts by
_idand compares IDs directly (no more reliance oncreatedfield) - New
?limit=Nquery parameter for pagination - No more silent empty response when
fromIddoesn't match - Query filter restricted to whitelisted keys only
- MongoDB operators (
$ne,$where, etc.) stripped from filter values
Implementation Details:
filterEntitiesFromId: sort by_id, direct string comparison on ObjectId,limitviaslicecreateFilterEntities:ALLOWED_FILTER_KEYSwhitelist,sanitizeValue()strips$-prefixed keys, rejects unrecognized value shapes
Files Modified:
app/middleware/filterEntitiesFromId.js- Rewritten pagination logic with sort, fromId comparison, limitapp/middleware/createFilterEntities.js- Added whitelist and sanitization against NoSQL injection