Skip to content

Commit 6edb6f9

Browse files
committed
add security response id with errors
1 parent 6e9dbd5 commit 6edb6f9

File tree

35 files changed

+75
-48
lines changed

35 files changed

+75
-48
lines changed

dd-java-agent/appsec/src/main/java/com/datadog/appsec/blocking/BlockingServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public boolean tryCommitBlockingResponse(
8989
log.debug("About to call block response function: {}", blockResponseFunction);
9090
boolean res =
9191
blockResponseFunction.tryCommitBlockingResponse(
92-
reqCtx.getTraceSegment(), statusCode, templateType, extraHeaders);
92+
reqCtx.getTraceSegment(), statusCode, templateType, extraHeaders, null);
9393
if (res) {
9494
TraceSegment traceSegment = reqCtx.getTraceSegment();
9595
if (traceSegment != null) {

dd-java-agent/appsec/src/main/java/com/datadog/appsec/ddwaf/WAFModule.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ public void onDataAvailable(
464464
}
465465

466466
private Flow.Action.RequestBlockingAction createBlockRequestAction(
467-
final ActionInfo actionInfo, final AppSecRequestContext reqCtx, final boolean isRasp, final String securityResponseId) {
467+
final ActionInfo actionInfo,
468+
final AppSecRequestContext reqCtx,
469+
final boolean isRasp,
470+
final String securityResponseId) {
468471
try {
469472
int statusCode;
470473
Object statusCodeObj = actionInfo.parameters.get("status_code");
@@ -482,7 +485,8 @@ private Flow.Action.RequestBlockingAction createBlockRequestAction(
482485
} catch (IllegalArgumentException iae) {
483486
log.warn("Unknown content type: {}; using auto", contentType);
484487
}
485-
return new Flow.Action.RequestBlockingAction(statusCode, blockingContentType, null, securityResponseId);
488+
return new Flow.Action.RequestBlockingAction(
489+
statusCode, blockingContentType, null, securityResponseId);
486490
} catch (RuntimeException cce) {
487491
log.warn("Invalid blocking action data", cce);
488492
if (!isRasp) {
@@ -493,7 +497,10 @@ private Flow.Action.RequestBlockingAction createBlockRequestAction(
493497
}
494498

495499
private Flow.Action.RequestBlockingAction createRedirectRequestAction(
496-
final ActionInfo actionInfo, final AppSecRequestContext reqCtx, final boolean isRasp, final String securityResponseId) {
500+
final ActionInfo actionInfo,
501+
final AppSecRequestContext reqCtx,
502+
final boolean isRasp,
503+
final String securityResponseId) {
497504
try {
498505
int statusCode;
499506
Object statusCodeObj = actionInfo.parameters.get("status_code");
@@ -520,8 +527,7 @@ private Flow.Action.RequestBlockingAction createRedirectRequestAction(
520527
location = location.replace("[security_response_id]", securityResponseId);
521528
}
522529
}
523-
return Flow.Action.RequestBlockingAction.forRedirect(
524-
statusCode, location);
530+
return Flow.Action.RequestBlockingAction.forRedirect(statusCode, location);
525531
} catch (RuntimeException cce) {
526532
log.warn("Invalid blocking action data", cce);
527533
if (!isRasp) {

dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/blocking/BlockingServiceImplSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class BlockingServiceImplSpecification extends DDSpecification {
108108

109109
then:
110110
res == true
111-
1 * brf.tryCommitBlockingResponse(mts, 405, BlockingContentType.HTML, [:],) >> true
111+
1 * brf.tryCommitBlockingResponse(mts, 405, BlockingContentType.HTML, [:], null) >> true
112112
1 * mts.effectivelyBlocked()
113113
}
114114

dd-java-agent/instrumentation/akka/akka-http/akka-http-10.0/src/main/java/datadog/trace/instrumentation/akkahttp/appsec/AkkaBlockResponseFunction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public boolean tryCommitBlockingResponse(
5555
TraceSegment segment,
5656
int statusCode,
5757
BlockingContentType templateType,
58-
Map<String, String> extraHeaders) {
58+
Map<String, String> extraHeaders,
59+
String securityResponseId) {
5960
AgentSpan agentSpan = AgentTracer.activeSpan();
6061
if (agentSpan == null) {
6162
return false;

dd-java-agent/instrumentation/grizzly/grizzly-2.0/src/main/java/datadog/trace/instrumentation/grizzly/GrizzlyDecorator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public boolean tryCommitBlockingResponse(
8989
TraceSegment segment,
9090
int statusCode,
9191
BlockingContentType templateType,
92-
Map<String, String> extraHeaders) {
92+
Map<String, String> extraHeaders,
93+
String securityResponseId) {
9394
AgentSpan agentSpan = AgentTracer.get().activeSpan();
9495
if (agentSpan == null) {
9596
log.warn("Can't block: no active span");

dd-java-agent/instrumentation/grizzly/grizzly-http-2.3.20/src/main/java/datadog/trace/instrumentation/grizzlyhttp232/GrizzlyDecorator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public boolean tryCommitBlockingResponse(
180180
TraceSegment segment,
181181
int statusCode,
182182
BlockingContentType templateType,
183-
Map<String, String> extraHeaders) {
183+
Map<String, String> extraHeaders,
184+
String securityResponseId) {
184185
if (ctx == null) {
185186
return false;
186187
}

dd-java-agent/instrumentation/grizzly/grizzly-http-2.3.20/src/main/java/datadog/trace/instrumentation/grizzlyhttp232/GrizzlyHttpBlockingHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public static boolean block(
139139
int statusCode,
140140
BlockingContentType templateType,
141141
Map<String, String> extraHeaders,
142-
TraceSegment segment) {
142+
TraceSegment segment,
143+
String securityResponseId) {
143144
if (ENCODE_HTTP_PACKET == null) {
144145
return false;
145146
}
@@ -166,7 +167,7 @@ public static boolean block(
166167
BlockingActionHelper.determineTemplateType(templateType, acceptHeader);
167168

168169
httpResponse.setHeader("Content-type", BlockingActionHelper.getContentType(type));
169-
byte[] template = BlockingActionHelper.getTemplate(type);
170+
byte[] template = BlockingActionHelper.getTemplate(type, securityResponseId);
170171
httpResponse.setContentLength(template.length);
171172
httpContent =
172173
HttpContent.builder(httpResponse).content(HeapBuffer.wrap(template)).last(true).build();

dd-java-agent/instrumentation/jetty/jetty-common/src/main/java/datadog/trace/instrumentation/jetty/JettyBlockResponseFunction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public boolean tryCommitBlockingResponse(
1919
TraceSegment segment,
2020
int statusCode,
2121
BlockingContentType templateType,
22-
Map<String, String> extraHeaders) {
22+
Map<String, String> extraHeaders,
23+
String securityResponseId) {
2324
Response response = request.getResponse();
2425
return JettyBlockingHelper.block(
25-
segment, request, response, statusCode, templateType, extraHeaders);
26+
segment, request, response, statusCode, templateType, extraHeaders, securityResponseId);
2627
}
2728
}

dd-java-agent/instrumentation/jetty/jetty-common/src/main/java/datadog/trace/instrumentation/jetty/JettyBlockingHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public static boolean block(
186186
BlockingActionHelper.determineTemplateType(bct, acceptHeader);
187187
response.setCharacterEncoding("utf-8");
188188
response.setHeader("Content-type", BlockingActionHelper.getContentType(type));
189-
byte[] template = BlockingActionHelper.getTemplate(type);
189+
byte[] template = BlockingActionHelper.getTemplate(type, securityResponseId);
190190

191191
if (!response.isWriting()) {
192192
response.setHeader("Content-length", Integer.toString(template.length));

dd-java-agent/instrumentation/jetty/jetty-server/jetty-server-10.0/src/main/java11/datadog/trace/instrumentation/jetty10/JettyOnCommitBlockingHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static boolean block(
5454
BlockingActionHelper.TemplateType type =
5555
BlockingActionHelper.determineTemplateType(bct, acceptHeader);
5656
putHeader(fields, "Content-type", BlockingActionHelper.getContentType(type));
57-
byte[] template = BlockingActionHelper.getTemplate(type);
57+
byte[] template = BlockingActionHelper.getTemplate(type, securityResponseId);
5858
putHeader(fields, "Content-length", Integer.toString(template.length));
5959

6060
info = new MetaData.Response(request.getHttpVersion(), statusCode, fields, template.length);

0 commit comments

Comments
 (0)