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 );
@@ -82,10 +89,14 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s
82
89
}
83
90
84
91
ConfigurationPoller configurationPoller = sco .configurationPoller (config );
92
+ wafBuilder = new WafBuilder (createWafConfig (config ));
85
93
// may throw and abort startup
86
94
APP_SEC_CONFIG_SERVICE =
87
95
new AppSecConfigServiceImpl (
88
- config , configurationPoller , () -> reloadSubscriptions (REPLACEABLE_EVENT_PRODUCER ));
96
+ config ,
97
+ configurationPoller ,
98
+ () -> reloadSubscriptions (REPLACEABLE_EVENT_PRODUCER ),
99
+ wafBuilder );
89
100
APP_SEC_CONFIG_SERVICE .init ();
90
101
91
102
sco .createRemaining (config );
@@ -143,8 +154,8 @@ public static void stop() {
143
154
RESET_SUBSCRIPTION_SERVICE = null ;
144
155
}
145
156
Blocking .setBlockingService (BlockingService .NOOP );
146
-
147
157
APP_SEC_CONFIG_SERVICE .close ();
158
+ wafBuilder .destroy ();
148
159
}
149
160
150
161
private static void loadModules (EventDispatcher eventDispatcher , Monitoring monitoring ) {
@@ -155,9 +166,9 @@ private static void loadModules(EventDispatcher eventDispatcher, Monitoring moni
155
166
for (AppSecModule module : modules ) {
156
167
log .debug ("Starting appsec module {}" , module .getName ());
157
168
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 );
161
172
cfgObject .commit ();
162
173
} catch (RuntimeException | AppSecModule .AppSecModuleActivationException t ) {
163
174
log .error ("Startup of appsec module {} failed" , module .getName (), t );
@@ -209,4 +220,21 @@ public static Set<String> getStartedModulesInfo() {
209
220
return Collections .emptySet ();
210
221
}
211
222
}
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
+ }
212
240
}
0 commit comments