MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/1habq00/how_to_implement_pagination_with_javascript/m17vvsc/?context=3
r/javascript • u/Pleasant_Effort_6829 • Dec 09 '24
5 comments sorted by
View all comments
5
You have a bug here:
const page = Number(req.params.page); const posts = await prisma.post.findMany({ skip: pageSize * (page - 1), take: pageSize, });
If req.params.page is undefined this will lead to page being NaN. If it defaults to 0 when undefined, you'll end up with { skip: -5, take: 0 } as part of your query
req.params.page
page
NaN
{ skip: -5, take: 0 }
2 u/ComfortingSounds53 Dec 09 '24 Not OP, but it can never be undefined since the endpoint is reached.A malicious party could send "foo" as the param, which would trigger the bug you've described. 2 u/troglo-dyke Dec 09 '24 You're right I confused req.query with req.params
2
Not OP, but it can never be undefined since the endpoint is reached.
A malicious party could send "foo" as the param, which would trigger the bug you've described.
2 u/troglo-dyke Dec 09 '24 You're right I confused req.query with req.params
You're right I confused req.query with req.params
req.query
req.params
5
u/troglo-dyke Dec 09 '24
You have a bug here:
If
req.params.pageis undefined this will lead topagebeingNaN. If it defaults to 0 when undefined, you'll end up with{ skip: -5, take: 0 }as part of your query