Skip to content

Commit de914df

Browse files
committed
Waf upgrade to 1.28.0
Signed-off-by: sezen.leblay <[email protected]>
1 parent f6e94b2 commit de914df

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

dd-java-agent/appsec/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
implementation project(':internal-api')
1515
implementation project(':communication')
1616
implementation project(':telemetry')
17-
implementation group: 'io.sqreen', name: 'libsqreen', version: '16.0.0'
17+
implementation group: 'io.sqreen', name: 'libsqreen', version: '17.0.0'
1818
implementation libs.moshi
1919

2020
testImplementation libs.bytebuddy

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import java.lang.reflect.UndeclaredThrowableException;
5454
import java.util.Collection;
5555
import java.util.Collections;
56-
import java.util.HashMap;
5756
import java.util.HashSet;
5857
import java.util.Iterator;
5958
import java.util.List;
@@ -81,8 +80,6 @@ public class WAFModule implements AppSecModule {
8180

8281
private static final JsonAdapter<List<WAFResultData>> RES_JSON_ADAPTER;
8382

84-
private static final Map<String, ActionInfo> DEFAULT_ACTIONS;
85-
8683
private static final String EXPLOIT_DETECTED_MSG = "Exploit detected";
8784
private boolean init = true;
8885
private String rulesetVersion;
@@ -118,12 +115,6 @@ private CtxAndAddresses(Collection<Address<?>> addressesOfInterest, WafHandle ct
118115
Moshi moshi = new Moshi.Builder().build();
119116
RES_JSON_ADAPTER = moshi.adapter(Types.newParameterizedType(List.class, WAFResultData.class));
120117

121-
Map<String, Object> actionParams = new HashMap<>();
122-
actionParams.put("status_code", 403);
123-
actionParams.put("type", "auto");
124-
actionParams.put("grpc_status_code", 10);
125-
DEFAULT_ACTIONS =
126-
Collections.singletonMap("block", new ActionInfo("block_request", actionParams));
127118
createLimitsObject();
128119
}
129120

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

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

3+
import com.datadog.appsec.AppSecModule.AppSecModuleActivationException
34
import com.datadog.appsec.AppSecSystem
45
import com.datadog.appsec.config.AppSecConfigService
56
import com.datadog.appsec.config.AppSecConfigServiceImpl
@@ -147,10 +148,42 @@ class WAFModuleSpecification extends DDSpecification {
147148
listener.remove(config, null)
148149
return
149150
}
150-
def json = ADAPTER.toJson(map)
151+
// Convert Double values to Long for status codes
152+
def convertedMap = convertDoublesToLongs(map)
153+
def json = ADAPTER.toJson(convertedMap)
151154
listener.accept(config, json.getBytes(), null)
152155
}
153156

157+
private static Map<String, Object> convertDoublesToLongs(Map<String, Object> map) {
158+
def result = [:]
159+
map.each { key, value ->
160+
if (value instanceof Map) {
161+
result[key] = convertDoublesToLongs(value as Map<String, Object>)
162+
} else if (value instanceof List) {
163+
result[key] = convertDoublesToLongs(value as List)
164+
} else if (value instanceof Double && ((Double) value).longValue() == ((Double) value).doubleValue()) {
165+
// Convert whole number doubles to longs
166+
result[key] = ((Double) value).longValue()
167+
} else {
168+
result[key] = value
169+
}
170+
}
171+
return result
172+
}
173+
174+
private static List convertDoublesToLongs(List list) {
175+
return list.collect { item ->
176+
if (item instanceof Map) {
177+
return convertDoublesToLongs(item as Map<String, Object>)
178+
} else if (item instanceof List) {
179+
return convertDoublesToLongs(item as List)
180+
} else if (item instanceof Double && ((Double) item).longValue() == ((Double) item).doubleValue()) {
181+
return ((Double) item).longValue()
182+
}
183+
return item
184+
}
185+
}
186+
154187
void 'override on_match through reconfiguration'() {
155188
ChangeableFlow flow = Mock()
156189

@@ -1333,8 +1366,9 @@ class WAFModuleSpecification extends DDSpecification {
13331366
initialRuleAddWithMap(waf)
13341367
13351368
then:
1336-
thrown RuntimeException
1369+
thrown AppSecModuleActivationException
13371370
wafModule.dataSubscriptions.empty
1371+
1 * wafMetricCollector.wafInit(Waf.LIB_VERSION, _, false)
13381372
0 * _
13391373
}
13401374
@@ -1345,8 +1379,10 @@ class WAFModuleSpecification extends DDSpecification {
13451379
initialRuleAddWithMap(waf)
13461380
13471381
then:
1348-
thrown RuntimeException
1382+
thrown AppSecModuleActivationException
13491383
wafModule.ctxAndAddresses.get() == null
1384+
// WAF initialization is attempted but fails, so wafInit is called with success=false
1385+
1 * wafMetricCollector.wafInit(Waf.LIB_VERSION, _, false)
13501386
0 * _
13511387
}
13521388

internal-api/src/main/java/datadog/trace/api/gateway/Flow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public boolean isBlocking() {
2828
}
2929

3030
class RequestBlockingAction implements Action {
31-
private final int statusCode;
31+
private final long statusCode;
3232
private final BlockingContentType blockingContentType;
3333
private final Map<String, String> extraHeaders;
3434

@@ -56,7 +56,7 @@ public boolean isBlocking() {
5656
}
5757

5858
public int getStatusCode() {
59-
return statusCode;
59+
return Math.toIntExact(statusCode);
6060
}
6161

6262
public BlockingContentType getBlockingContentType() {

0 commit comments

Comments
 (0)