Skip to content

Commit 19ae772

Browse files
committed
fix(appsec/jetty): cover Jetty 10.0.0-10.0.9 and close PartHelper InputStream
- jetty-appsec-9.4: extend muzzle to also cover Jetty 10.0.0–10.0.9, which were previously a gap. In those versions _multiParts is typed MultiPartFormInputStream (not MultiParts); the primary Reference spec matches 9.4.10+ and 10.0.10+, and an OrReference alternative matches 10.0.0–10.0.9. The GetFilenamesAdvice already uses typing=DYNAMIC so no advice changes are needed. - jetty-appsec-8.1.3 PartHelper: wrap part.getInputStream() in try-with-resources to avoid leaking file descriptors on file-backed multipart form fields.
1 parent e43466f commit 19ae772

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

dd-java-agent/instrumentation/jetty/jetty-appsec/jetty-appsec-8.1.3/src/main/java/datadog/trace/instrumentation/jetty8/PartHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ static String filenameFromPart(Part part) {
9494
}
9595

9696
private static String readPartContent(Part part) {
97-
try {
98-
InputStream is = part.getInputStream();
97+
try (InputStream is = part.getInputStream()) {
9998
ByteArrayOutputStream baos = new ByteArrayOutputStream();
10099
byte[] buf = new byte[4096];
101100
int read;

dd-java-agent/instrumentation/jetty/jetty-appsec/jetty-appsec-9.4/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ muzzle {
55
module = 'jetty-server'
66
versions = '[9.4.10,10.0)'
77
}
8+
pass {
9+
name = 'early_10_series'
10+
group = 'org.eclipse.jetty'
11+
module = 'jetty-server'
12+
// _multiParts: MultiPartFormInputStream (before 10.0.10 switched to MultiParts)
13+
versions = '[10.0.0,10.0.10)'
14+
javaVersion = 11
15+
}
816
pass {
917
name = '10_series'
1018
group = 'org.eclipse.jetty'

dd-java-agent/instrumentation/jetty/jetty-appsec/jetty-appsec-9.4/src/main/java/datadog/trace/instrumentation/jetty94/RequestExtractContentParametersInstrumentation.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ public void methodAdvice(MethodTransformer transformer) {
5858
getClass().getName() + "$GetFilenamesFromMultiPartAdvice");
5959
}
6060

61-
// Discriminates Jetty [9.4.10, 10.0) and [10.0.10, 11.0):
61+
// Discriminates Jetty [9.4.10, 10.0) + [10.0.0, 11.0):
6262
// - _contentParameters + extractContentParameters(void) exist from 9.3+ (excludes 9.2)
63-
// - _multiParts: MultiParts exists in 9.4.10+ and 10.0.10+ (excludes early 9.4.x covered by
64-
// jetty-appsec-9.3, and excludes 10.0.0–10.0.9 where _multiParts is MultiPartFormInputStream)
63+
// - _multiParts field exists from 9.4.10+ (excludes 9.3.x–9.4.9 covered by jetty-appsec-9.3)
64+
// - primary spec: _multiParts: MultiParts → matches 9.4.10–9.4.x and 10.0.10+
65+
// - OR spec: _multiParts: MultiPartFormInputStream → matches 10.0.0–10.0.9
6566
// - _dispatcherType: Ljavax/servlet/DispatcherType; in the Request bytecode (excludes Jetty 11+
6667
// where the field descriptor is Ljakarta/servlet/DispatcherType;). This check is tied to the
6768
// Request.class bytecode, NOT just classpath presence, so it works even when both
@@ -73,6 +74,15 @@ public void methodAdvice(MethodTransformer transformer) {
7374
.withField(new String[0], 0, "_contentParameters", MULTI_MAP_INTERNAL_NAME)
7475
.withField(new String[0], 0, "_multiParts", "Lorg/eclipse/jetty/server/MultiParts;")
7576
.withField(new String[0], 0, "_dispatcherType", "Ljavax/servlet/DispatcherType;")
77+
.or()
78+
.withMethod(new String[0], 0, "extractContentParameters", "V")
79+
.withField(new String[0], 0, "_contentParameters", MULTI_MAP_INTERNAL_NAME)
80+
.withField(
81+
new String[0],
82+
0,
83+
"_multiParts",
84+
"Lorg/eclipse/jetty/server/MultiPartFormInputStream;")
85+
.withField(new String[0], 0, "_dispatcherType", "Ljavax/servlet/DispatcherType;")
7686
.build();
7787

7888
@Override

0 commit comments

Comments
 (0)