77import com .datadog .appsec .config .AppSecConfigService ;
88import com .datadog .appsec .config .AppSecConfigServiceImpl ;
99import com .datadog .appsec .ddwaf .WAFModule ;
10+ import com .datadog .appsec .ddwaf .WafInitialization ;
1011import com .datadog .appsec .event .EventDispatcher ;
1112import com .datadog .appsec .event .ReplaceableEventProducerService ;
1213import com .datadog .appsec .gateway .GatewayBridge ;
1314import com .datadog .appsec .util .AbortStartupException ;
1415import com .datadog .appsec .util .StandardizedLogging ;
16+ import com .datadog .ddwaf .WafBuilder ;
17+ import com .datadog .ddwaf .WafConfig ;
1518import datadog .appsec .api .blocking .Blocking ;
1619import datadog .appsec .api .blocking .BlockingService ;
1720import datadog .communication .ddagent .SharedCommunicationObjects ;
@@ -43,6 +46,7 @@ public class AppSecSystem {
4346 private static ReplaceableEventProducerService REPLACEABLE_EVENT_PRODUCER ; // testing
4447 private static Runnable STOP_SUBSCRIPTION_SERVICE ;
4548 private static Runnable RESET_SUBSCRIPTION_SERVICE ;
49+ private static WafBuilder wafBuilder ;
4650
4751 public static void start (SubscriptionService gw , SharedCommunicationObjects sco ) {
4852 try {
@@ -64,7 +68,10 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
6468 return ;
6569 }
6670 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+ }
6875 REPLACEABLE_EVENT_PRODUCER = new ReplaceableEventProducerService ();
6976 EventDispatcher eventDispatcher = new EventDispatcher ();
7077 REPLACEABLE_EVENT_PRODUCER .replaceEventProducerService (eventDispatcher );
@@ -82,10 +89,14 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
8289 }
8390
8491 ConfigurationPoller configurationPoller = sco .configurationPoller (config );
92+ wafBuilder = new WafBuilder (createWafConfig (config ));
8593 // may throw and abort startup
8694 APP_SEC_CONFIG_SERVICE =
8795 new AppSecConfigServiceImpl (
88- config , configurationPoller , () -> reloadSubscriptions (REPLACEABLE_EVENT_PRODUCER ));
96+ config ,
97+ configurationPoller ,
98+ () -> reloadSubscriptions (REPLACEABLE_EVENT_PRODUCER ),
99+ wafBuilder );
89100 APP_SEC_CONFIG_SERVICE .init ();
90101
91102 sco .createRemaining (config );
@@ -143,8 +154,8 @@ public static void stop() {
143154 RESET_SUBSCRIPTION_SERVICE = null ;
144155 }
145156 Blocking .setBlockingService (BlockingService .NOOP );
146-
147157 APP_SEC_CONFIG_SERVICE .close ();
158+ wafBuilder .destroy ();
148159 }
149160
150161 private static void loadModules (EventDispatcher eventDispatcher , Monitoring monitoring ) {
@@ -155,9 +166,9 @@ private static void loadModules(EventDispatcher eventDispatcher, Monitoring moni
155166 for (AppSecModule module : modules ) {
156167 log .debug ("Starting appsec module {}" , module .getName ());
157168 try {
158- AppSecConfigService .TransactionalAppSecModuleConfigurer cfgObject ;
159- cfgObject = APP_SEC_CONFIG_SERVICE .createAppSecModuleConfigurer ();
160- module .config (cfgObject );
169+ AppSecConfigService .TransactionalAppSecModuleConfigurer cfgObject =
170+ APP_SEC_CONFIG_SERVICE .createAppSecModuleConfigurer ();
171+ module .config (cfgObject , wafBuilder );
161172 cfgObject .commit ();
162173 } catch (RuntimeException | AppSecModule .AppSecModuleActivationException t ) {
163174 log .error ("Startup of appsec module {} failed" , module .getName (), t );
@@ -209,4 +220,21 @@ public static Set<String> getStartedModulesInfo() {
209220 return Collections .emptySet ();
210221 }
211222 }
223+
224+ private static WafConfig createWafConfig (Config config ) {
225+ WafConfig wafConfig = new WafConfig ();
226+ String keyRegexp = config .getAppSecObfuscationParameterKeyRegexp ();
227+ if (keyRegexp != null ) {
228+ wafConfig .obfuscatorKeyRegex = keyRegexp ;
229+ } else { // reset
230+ wafConfig .obfuscatorKeyRegex = WafConfig .DEFAULT_KEY_REGEX ;
231+ }
232+ String valueRegexp = config .getAppSecObfuscationParameterValueRegexp ();
233+ if (valueRegexp != null ) {
234+ wafConfig .obfuscatorValueRegex = valueRegexp ;
235+ } else { // reset
236+ wafConfig .obfuscatorValueRegex = WafConfig .DEFAULT_VALUE_REGEX ;
237+ }
238+ return wafConfig ;
239+ }
212240}
0 commit comments