Skip to content

Commit b1ffeb4

Browse files
authored
[ANCHOR-1185] Add XDR size validation in SEP-10 and SEP-45 auth endpoint (#1917)
### Description - Add 50KB size limit on `transaction` field in SEP-10 POST `/auth` before XDR parsing - Reduce existing SEP-45 `authorization_entries` size limit from 100KB to 50KB ### Context Valid SEP-10/SEP-45 auth payloads are small (a few KB). Limiting input size before XDR deserialization prevents unnecessary memory allocation from oversized payloads. ### Testing - `./gradlew test` ### Documentation N/A ### Known limitations N/A
1 parent f4d63f9 commit b1ffeb4

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

core/src/main/java/org/stellar/anchor/sep10/Sep10Service.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,14 @@ String fetchClientDomain(ChallengeTransaction challenge) {
511511

512512
ChallengeTransaction parseChallenge(ValidationRequest request) throws SepValidationException {
513513

514-
if (request == null || request.getTransaction() == null) {
514+
if (request == null || isEmpty(request.getTransaction())) {
515515
throw new SepValidationException("{transaction} is required.");
516516
}
517517

518+
if (request.getTransaction().length() > 50_000) {
519+
throw new SepValidationException("transaction exceeds maximum allowed size");
520+
}
521+
518522
String transaction = request.getTransaction();
519523
Network network = new Network(stellarNetworkConfig.getStellarNetworkPassphrase());
520524
String homeDomain = extractHomeDomainFromChallengeXdr(transaction, network);

core/src/main/java/org/stellar/anchor/sep45/Sep45Service.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public ValidationResponse validate(ValidationRequest request) throws AnchorExcep
180180
throw new BadRequestException("authorization_entries is required");
181181
}
182182

183-
if (request.getAuthorizationEntries().length() > 100_000) {
183+
if (request.getAuthorizationEntries().length() > 50_000) {
184184
throw new BadRequestException("authorization_entries exceeds maximum allowed size");
185185
}
186186

core/src/test/kotlin/org/stellar/anchor/sep10/Sep10ServiceTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ internal class Sep10ServiceTest {
280280
assertThrows<SepValidationException> { sep10Service.validateChallenge(vr) }
281281
}
282282

283+
@Test
284+
fun `Test validate challenge rejects oversized transaction`() {
285+
val vr = ValidationRequest()
286+
vr.transaction = "A".repeat(50_001)
287+
val ex = assertThrows<SepValidationException> { sep10Service.validateChallenge(vr) }
288+
assertEquals("transaction exceeds maximum allowed size", ex.message)
289+
}
290+
283291
@Test
284292
@LockAndMockStatic([Sep10Challenge::class])
285293
fun `Test validate challenge with bad home domain failure`() {

core/src/test/kotlin/org/stellar/anchor/sep45/Sep45ServiceTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ class Sep45ServiceTest {
192192
assertEquals("authorization_entries is required", ex.message)
193193
}
194194

195+
@Test
196+
fun `test validate throws BadRequestException when auth entries exceed max size`() {
197+
val validationRequest =
198+
ValidationRequest.builder().authorizationEntries("A".repeat(50_001)).build()
199+
200+
val ex =
201+
assertThrows(BadRequestException::class.java) { sep45Service.validate(validationRequest) }
202+
assertEquals("authorization_entries exceeds maximum allowed size", ex.message)
203+
}
204+
195205
@Test
196206
fun `test validate throws BadRequestException when auth entries list empty`() {
197207
val emptyAuth = SorobanAuthorizationEntries(arrayOf())

0 commit comments

Comments
 (0)