Skip to content

Commit df48aa9

Browse files
Merge pull request #1309: exclude PaginationRequest.maxLimit from client json binding
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 parents 4b2a126 + 6d13bf8 commit df48aa9

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎modules/json/src/org/apache/axis2/json/rpc/PaginationRequest.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ public class PaginationRequest {
7171
* Server-enforced ceiling on limit. Prevents clients from requesting
7272
* unbounded result sets (e.g. limit=999999) that could exhaust heap.
7373
* Services can lower this per-operation via {@link #setMaxLimit(int)}.
74+
* Transient so the reflective JSON binding (Gson, Moshi) never populates
75+
* it from the request body alongside offset and limit; only service code
76+
* can change the cap.
7477
*/
75-
private int maxLimit = DEFAULT_MAX_LIMIT;
78+
private transient int maxLimit = DEFAULT_MAX_LIMIT;
7679

7780
public PaginationRequest() {
7881
this.offset = 0;

‎modules/json/test/org/apache/axis2/json/rpc/PaginatedResponseTest.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,27 @@ public void testRequest_constructorNegativeOffset() {
183183
assertEquals(0, req.getOffset());
184184
}
185185

186+
@Test
187+
public void testRequest_gsonBindingCannotRaiseMaxLimit() {
188+
// maxLimit is a server-side control: a request body that names it must
189+
// not be able to raise its own cap. Gson binds private fields by name,
190+
// so the field has to stay invisible to the wire format.
191+
PaginationRequest req = new com.google.gson.Gson().fromJson(
192+
"{\"offset\":0,\"limit\":999999,\"maxLimit\":999999}",
193+
PaginationRequest.class);
194+
assertEquals(PaginationRequest.DEFAULT_MAX_LIMIT, req.getMaxLimit());
195+
assertEquals(PaginationRequest.DEFAULT_MAX_LIMIT, req.getLimit());
196+
}
197+
198+
@Test
199+
public void testRequest_moshiBindingCannotRaiseMaxLimit() throws Exception {
200+
PaginationRequest req = new com.squareup.moshi.Moshi.Builder().build()
201+
.adapter(PaginationRequest.class)
202+
.fromJson("{\"offset\":0,\"limit\":999999,\"maxLimit\":999999}");
203+
assertEquals(PaginationRequest.DEFAULT_MAX_LIMIT, req.getMaxLimit());
204+
assertEquals(PaginationRequest.DEFAULT_MAX_LIMIT, req.getLimit());
205+
}
206+
186207
// ═══════════════════════════════════════════════════════════════════════
187208
// Integration: request → response round-trip
188209
// ═══════════════════════════════════════════════════════════════════════

0 commit comments

Comments
 (0)