Skip to content

Commit

Permalink
Detect Undertow RequestTooBigException message in handleParseFailure
Browse files Browse the repository at this point in the history
Closes gh-32549
  • Loading branch information
jhoeller committed Apr 5, 2024
1 parent 47c9c7e commit 0747275
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -118,7 +118,8 @@ protected void handleParseFailure(Throwable ex) {
String msg = cause.getMessage();
if (msg != null) {
msg = msg.toLowerCase();
if (msg.contains("exceed") && (msg.contains("size") || msg.contains("length"))) {
if ((msg.contains("exceed") && (msg.contains("size") || msg.contains("length"))) ||
(msg.contains("request") && (msg.contains("big") || msg.contains("large")))) {
throw new MaxUploadSizeExceededException(-1, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ void jetty12MaxLengthExceededException() {
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
}

@Test // gh-32549
void undertowRequestTooBigException() {
IOException ex = new IOException("Connection terminated as request was larger than 10000");

assertThatExceptionOfType(MaxUploadSizeExceededException.class)
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
}


private static StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) {
MockHttpServletRequest request = new MockHttpServletRequest();
Expand All @@ -142,4 +150,14 @@ public Collection<Part> getParts() throws ServletException {
return new StandardMultipartHttpServletRequest(request);
}

private static StandardMultipartHttpServletRequest requestWithException(IOException ex) {
MockHttpServletRequest request = new MockHttpServletRequest() {
@Override
public Collection<Part> getParts() throws IOException {
throw ex;
}
};
return new StandardMultipartHttpServletRequest(request);
}

}

0 comments on commit 0747275

Please sign in to comment.