55import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_AUTO_USER_INSTRUM_MODE ;
66import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_CUSTOM_BLOCKING_RESPONSE ;
77import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_CUSTOM_RULES ;
8+ import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_DD_MULTICONFIG ;
89import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_DD_RULES ;
910import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_EXCLUSIONS ;
1011import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_EXCLUSION_DATA ;
1819import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_RASP_SSRF ;
1920import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_REQUEST_BLOCKING ;
2021import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_SESSION_FINGERPRINT ;
22+ import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_TRACE_TAGGING_RULES ;
2123import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_TRUSTED_IPS ;
2224import static datadog .remoteconfig .Capabilities .CAPABILITY_ASM_USER_BLOCKING ;
2325import static datadog .remoteconfig .Capabilities .CAPABILITY_ENDPOINT_FINGERPRINT ;
3739import com .datadog .ddwaf .exception .InvalidRuleSetException ;
3840import com .datadog .ddwaf .exception .UnclassifiedWafException ;
3941import com .squareup .moshi .JsonAdapter ;
42+ import com .squareup .moshi .JsonReader ;
43+ import com .squareup .moshi .JsonWriter ;
4044import com .squareup .moshi .Moshi ;
41- import com .squareup .moshi .Types ;
4245import datadog .remoteconfig .ConfigurationEndListener ;
4346import datadog .remoteconfig .ConfigurationPoller ;
4447import datadog .remoteconfig .PollingRateHinter ;
6568import java .util .Set ;
6669import java .util .concurrent .ConcurrentHashMap ;
6770import java .util .concurrent .atomic .AtomicBoolean ;
71+ import javax .annotation .Nullable ;
6872import okio .Okio ;
6973import org .slf4j .Logger ;
7074import org .slf4j .LoggerFactory ;
@@ -92,10 +96,25 @@ public class AppSecConfigServiceImpl implements AppSecConfigService {
9296 new WAFInitializationResultReporter ();
9397 private final WAFStatsReporter statsReporter = new WAFStatsReporter ();
9498
95- private static final JsonAdapter <Map < String , Object > > ADAPTER =
99+ private static final JsonAdapter <Object > ADAPTER =
96100 new Moshi .Builder ()
101+ .add (
102+ Double .class ,
103+ new JsonAdapter <Number >() {
104+ @ Override
105+ public Number fromJson (JsonReader reader ) throws IOException {
106+ double value = reader .nextDouble ();
107+ long longValue = (long ) value ;
108+ return value % 1 == 0 ? longValue : value ;
109+ }
110+
111+ @ Override
112+ public void toJson (JsonWriter writer , @ Nullable Number value ) throws IOException {
113+ throw new UnsupportedOperationException ();
114+ }
115+ })
97116 .build ()
98- .adapter (Types . newParameterizedType ( Map . class , String . class , Object .class ) );
117+ .adapter (Object .class );
99118
100119 private boolean hasUserWafConfig ;
101120 private boolean defaultConfigActivated ;
@@ -104,7 +123,7 @@ public class AppSecConfigServiceImpl implements AppSecConfigService {
104123 Collections .newSetFromMap (new ConcurrentHashMap <>());
105124 private final Set <String > ignoredConfigKeys =
106125 Collections .newSetFromMap (new ConcurrentHashMap <>());
107- private final String DEFAULT_WAF_CONFIG_RULE = "DEFAULT_WAF_CONFIG " ;
126+ private final String DEFAULT_WAF_CONFIG_RULE = "ASM_DD/default " ;
108127 private String currentRuleVersion ;
109128 private List <AppSecModule > modulesToUpdateVersionIn ;
110129
@@ -137,6 +156,7 @@ private void subscribeConfigurationPoller() {
137156 private long getRulesAndDataCapabilities () {
138157 long capabilities =
139158 CAPABILITY_ASM_DD_RULES
159+ | CAPABILITY_ASM_DD_MULTICONFIG
140160 | CAPABILITY_ASM_IP_BLOCKING
141161 | CAPABILITY_ASM_EXCLUSIONS
142162 | CAPABILITY_ASM_EXCLUSION_DATA
@@ -148,7 +168,8 @@ private long getRulesAndDataCapabilities() {
148168 | CAPABILITY_ENDPOINT_FINGERPRINT
149169 | CAPABILITY_ASM_SESSION_FINGERPRINT
150170 | CAPABILITY_ASM_NETWORK_FINGERPRINT
151- | CAPABILITY_ASM_HEADER_FINGERPRINT ;
171+ | CAPABILITY_ASM_HEADER_FINGERPRINT
172+ | CAPABILITY_ASM_TRACE_TAGGING_RULES ;
152173 if (tracerConfig .isAppSecRaspEnabled ()) {
153174 capabilities |= CAPABILITY_ASM_RASP_SQLI ;
154175 capabilities |= CAPABILITY_ASM_RASP_SSRF ;
@@ -210,7 +231,8 @@ public void accept(ConfigKey configKey, byte[] content, PollingRateHinter pollin
210231 }
211232 final String key = configKey .toString ();
212233 Map <String , Object > contentMap =
213- ADAPTER .fromJson (Okio .buffer (Okio .source (new ByteArrayInputStream (content ))));
234+ (Map <String , Object >)
235+ ADAPTER .fromJson (Okio .buffer (Okio .source (new ByteArrayInputStream (content ))));
214236 if (contentMap == null || contentMap .isEmpty ()) {
215237 ignoredConfigKeys .add (key );
216238 } else {
@@ -255,7 +277,7 @@ private class AppSecConfigChangesDDListener extends AppSecConfigChangesListener
255277 @ Override
256278 protected void beforeApply (final String key , final Map <String , Object > config ) {
257279 if (defaultConfigActivated ) { // if we get any config, remove the default one
258- log .debug ("Removing default config" );
280+ log .debug ("Removing default config ASM_DD/default " );
259281 try {
260282 wafBuilder .removeConfig (DEFAULT_WAF_CONFIG_RULE );
261283 } catch (UnclassifiedWafException e ) {
@@ -466,7 +488,8 @@ private static Map<String, Object> loadDefaultWafConfig() throws IOException {
466488 throw new IOException ("Resource " + DEFAULT_CONFIG_LOCATION + " not found" );
467489 }
468490
469- Map <String , Object > ret = ADAPTER .fromJson (Okio .buffer (Okio .source (is )));
491+ Map <String , Object > ret =
492+ (Map <String , Object >) ADAPTER .fromJson (Okio .buffer (Okio .source (is )));
470493
471494 StandardizedLogging ._initialConfigSourceAndLibddwafVersion (log , "<bundled config>" );
472495 if (log .isInfoEnabled ()) {
@@ -483,7 +506,8 @@ private static Map<String, Object> loadUserWafConfig(Config tracerConfig) throws
483506 return null ;
484507 }
485508 try (InputStream is = new FileInputStream (filename )) {
486- Map <String , Object > ret = ADAPTER .fromJson (Okio .buffer (Okio .source (is )));
509+ Map <String , Object > ret =
510+ (Map <String , Object >) ADAPTER .fromJson (Okio .buffer (Okio .source (is )));
487511
488512 StandardizedLogging ._initialConfigSourceAndLibddwafVersion (log , filename );
489513 if (log .isInfoEnabled ()) {
@@ -512,6 +536,7 @@ public void close() {
512536 this .configurationPoller .removeCapabilities (
513537 CAPABILITY_ASM_ACTIVATION
514538 | CAPABILITY_ASM_DD_RULES
539+ | CAPABILITY_ASM_DD_MULTICONFIG
515540 | CAPABILITY_ASM_IP_BLOCKING
516541 | CAPABILITY_ASM_EXCLUSIONS
517542 | CAPABILITY_ASM_EXCLUSION_DATA
@@ -529,7 +554,8 @@ public void close() {
529554 | CAPABILITY_ENDPOINT_FINGERPRINT
530555 | CAPABILITY_ASM_SESSION_FINGERPRINT
531556 | CAPABILITY_ASM_NETWORK_FINGERPRINT
532- | CAPABILITY_ASM_HEADER_FINGERPRINT );
557+ | CAPABILITY_ASM_HEADER_FINGERPRINT
558+ | CAPABILITY_ASM_TRACE_TAGGING_RULES );
533559 this .configurationPoller .removeListeners (Product .ASM_DD );
534560 this .configurationPoller .removeListeners (Product .ASM_DATA );
535561 this .configurationPoller .removeListeners (Product .ASM );
0 commit comments