Skip to content

Commit 4b5c9f0

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

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
@@ -15,7 +15,7 @@ dependencies {
1515
implementation project(':internal-api')
1616
implementation project(':communication')
1717
implementation project(':telemetry')
18-
implementation group: 'io.sqreen', name: 'libsqreen', version: '15.0.1'
18+
implementation group: 'io.sqreen', name: 'libsqreen', version: '17.0.0'
1919
implementation libs.moshi
2020

2121
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
@@ -52,7 +52,6 @@
5252
import java.lang.reflect.UndeclaredThrowableException;
5353
import java.util.Collection;
5454
import java.util.Collections;
55-
import java.util.HashMap;
5655
import java.util.HashSet;
5756
import java.util.Iterator;
5857
import java.util.List;
@@ -80,8 +79,6 @@ public class WAFModule implements AppSecModule {
8079

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

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

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

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

@@ -1309,8 +1342,9 @@ class WAFModuleSpecification extends DDSpecification {
13091342
initialRuleAddWithMap(waf)
13101343
13111344
then:
1312-
thrown RuntimeException
1345+
thrown AppSecModuleActivationException
13131346
wafModule.dataSubscriptions.empty
1347+
1 * wafMetricCollector.wafInit(Waf.LIB_VERSION, _, false)
13141348
0 * _
13151349
}
13161350
@@ -1321,8 +1355,10 @@ class WAFModuleSpecification extends DDSpecification {
13211355
initialRuleAddWithMap(waf)
13221356
13231357
then:
1324-
thrown RuntimeException
1358+
thrown AppSecModuleActivationException
13251359
wafModule.ctxAndAddresses.get() == null
1360+
// WAF initialization is attempted but fails, so wafInit is called with success=false
1361+
1 * wafMetricCollector.wafInit(Waf.LIB_VERSION, _, false)
13261362
0 * _
13271363
}
13281364

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)