diff --git a/config.example.py b/config.example.py index 20002f9..a4c8025 100644 --- a/config.example.py +++ b/config.example.py @@ -149,6 +149,9 @@ BACKUP_TORRENT_FOLDER = 'torrents' # How many results should a page contain. Applies to RSS as well. RESULTS_PER_PAGE = 75 +# How many pages we'll return at most +MAX_PAGES = 100 + # Use better searching with ElasticSearch # See README.MD on setup! USE_ELASTIC_SEARCH = False diff --git a/nyaa/search.py b/nyaa/search.py index d1a5282..3e04613 100644 --- a/nyaa/search.py +++ b/nyaa/search.py @@ -372,6 +372,12 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0', if page > 4294967295: flask.abort(404) + MAX_PAGES = app.config.get("MAX_PAGES", 0) + + if MAX_PAGES and page > MAX_PAGES: + flask.abort(flask.Response("You've exceeded the maximum number of pages. Please " + "make your search query less broad.", 403)) + sort_keys = { 'id': models.Torrent.id, 'size': models.Torrent.filesize, @@ -518,6 +524,7 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0', if rss: query = query.limit(per_page) else: - query = query.paginate_faste(page, per_page=per_page, step=5, count_query=count_query) + query = query.paginate_faste(page, per_page=per_page, step=5, count_query=count_query, + max_page=MAX_PAGES) return query