Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/com/stripe/mpp/Challenge.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public static List<Challenge> fromWwwAuthenticate(List<String> wwwAuthenticateHe
if (authParams == null) continue;

Map<String, String> params = Parsing.parseAuthParams(authParams);
String request = params.get("request");
if (request != null && request.length() > Parsing.MAX_PAYLOAD_SIZE) {
throw new com.stripe.mpp.error.ParseException(
"Request parameter exceeds maximum length of " + Parsing.MAX_PAYLOAD_SIZE + " bytes"
);
}
Map<String, Object> opaque = null;
String opaqueVal = params.get("opaque");
if (opaqueVal != null && !opaqueVal.isEmpty()) {
Expand All @@ -103,7 +109,7 @@ public static List<Challenge> fromWwwAuthenticate(List<String> wwwAuthenticateHe
params.get("intent"),
null,
params.get("realm"),
params.get("request"),
request,
params.get("digest"),
params.get("expires"),
params.get("description"),
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/stripe/mpp/ParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ void challengeRejectsCrlfDescription() {
.hasMessageContaining("CR or LF");
}

@Test
void challengeRejectsOversizedRequestParameter() {
String oversizedRequest = "a".repeat(Parsing.MAX_PAYLOAD_SIZE + 1);
String header = "Payment id=\"abc\", realm=\"api\", method=\"tempo\", intent=\"charge\", request=\""
+ oversizedRequest
+ "\"";

assertThatThrownBy(() -> Challenge.fromWwwAuthenticate(header))
.isInstanceOf(com.stripe.mpp.error.ParseException.class)
.hasMessageContaining("Request parameter exceeds");
}

// --- Credential (Authorization) ---

@Test
Expand Down
Loading