Skip to content

Commit 1776ef8

Browse files
committed
Fix appsec.waf.requests
1 parent e57d2c4 commit 1776ef8

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

dd-java-agent/appsec/src/main/java/com/datadog/appsec/gateway/AppSecRequestContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public class AppSecRequestContext implements DataBundle, Closeable {
120120
private volatile PowerwafMetrics raspMetrics;
121121
private final AtomicInteger raspMetricsCounter = new AtomicInteger(0);
122122
private volatile boolean blocked;
123+
private volatile boolean errors;
123124
private volatile int wafTimeouts;
124125
private volatile int raspTimeouts;
125126

@@ -182,6 +183,14 @@ public boolean isBlocked() {
182183
return blocked;
183184
}
184185

186+
public void setErrors() {
187+
this.errors = true;
188+
}
189+
190+
public boolean hasErrors() {
191+
return errors;
192+
}
193+
185194
public void increaseWafTimeouts() {
186195
WAF_TIMEOUTS_UPDATER.incrementAndGet(this);
187196
}

dd-java-agent/appsec/src/main/java/com/datadog/appsec/gateway/GatewayBridge.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,9 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
724724
log.debug("Unable to commit, derivatives will be skipped {}", ctx.getDerivativeKeys());
725725
}
726726

727-
if (ctx.isBlocked()) {
727+
if (ctx.hasErrors()) {
728+
WafMetricCollector.get().wafRequestError();
729+
} else if (ctx.isBlocked()) {
728730
WafMetricCollector.get().wafRequestBlocked();
729731
} else if (!collectedEvents.isEmpty()) {
730732
WafMetricCollector.get().wafRequestTriggered();

dd-java-agent/appsec/src/main/java/com/datadog/appsec/powerwaf/PowerWAFModule.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,11 @@ public void onDataAvailable(
449449
if (!reqCtx.isAdditiveClosed()) {
450450
log.error("Error calling WAF", e);
451451
}
452-
WafMetricCollector.get().wafRequestError();
453452
// TODO: replace -127 for e.code when UnclassifiedPowerwafException code is fixed
454-
incrementErrorCodeMetric(gwCtx, -127);
453+
incrementErrorCodeMetric(reqCtx, gwCtx, -127);
455454
return;
456455
} catch (AbstractPowerwafException e) {
457-
incrementErrorCodeMetric(gwCtx, e.code);
456+
incrementErrorCodeMetric(reqCtx, gwCtx, e.code);
458457
return;
459458
} finally {
460459
if (log.isDebugEnabled()) {
@@ -549,7 +548,9 @@ public void onDataAvailable(
549548
}
550549

551550
if (flow.isBlocking()) {
552-
reqCtx.setBlocked();
551+
if (!gwCtx.isRasp) {
552+
reqCtx.setBlocked();
553+
}
553554
}
554555
}
555556

@@ -650,11 +651,13 @@ private Powerwaf.ResultWithData runPowerwafAdditive(
650651
}
651652
}
652653

653-
private static void incrementErrorCodeMetric(GatewayContext gwCtx, int code) {
654+
private static void incrementErrorCodeMetric(
655+
AppSecRequestContext reqCtx, GatewayContext gwCtx, int code) {
654656
if (gwCtx.isRasp) {
655657
WafMetricCollector.get().raspErrorCode(gwCtx.raspRuleType, code);
656658
} else {
657659
WafMetricCollector.get().wafErrorCode(code);
660+
reqCtx.setErrors();
658661
}
659662
}
660663

0 commit comments

Comments
 (0)