I was watching the Firebase doc videos and noticed that in this video: https://www.youtube.com/watch?v=9sOT5VOflvQ&list=PLl-K7zZEsYLn8h1NyU_OV6dX8mBhH2s_L&index=4
at 6:39, Doug mentions that it is possible to limit the amount of document returned by one query, by doing something like:
allow list if: request.query.limit <= 20
However, he mentions that, although this is beneficial because it prevents you from accidentally executing a very costly set of reads, it still won't prevent malicious users from reading everything in your database by making multiple requests and using pagination to sift through your database. I could envision some sort of infinite while loop in JavaScript that makes this very problematic and costly.
The only way that I could think to solve this problem is by somehow using timestamps perhaps, and saving some information associated with each user which informs the database of when they last made a request. Would it be possible to do this and then access those timestamps in the security rules? Something along the lines of (where the second condition is kind of pseudo-code):
allow list if: request.query.limit <= 20 && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.last-time <= 100
This seems to me the most feasible way but if anyone else has thoughts on this, they would be much appreciated!