Skip to content

Commit 83ad20d

Browse files
committed
fix(appsec/jetty8): correct partPeek condition — use == 0 instead of == 1
CallDepthThreadLocalMap.incrementCallDepth() uses post-increment (depth++) so it returns the depth BEFORE the increment. In the normal case (no GetPartAdvice active), Part.class depth is 0 before the peek, making partPeek == 0. The previous guard checked partPeek == 1 which is true only when GetPartAdvice IS already on the stack — exactly backwards. Result: GetFilenamesAdvice never fired for direct getParts() calls, breaking the filenames event on Jetty 8.x. Fix: use partPeek == 0 (proceed when GetPartAdvice is not active) so the condition is: - partPeek == 0: normal direct getParts() → proceed (fire filenames event) - partPeek == 1: getParts() called by getPart() in Jetty 9.0/9.1 → skip (GetPartAdvice handles it)
1 parent af78ea4 commit 83ad20d

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ static boolean before(
127127
final Object multiPartInputStream) {
128128
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(Collection.class);
129129
// _multiPartInputStream is null before the first parse; non-null on cached repeat calls.
130-
// In Jetty 9.0/9.1, getPart(String) delegates to getParts() internally, which would
131-
// trigger this advice and then GetPartAdvice — double-firing the filename event.
132-
// Peek at Part.class depth: if > 1, GetPartAdvice is active and will handle the event.
130+
// In Jetty 9.0/9.1, getPart(String) delegates to getParts() internally, triggering both
131+
// GetPartAdvice and GetFilenamesAdvice — double-firing the filename event.
132+
// incrementCallDepth returns the depth BEFORE incrementing (post-increment semantics).
133+
// If Part.class depth is already 1, GetPartAdvice is active and will handle the event; skip.
133134
int partPeek = CallDepthThreadLocalMap.incrementCallDepth(Part.class);
134135
CallDepthThreadLocalMap.decrementCallDepth(Part.class);
135-
return callDepth == 0 && multiPartInputStream == null && partPeek == 1;
136+
return callDepth == 0 && multiPartInputStream == null && partPeek == 0;
136137
}
137138

138139
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)

0 commit comments

Comments
 (0)