Skip to content

Commit 68a511a

Browse files
committed
stuff
1 parent c7d8eb0 commit 68a511a

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

dd-java-agent/appsec/src/main/java/com/datadog/appsec/AppSecSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
7272
log.debug("In-app WAF initialization failed. See previous log entries");
7373
return;
7474
}
75-
wafBuilder = new WafBuilder(createWafConfig(config));
7675
REPLACEABLE_EVENT_PRODUCER = new ReplaceableEventProducerService();
7776
EventDispatcher eventDispatcher = new EventDispatcher();
7877
REPLACEABLE_EVENT_PRODUCER.replaceEventProducerService(eventDispatcher);
@@ -94,6 +93,7 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
9493
APP_SEC_CONFIG_SERVICE =
9594
new AppSecConfigServiceImpl(
9695
config, configurationPoller, () -> reloadSubscriptions(REPLACEABLE_EVENT_PRODUCER));
96+
wafBuilder = new WafBuilder(createWafConfig(config));
9797
APP_SEC_CONFIG_SERVICE.init(wafBuilder);
9898

9999
sco.createRemaining(config);
@@ -113,7 +113,7 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
113113

114114
setActive(appSecEnabledConfig == ProductActivation.FULLY_ENABLED);
115115

116-
APP_SEC_CONFIG_SERVICE.maybeSubscribeConfigPolling(AppSecSystem.wafBuilder);
116+
APP_SEC_CONFIG_SERVICE.maybeSubscribeConfigPolling(wafBuilder);
117117

118118
Blocking.setBlockingService(new BlockingServiceImpl(REPLACEABLE_EVENT_PRODUCER));
119119

dd-java-agent/appsec/src/main/java/com/datadog/appsec/config/AppSecConfigServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ private void subscribeRulesAndData(WafBuilder wafBuilder) {
174174
} catch (InvalidRuleSetException e) {
175175
throw new RuntimeException(e);
176176
}
177-
this.currentAppSecConfig.dirtyStatus.data = true;
178177
}
178+
this.currentAppSecConfig.dirtyStatus.data = true;
179179
});
180180
this.configurationPoller.addListener(
181181
Product.ASM,

dd-java-agent/appsec/src/main/java/com/datadog/appsec/config/AppSecDataDeserializer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,19 @@ public AppSecData deserialize(byte[] content) throws IOException {
2828
@SuppressWarnings("unchecked")
2929
private AppSecData deserialize(InputStream is) throws IOException {
3030
AppSecData appSecData = ADAPTER.fromJson(Okio.buffer(Okio.source(is)));
31+
is.reset();
3132
if (appSecData != null && is.available() > 0) {
3233
appSecData.setRawConfig(MOSHI.adapter(Map.class).fromJson(Okio.buffer(Okio.source(is))));
34+
if (appSecData.getRawConfig().containsKey("rules_data")) {
35+
appSecData.getRawConfig().put("rules", appSecData.getRawConfig().get("rules_data"));
36+
appSecData.getRawConfig().remove("rules_data");
37+
}
38+
if (appSecData.getRawConfig().containsKey("exclusion_data")) {
39+
appSecData
40+
.getRawConfig()
41+
.put("exclusions", appSecData.getRawConfig().get("exclusion_data"));
42+
appSecData.getRawConfig().remove("exclusion_data");
43+
}
3344
}
3445
return appSecData;
3546
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ public void config(AppSecModuleConfigurer appSecConfigService, WafBuilder wafBui
176176
if (!initialConfig.isPresent()) {
177177
throw new AppSecModuleActivationException("No initial config for WAF");
178178
}
179-
180179
try {
181180
applyConfig(initialConfig.get(), AppSecModuleConfigurer.Reconfiguration.NOOP);
182181
} catch (AbstractWafException | ClassCastException e) {
@@ -200,7 +199,9 @@ private void applyConfig(Object config_, AppSecModuleConfigurer.Reconfiguration
200199

201200
boolean success = false;
202201
boolean init = ctxAndAddresses.get() == null;
203-
config.dirtyStatus.markAllDirty();
202+
if (init) {
203+
config.dirtyStatus.markAllDirty();
204+
}
204205
try {
205206
success = initOrUpdateWafBuilder(config, reconf);
206207
} catch (Exception e) {
@@ -278,6 +279,7 @@ private boolean initOrUpdateWafBuilder(
278279
this.statsReporter.rulesVersion = initReport.rulesetVersion;
279280
} catch (InvalidRuleSetException irse) {
280281
initReport = irse.ruleSetInfo;
282+
log.info(irse.getMessage());
281283
throw new AppSecModuleActivationException("Error creating WAF rules", irse);
282284
} catch (RuntimeException | AbstractWafException e) {
283285
throw new AppSecModuleActivationException("Error creating WAF rules", e);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.datadog.appsec
22

33
import com.datadog.appsec.config.AppSecConfig
4+
import com.datadog.appsec.config.CurrentAppSecConfig
5+
import com.datadog.appsec.ddwaf.WafInitialization
46
import com.datadog.appsec.event.EventProducerService
57
import com.datadog.appsec.gateway.AppSecRequestContext
68
import com.datadog.appsec.report.AppSecEvent
@@ -102,6 +104,7 @@ class AppSecSystemSpecification extends DDSpecification {
102104
}
103105

104106
void 'updating configuration replaces the EventProducer'() {
107+
WafInitialization.ONLINE
105108
ConfigurationChangesTypedListener<AppSecConfig> savedAsmListener
106109
ConfigurationEndListener savedConfEndListener
107110

@@ -118,7 +121,7 @@ class AppSecSystemSpecification extends DDSpecification {
118121
}
119122

120123
when:
121-
savedAsmListener.accept('ignored config key',
124+
savedAsmListener.accept(CurrentAppSecConfig.DEFAULT_KEY,
122125
AppSecConfig.valueOf([version: '2.1', rules: [
123126
[
124127
id: 'foo',

dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/config/AppSecConfigServiceImplSpecification.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class AppSecConfigServiceImplSpecification extends DDSpecification {
232232

233233
when:
234234
listeners.savedFeaturesListener.accept(
235-
'ignored config key',
235+
CurrentAppSecConfig.DEFAULT_KEY,
236236
listeners.savedFeaturesDeserializer.deserialize(
237237
'{"asm":{"enabled": true}}'.bytes), null)
238238
listeners.savedConfEndListener.onConfigurationEnd()
@@ -302,7 +302,7 @@ class AppSecConfigServiceImplSpecification extends DDSpecification {
302302
when:
303303
// AppSec is INACTIVE - rules should not trigger subscriptions
304304
listeners.savedConfChangesListener.accept(
305-
'ignored config key',
305+
CurrentAppSecConfig.DEFAULT_KEY,
306306
listeners.savedConfDeserializer.deserialize(
307307
'{"version": "1.0"}'.bytes), null)
308308

@@ -311,7 +311,7 @@ class AppSecConfigServiceImplSpecification extends DDSpecification {
311311

312312
when:
313313
listeners.savedFeaturesListener.accept(
314-
'asm_features_activation',
314+
CurrentAppSecConfig.DEFAULT_KEY,
315315
listeners.savedFeaturesDeserializer.deserialize(
316316
'{"asm":{"enabled": true}}'.bytes), null)
317317
listeners.savedConfEndListener.onConfigurationEnd()
@@ -323,14 +323,14 @@ class AppSecConfigServiceImplSpecification extends DDSpecification {
323323
when:
324324
// AppSec is ACTIVE - rules trigger subscriptions
325325
listeners.savedConfChangesListener.accept(
326-
'ignored config key',
326+
CurrentAppSecConfig.DEFAULT_KEY,
327327
listeners.savedConfDeserializer.deserialize(
328328
'{"version": "2.0"}'.bytes), null)
329329
listeners.savedWafDataChangesListener.accept(
330-
'ignored config key',
331-
listeners.savedWafDataDeserializer.deserialize('{"rules_data":[{"id":"foo","type":"","data":[]}]}'.bytes), null)
330+
CurrentAppSecConfig.DEFAULT_KEY,
331+
listeners.savedWafDataDeserializer.deserialize('{"rules_data":[{"id":"foo", "conditions": "foo", "type":"","data":[]}]}'.bytes), null)
332332
listeners.savedWafRulesOverrideListener.accept(
333-
'ignored config key',
333+
CurrentAppSecConfig.DEFAULT_KEY,
334334
listeners.savedWafRulesOverrideDeserializer.deserialize('{"rules_override": [{"rules_target":[{"rule_id": "foo"}], "enabled":false}]}'.bytes), null)
335335
listeners.savedConfEndListener.onConfigurationEnd()
336336

0 commit comments

Comments
 (0)