7
7
import com .datadog .appsec .config .AppSecConfigService ;
8
8
import com .datadog .appsec .config .AppSecConfigServiceImpl ;
9
9
import com .datadog .appsec .ddwaf .WAFModule ;
10
+ import com .datadog .appsec .ddwaf .WafInitialization ;
10
11
import com .datadog .appsec .event .EventDispatcher ;
11
12
import com .datadog .appsec .event .ReplaceableEventProducerService ;
12
13
import com .datadog .appsec .gateway .GatewayBridge ;
13
14
import com .datadog .appsec .util .AbortStartupException ;
14
15
import com .datadog .appsec .util .StandardizedLogging ;
16
+ import com .datadog .ddwaf .WafBuilder ;
17
+ import com .datadog .ddwaf .WafConfig ;
15
18
import datadog .appsec .api .blocking .Blocking ;
16
19
import datadog .appsec .api .blocking .BlockingService ;
17
20
import datadog .communication .ddagent .SharedCommunicationObjects ;
@@ -43,6 +46,7 @@ public class AppSecSystem {
43
46
private static ReplaceableEventProducerService REPLACEABLE_EVENT_PRODUCER ; // testing
44
47
private static Runnable STOP_SUBSCRIPTION_SERVICE ;
45
48
private static Runnable RESET_SUBSCRIPTION_SERVICE ;
49
+ private static WafBuilder wafBuilder ;
46
50
47
51
public static void start (SubscriptionService gw , SharedCommunicationObjects sco ) {
48
52
try {
@@ -64,7 +68,10 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
64
68
return ;
65
69
}
66
70
log .debug ("AppSec is starting ({})" , appSecEnabledConfig );
67
-
71
+ if (!WafInitialization .ONLINE ) {
72
+ log .debug ("In-app WAF initialization failed. See previous log entries" );
73
+ return ;
74
+ }
68
75
REPLACEABLE_EVENT_PRODUCER = new ReplaceableEventProducerService ();
69
76
EventDispatcher eventDispatcher = new EventDispatcher ();
70
77
REPLACEABLE_EVENT_PRODUCER .replaceEventProducerService (eventDispatcher );
@@ -86,7 +93,8 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
86
93
APP_SEC_CONFIG_SERVICE =
87
94
new AppSecConfigServiceImpl (
88
95
config , configurationPoller , () -> reloadSubscriptions (REPLACEABLE_EVENT_PRODUCER ));
89
- APP_SEC_CONFIG_SERVICE .init ();
96
+ wafBuilder = new WafBuilder (createWafConfig (config ));
97
+ APP_SEC_CONFIG_SERVICE .init (wafBuilder );
90
98
91
99
sco .createRemaining (config );
92
100
@@ -105,7 +113,7 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
105
113
106
114
setActive (appSecEnabledConfig == ProductActivation .FULLY_ENABLED );
107
115
108
- APP_SEC_CONFIG_SERVICE .maybeSubscribeConfigPolling ();
116
+ APP_SEC_CONFIG_SERVICE .maybeSubscribeConfigPolling (wafBuilder );
109
117
110
118
Blocking .setBlockingService (new BlockingServiceImpl (REPLACEABLE_EVENT_PRODUCER ));
111
119
@@ -143,8 +151,8 @@ public static void stop() {
143
151
RESET_SUBSCRIPTION_SERVICE = null ;
144
152
}
145
153
Blocking .setBlockingService (BlockingService .NOOP );
146
-
147
154
APP_SEC_CONFIG_SERVICE .close ();
155
+ wafBuilder .destroy ();
148
156
}
149
157
150
158
private static void loadModules (EventDispatcher eventDispatcher , Monitoring monitoring ) {
@@ -155,9 +163,9 @@ private static void loadModules(EventDispatcher eventDispatcher, Monitoring moni
155
163
for (AppSecModule module : modules ) {
156
164
log .debug ("Starting appsec module {}" , module .getName ());
157
165
try {
158
- AppSecConfigService .TransactionalAppSecModuleConfigurer cfgObject ;
159
- cfgObject = APP_SEC_CONFIG_SERVICE .createAppSecModuleConfigurer ();
160
- module .config (cfgObject );
166
+ AppSecConfigService .TransactionalAppSecModuleConfigurer cfgObject =
167
+ APP_SEC_CONFIG_SERVICE .createAppSecModuleConfigurer ();
168
+ module .config (cfgObject , wafBuilder );
161
169
cfgObject .commit ();
162
170
} catch (RuntimeException | AppSecModule .AppSecModuleActivationException t ) {
163
171
log .error ("Startup of appsec module {} failed" , module .getName (), t );
@@ -209,4 +217,21 @@ public static Set<String> getStartedModulesInfo() {
209
217
return Collections .emptySet ();
210
218
}
211
219
}
220
+
221
+ private static WafConfig createWafConfig (Config config ) {
222
+ WafConfig wafConfig = new WafConfig ();
223
+ String keyRegexp = config .getAppSecObfuscationParameterKeyRegexp ();
224
+ if (keyRegexp != null ) {
225
+ wafConfig .obfuscatorKeyRegex = keyRegexp ;
226
+ } else { // reset
227
+ wafConfig .obfuscatorKeyRegex = WafConfig .DEFAULT_KEY_REGEX ;
228
+ }
229
+ String valueRegexp = config .getAppSecObfuscationParameterValueRegexp ();
230
+ if (valueRegexp != null ) {
231
+ wafConfig .obfuscatorValueRegex = valueRegexp ;
232
+ } else { // reset
233
+ wafConfig .obfuscatorValueRegex = WafConfig .DEFAULT_VALUE_REGEX ;
234
+ }
235
+ return wafConfig ;
236
+ }
212
237
}
0 commit comments