Skip to content

Commit 510b150

Browse files
committed
fix(appsec): do not gate Netty file content callback on requestBodyProcessed subscriber
1 parent 43d9017 commit 510b150

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

dd-java-agent/instrumentation/netty/netty-4.1/src/main/java/datadog/trace/instrumentation/netty41/HttpPostRequestDecoderInstrumentation.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ static void after(
110110
BiFunction<RequestContext, Object, Flow<Void>> callback =
111111
cbp.getCallback(EVENTS.requestBodyProcessed());
112112

113-
if (callback == null) {
113+
BiFunction<RequestContext, List<String>, Flow<Void>> contentCb =
114+
cbp.getCallback(EVENTS.requestFilesContent());
115+
116+
if (callback == null && contentCb == null) {
114117
return;
115118
}
116119

117120
RuntimeException exc = null;
118121

119-
BiFunction<RequestContext, List<String>, Flow<Void>> contentCb =
120-
cbp.getCallback(EVENTS.requestFilesContent());
121-
122122
Map<String, List<String>> attributes = new LinkedHashMap<>();
123123
List<String> filenames = new ArrayList<>();
124124
List<String> filesContent = contentCb != null ? new ArrayList<>() : null;
@@ -147,16 +147,18 @@ static void after(
147147
}
148148
}
149149

150-
Flow<Void> flow = callback.apply(requestContext, attributes);
151-
Flow.Action action = flow.getAction();
152-
if (action instanceof Flow.Action.RequestBlockingAction) {
153-
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
154-
BlockResponseFunction brf = requestContext.getBlockResponseFunction();
155-
if (brf != null) {
156-
brf.tryCommitBlockingResponse(requestContext.getTraceSegment(), rba);
157-
// effectivelyBlocked() is intentionally absent: tryCommitBlockingResponse finishes
158-
// the span synchronously in this Netty path; calling it on a finished span throws.
159-
thr = new BlockingException("Blocked request (multipart/urlencoded post data)");
150+
if (callback != null) {
151+
Flow<Void> flow = callback.apply(requestContext, attributes);
152+
Flow.Action action = flow.getAction();
153+
if (action instanceof Flow.Action.RequestBlockingAction) {
154+
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
155+
BlockResponseFunction brf = requestContext.getBlockResponseFunction();
156+
if (brf != null) {
157+
brf.tryCommitBlockingResponse(requestContext.getTraceSegment(), rba);
158+
// effectivelyBlocked() is intentionally absent: tryCommitBlockingResponse finishes
159+
// the span synchronously in this Netty path; calling it on a finished span throws.
160+
thr = new BlockingException("Blocked request (multipart/urlencoded post data)");
161+
}
160162
}
161163
}
162164

0 commit comments

Comments
 (0)