Skip to content

fix: add pagination to /rest/v1/root_cres and cap per_page on list endpoints#849

Open
shiwani42 wants to merge 1 commit intoOWASP:mainfrom
shiwani42:fix/unbounded-api-responses
Open

fix: add pagination to /rest/v1/root_cres and cap per_page on list endpoints#849
shiwani42 wants to merge 1 commit intoOWASP:mainfrom
shiwani42:fix/unbounded-api-responses

Conversation

@shiwani42
Copy link
Copy Markdown

Fixes #847

What changed

/rest/v1/root_cres

Added get_root_cres_with_pagination(page, per_page) to db.py using SQLAlchemy's .paginate(). The endpoint now accepts page and per_page query params and returns page and total_pages alongside data in the JSON response, consistent with /rest/v1/all_cres.

Format-based responses (Markdown, CSV, OSCAL) are intentional full-export flows and remain unpaginated.

/rest/v1/all_cres

Added MAX_PER_PAGE = 100 constant. per_page is now capped at MAX_PER_PAGE on both list endpoints, preventing a single request from fetching the entire dataset.

Tests

  • Added test_get_root_cres_with_pagination in db_test.py
  • Updated test_find_root_cres in web_main_test.py to reflect the new response shape
  • Added test_root_cres_per_page_cap and test_all_cres_per_page_cap in web_main_test.py

…dpoints

/rest/v1/root_cres had no pagination, returning all root CREs in a
single unbounded query. Add get_root_cres_with_pagination() in db.py
and update the endpoint to accept page/per_page params, returning
page and total_pages metadata alongside data.

/rest/v1/all_cres already supported pagination but accepted any
positive integer for per_page, allowing a single request to fetch
the entire dataset. Introduce MAX_PER_PAGE = 100 and cap per_page
on both list endpoints.

Format-based responses (Markdown, CSV, OSCAL) on root_cres are
intentional full-export flows and are not paginated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unbounded API responses on /rest/v1/root_cres and /rest/v1/all_cres

1 participant