fix(resourceexplorer2): reject invalid pagination tokens (#3444)

This commit is contained in:
Franklin G. Mendoza authored and GitHub committed 2026-09-11 22:37:57 -04:00
1 parent 128d3ef181
commit f482a2d15e
3 files changed
+30 -6

No files matched your search

@@ -999,10 +999,14 @@ public class ResourceExplorer2Service {
return 0;
}
try {
return Integer.parseInt(new String(Base64.getDecoder().decode(token)));
int offset = Integer.parseInt(new String(Base64.getDecoder().decode(token)));
if (offset < 0) {
throw new IllegalArgumentException("negative offset");
}
return offset;
} catch (Exception e) {
LOG.debugf("Invalid NextToken '%s', restarting from offset 0: %s", token, e.getMessage());
return 0;
throw new AwsException("ValidationException",
"NextToken is invalid or has expired.", 400);
}
}
@@ -426,6 +426,19 @@ class ResourceExplorer2IntegrationTest {
.body("Resources.findAll { it.Service == 's3' }.size()", equalTo(0));
}
@Test
void listResourcesInvalidNextTokenReturnsValidationError() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"NextToken\":\"!!!not-base64!!!\"}")
.when()
.post("/ListResources")
.then()
.statusCode(400)
.body("__type", equalTo("ValidationException"));
}
@Test
void listResourcesInvalidFilterReturns400() {
given()
@@ -7,6 +7,7 @@ import java.util.Base64;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Unit tests for the pure pagination math behind ListResources/Search:
@@ -63,9 +64,15 @@ class ResourceExplorer2PaginationTest {
}
@Test
void garbageTokenDecodesToZeroOffset() {
var b = ResourceExplorer2Service.pageBounds(50, 10, "!!!not-base64!!!", CAP);
assertEquals(0, b.start());
void garbageTokenIsRejected() {
assertThrows(io.github.hectorvent.floci.core.common.AwsException.class,
() -> ResourceExplorer2Service.pageBounds(50, 10, "!!!not-base64!!!", CAP));
}
@Test
void negativeTokenOffsetIsRejected() {
assertThrows(io.github.hectorvent.floci.core.common.AwsException.class,
() -> ResourceExplorer2Service.pageBounds(50, 10, token(-1), CAP));
}
@Test