From f563bd4ff1d5740c8ce4fef38453cd1b9c8b7c82 Mon Sep 17 00:00:00 2001 From: gotjoshua Date: Mon, 12 Apr 2021 12:51:56 +0100 Subject: [PATCH] RPC: don't cap page size in unsafe mode (#6329) --- CHANGELOG_PENDING.md | 1 + rpc/core/env.go | 4 +++- rpc/core/env_test.go | 22 ++++++++++++++-------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 1e5e0df8e..308197613 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -52,6 +52,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi ### FEATURES - [config] Add `--mode` flag and config variable. See [ADR-52](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-052-tendermint-mode.md) @dongsam +- [rpc] /#6329 Don't cap page size in unsafe mode (@gotjoshua, @cmwaters) ### IMPROVEMENTS diff --git a/rpc/core/env.go b/rpc/core/env.go index aa9ce4ba4..019c74d10 100644 --- a/rpc/core/env.go +++ b/rpc/core/env.go @@ -126,7 +126,9 @@ func validatePerPage(perPagePtr *int) int { perPage := *perPagePtr if perPage < 1 { return defaultPerPage - } else if perPage > maxPerPage { + // in unsafe mode there is no max on the page size but in safe mode + // we cap it to maxPerPage + } else if perPage > maxPerPage && !env.Config.Unsafe { return maxPerPage } return perPage diff --git a/rpc/core/env_test.go b/rpc/core/env_test.go index b44c21a4c..1c3b221c4 100644 --- a/rpc/core/env_test.go +++ b/rpc/core/env_test.go @@ -58,17 +58,16 @@ func TestPaginationPage(t *testing.T) { func TestPaginationPerPage(t *testing.T) { cases := []struct { - totalCount int perPage int newPerPage int }{ - {5, 0, defaultPerPage}, - {5, 1, 1}, - {5, 2, 2}, - {5, defaultPerPage, defaultPerPage}, - {5, maxPerPage - 1, maxPerPage - 1}, - {5, maxPerPage, maxPerPage}, - {5, maxPerPage + 1, maxPerPage}, + {0, defaultPerPage}, + {1, 1}, + {2, 2}, + {defaultPerPage, defaultPerPage}, + {maxPerPage - 1, maxPerPage - 1}, + {maxPerPage, maxPerPage}, + {maxPerPage + 1, maxPerPage}, } for _, c := range cases { @@ -79,4 +78,11 @@ func TestPaginationPerPage(t *testing.T) { // nil case p := validatePerPage(nil) assert.Equal(t, defaultPerPage, p) + + // test in unsafe mode + env.Config.Unsafe = true + perPage := 1000 + p = validatePerPage(&perPage) + assert.Equal(t, perPage, p) + env.Config.Unsafe = false }