Skip to content

Commit ef2e9f0

Browse files
authored
Fix NullPointerException log in AppSec (#9355)
What Does This Do Modifies WafModule#buildEvents to safely handle actionWithData.data being null. Motivation Fix #9346 Additional Notes The current version of libddwaf may return null in the data field of actionWithData. This was previously not handled and could cause unexpected logged exceptions. The method now explicitly checks for null to prevent this.
1 parent 8d4316a commit ef2e9f0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.datadog.appsec.ddwaf;
22

3+
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
34
import static datadog.trace.util.stacktrace.StackTraceEvent.DEFAULT_LANGUAGE;
45
import static java.util.Collections.emptyList;
56
import static java.util.Collections.singletonList;
@@ -557,6 +558,10 @@ private Waf.ResultWithData runWafTransient(
557558
}
558559

559560
private Collection<AppSecEvent> buildEvents(Waf.ResultWithData actionWithData) {
561+
if (actionWithData.data == null) {
562+
log.debug(SEND_TELEMETRY, "WAF result data is null");
563+
return Collections.emptyList();
564+
}
560565
Collection<WAFResultData> listResults;
561566
try {
562567
listResults = RES_JSON_ADAPTER.fromJson(actionWithData.data);

dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/ddwaf/WAFModuleSpecification.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,19 @@ class WAFModuleSpecification extends DDSpecification {
16821682
internal == libddwaf
16831683
}
16841684

1685+
void 'ResultWithData - null data'() {
1686+
def waf = new WAFModule()
1687+
Waf.ResultWithData rwd = new Waf.ResultWithData(null, null, null, null)
1688+
Collection ret
1689+
1690+
when:
1691+
ret = waf.buildEvents(rwd)
1692+
1693+
then:
1694+
noExceptionThrown()
1695+
ret.isEmpty()
1696+
}
1697+
16851698
/**
16861699
* Helper to return a concrete Waf exception for each WafErrorCode
16871700
*/

0 commit comments

Comments
 (0)