Skip to content

Commit 870da2f

Browse files
committed
Decouple requestBodyProcessed and requestFilesFilenames callbacks in Undertow
Both callbacks are now fetched upfront; the method only returns early when both are null. Previously an early return on requestBodyProcessed==null silently skipped filename detection, breaking deployments with filename-only WAF rules.
1 parent f340ebf commit 870da2f

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

dd-java-agent/instrumentation/undertow/undertow-2.0/src/main/java/datadog/trace/instrumentation/undertow/MultiPartUploadHandlerInstrumentation.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,35 @@ static void after(
8383
}
8484

8585
CallbackProvider cbp = AgentTracer.get().getCallbackProvider(RequestContextSlot.APPSEC);
86-
BiFunction<RequestContext, Object, Flow<Void>> callback =
86+
BiFunction<RequestContext, Object, Flow<Void>> bodyCallback =
8787
cbp.getCallback(EVENTS.requestBodyProcessed());
88-
if (callback == null) {
88+
BiFunction<RequestContext, List<String>, Flow<Void>> filenamesCb =
89+
cbp.getCallback(EVENTS.requestFilesFilenames());
90+
if (bodyCallback == null && filenamesCb == null) {
8991
return;
9092
}
9193
FormData attachment = exchange.getAttachment(FORM_DATA);
9294
if (attachment == null) {
9395
return;
9496
}
9597

96-
Flow<Void> flow = callback.apply(reqCtx, new FormDataMap(attachment));
97-
Flow.Action action = flow.getAction();
98-
if (action instanceof Flow.Action.RequestBlockingAction) {
99-
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
100-
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction();
101-
if (blockResponseFunction != null) {
102-
blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba);
103-
if (t == null) {
104-
t = new BlockingException("Blocked request (for MultiPartUploadHandler/parseBlocking)");
98+
if (bodyCallback != null) {
99+
Flow<Void> flow = bodyCallback.apply(reqCtx, new FormDataMap(attachment));
100+
Flow.Action action = flow.getAction();
101+
if (action instanceof Flow.Action.RequestBlockingAction) {
102+
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
103+
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction();
104+
if (blockResponseFunction != null) {
105+
blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba);
106+
if (t == null) {
107+
t =
108+
new BlockingException(
109+
"Blocked request (for MultiPartUploadHandler/parseBlocking)");
110+
}
105111
}
106112
}
107113
}
108114

109-
BiFunction<RequestContext, List<String>, Flow<Void>> filenamesCb =
110-
cbp.getCallback(EVENTS.requestFilesFilenames());
111115
if (filenamesCb != null) {
112116
List<String> filenames = new ArrayList<>();
113117
for (String key : attachment) {

0 commit comments

Comments
 (0)