Skip to content

Commit ae5c8e3

Browse files
authored
Issue #7617 - RequestLog content params extraction prevention (#7618)
1 parent cab9945 commit ae5c8e3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

jetty-server/src/main/java/org/eclipse/jetty/server/Request.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,10 @@ public void onCompleted()
14351435
RequestLog requestLog = httpChannel.getRequestLog();
14361436
if (requestLog != null)
14371437
{
1438-
// Don't allow pulling more parameters
1438+
// Don't allow pulling more parameters from request body content
14391439
_contentParamsExtracted = true;
1440+
if (_contentParameters == null)
1441+
_contentParameters = NO_PARAMS;
14401442

14411443
// Reset the status code to what was committed
14421444
MetaData.Response committedResponse = getResponse().getCommittedMetaData();

jetty-server/src/test/java/org/eclipse/jetty/server/RequestLogTest.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.eclipse.jetty.util.component.LifeCycle;
3535
import org.junit.jupiter.api.Disabled;
3636
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.params.ParameterizedTest;
38+
import org.junit.jupiter.params.provider.ValueSource;
3739
import org.slf4j.Logger;
3840
import org.slf4j.LoggerFactory;
3941

@@ -145,8 +147,9 @@ public void testNormalGetRequest() throws Exception
145147
* Test an unread HTTP/1.1 POST, it has valid body content, the dispatched Handler on the server doesn't read the POST body content.
146148
* The RequestLog accidentally attempts to read the Request body content due to the use of Request.getParameterNames() API.
147149
*/
148-
@Test
149-
public void testNormalPostFormRequest() throws Exception
150+
@ParameterizedTest
151+
@ValueSource(strings = {"/hello", "/hello?a=b"})
152+
public void testNormalPostFormRequest(String requestPath) throws Exception
150153
{
151154
Server server = null;
152155
try
@@ -179,7 +182,7 @@ public void testNormalPostFormRequest() throws Exception
179182
byte[] bufForm = form.toString().getBytes(UTF_8);
180183

181184
StringBuilder req = new StringBuilder();
182-
req.append("POST /hello HTTP/1.1\r\n");
185+
req.append("POST ").append(requestPath).append(" HTTP/1.1\r\n");
183186
req.append("Host: ").append(baseURI.getRawAuthority()).append("\r\n");
184187
req.append("Content-Type: ").append(MimeTypes.Type.FORM_ENCODED).append("\r\n");
185188
req.append("Content-Length: ").append(bufForm.length).append("\r\n");
@@ -213,7 +216,10 @@ public void testNormalPostFormRequest() throws Exception
213216
assertThat("Body Content", bodyContent, containsString("Got POST to /hello"));
214217

215218
String reqlog = requestLogLines.poll(5, TimeUnit.SECONDS);
216-
assertThat("RequestLog", reqlog, containsString("method:POST|uri:/hello|paramNames.size:0|status:200"));
219+
int querySize = 0;
220+
if (requestPath.contains("?"))
221+
querySize = 1; // assuming that parameterized version only has 1 query value
222+
assertThat("RequestLog", reqlog, containsString("method:POST|uri:/hello|paramNames.size:" + querySize + "|status:200"));
217223
}
218224
}
219225
finally

0 commit comments

Comments
 (0)