@@ -102,11 +102,12 @@ public class AppSecConfigServiceImpl implements AppSecConfigService {
102102 private final AtomicBoolean subscribedToRulesAndData = new AtomicBoolean ();
103103 private final Set <String > usedDDWafConfigKeys =
104104 Collections .newSetFromMap (new ConcurrentHashMap <>());
105- private final Set <String > emptyConfigKeys = Collections .newSetFromMap (new ConcurrentHashMap <>());
105+ private final Set <String > ignoredConfigKeys =
106+ Collections .newSetFromMap (new ConcurrentHashMap <>());
106107 private final String DEFAULT_WAF_CONFIG_RULE = "DEFAULT_WAF_CONFIG" ;
107108 private String currentRuleVersion ;
108109 private List <AppSecModule > modulesToUpdateVersionIn ;
109- private long rulesAndDataCapabilities ;
110+ private long rulesAndDataCapabilities = - 1L ;
110111
111112 public AppSecConfigServiceImpl (
112113 Config tracerConfig ,
@@ -135,32 +136,34 @@ private void subscribeConfigurationPoller() {
135136 }
136137
137138 private long buildRulesAndDataCapabilities () {
138- long capabilities =
139- CAPABILITY_ASM_DD_RULES
140- | CAPABILITY_ASM_IP_BLOCKING
141- | CAPABILITY_ASM_EXCLUSIONS
142- | CAPABILITY_ASM_EXCLUSION_DATA
143- | CAPABILITY_ASM_REQUEST_BLOCKING
144- | CAPABILITY_ASM_USER_BLOCKING
145- | CAPABILITY_ASM_CUSTOM_RULES
146- | CAPABILITY_ASM_CUSTOM_BLOCKING_RESPONSE
147- | CAPABILITY_ASM_TRUSTED_IPS
148- | CAPABILITY_ENDPOINT_FINGERPRINT
149- | CAPABILITY_ASM_SESSION_FINGERPRINT
150- | CAPABILITY_ASM_NETWORK_FINGERPRINT
151- | CAPABILITY_ASM_HEADER_FINGERPRINT ;
152- if (tracerConfig .isAppSecRaspEnabled ()) {
153- capabilities |= CAPABILITY_ASM_RASP_SQLI ;
154- capabilities |= CAPABILITY_ASM_RASP_SSRF ;
155- capabilities |= CAPABILITY_ASM_RASP_CMDI ;
156- capabilities |= CAPABILITY_ASM_RASP_SHI ;
157- // RASP LFI is only available in fully enabled mode as it's implemented using callsite
158- // instrumentation
159- if (tracerConfig .getAppSecActivation () == ProductActivation .FULLY_ENABLED ) {
160- capabilities |= CAPABILITY_ASM_RASP_LFI ;
139+ if (rulesAndDataCapabilities == -1 ) {
140+ rulesAndDataCapabilities =
141+ CAPABILITY_ASM_DD_RULES
142+ | CAPABILITY_ASM_IP_BLOCKING
143+ | CAPABILITY_ASM_EXCLUSIONS
144+ | CAPABILITY_ASM_EXCLUSION_DATA
145+ | CAPABILITY_ASM_REQUEST_BLOCKING
146+ | CAPABILITY_ASM_USER_BLOCKING
147+ | CAPABILITY_ASM_CUSTOM_RULES
148+ | CAPABILITY_ASM_CUSTOM_BLOCKING_RESPONSE
149+ | CAPABILITY_ASM_TRUSTED_IPS
150+ | CAPABILITY_ENDPOINT_FINGERPRINT
151+ | CAPABILITY_ASM_SESSION_FINGERPRINT
152+ | CAPABILITY_ASM_NETWORK_FINGERPRINT
153+ | CAPABILITY_ASM_HEADER_FINGERPRINT ;
154+ if (tracerConfig .isAppSecRaspEnabled ()) {
155+ rulesAndDataCapabilities |= CAPABILITY_ASM_RASP_SQLI ;
156+ rulesAndDataCapabilities |= CAPABILITY_ASM_RASP_SSRF ;
157+ rulesAndDataCapabilities |= CAPABILITY_ASM_RASP_CMDI ;
158+ rulesAndDataCapabilities |= CAPABILITY_ASM_RASP_SHI ;
159+ // RASP LFI is only available in fully enabled mode as it's implemented using callsite
160+ // instrumentation
161+ if (tracerConfig .getAppSecActivation () == ProductActivation .FULLY_ENABLED ) {
162+ rulesAndDataCapabilities |= CAPABILITY_ASM_RASP_LFI ;
163+ }
161164 }
162165 }
163- return capabilities ;
166+ return rulesAndDataCapabilities ;
164167 }
165168
166169 private void updateRulesAndDataSubscription () {
@@ -179,7 +182,7 @@ private void subscribeRulesAndData() {
179182 this .configurationPoller .addListener (Product .ASM_DD , new AppSecConfigChangesDDListener ());
180183 this .configurationPoller .addListener (Product .ASM_DATA , new AppSecConfigChangesListener ());
181184 this .configurationPoller .addListener (Product .ASM , new AppSecConfigChangesListener ());
182- this .configurationPoller .addCapabilities (rulesAndDataCapabilities );
185+ this .configurationPoller .addCapabilities (buildRulesAndDataCapabilities () );
183186 }
184187 }
185188
@@ -188,7 +191,7 @@ private void unsubscribeRulesAndData() {
188191 this .configurationPoller .removeListeners (Product .ASM_DD );
189192 this .configurationPoller .removeListeners (Product .ASM_DATA );
190193 this .configurationPoller .removeListeners (Product .ASM );
191- this .configurationPoller .removeCapabilities (rulesAndDataCapabilities );
194+ this .configurationPoller .removeCapabilities (buildRulesAndDataCapabilities () );
192195 }
193196 }
194197
@@ -204,35 +207,39 @@ private class AppSecConfigChangesListener implements ProductListener {
204207 @ Override
205208 public void accept (ConfigKey configKey , byte [] content , PollingRateHinter pollingRateHinter )
206209 throws IOException {
207- maybeInitializeDefaultConfig ();
208210 final String key = configKey .toString ();
209211 if (content == null ) {
210- if (! emptyConfigKeys . remove (key )) {
211- try {
212- wafBuilder . removeConfig ( key );
213- } catch ( UnclassifiedWafException e ) {
214- throw new RuntimeException ( e );
215- }
216- }
212+ remove (configKey , pollingRateHinter );
213+ return ;
214+ }
215+ Map < String , Object > contentMap =
216+ ADAPTER . fromJson ( Okio . buffer ( Okio . source ( new ByteArrayInputStream ( content ))) );
217+ if ( contentMap == null || contentMap . isEmpty ()) {
218+ ignoredConfigKeys . add ( key );
217219 } else {
218- Map <String , Object > contentMap =
219- ADAPTER .fromJson (Okio .buffer (Okio .source (new ByteArrayInputStream (content ))));
220- if (contentMap == null || contentMap .isEmpty ()) {
221- emptyConfigKeys .add (key );
222- } else {
223- try {
224- handleWafUpdateResultReport (key , contentMap );
225- } catch (AppSecModule .AppSecModuleActivationException e ) {
226- throw new RuntimeException (e );
227- }
220+ ignoredConfigKeys .remove (key );
221+ try {
222+ maybeInitializeDefaultConfig ();
223+ handleWafUpdateResultReport (key , contentMap );
224+ } catch (AppSecModule .AppSecModuleActivationException e ) {
225+ throw new RuntimeException (e );
228226 }
229227 }
230228 }
231229
232230 @ Override
233231 public void remove (ConfigKey configKey , PollingRateHinter pollingRateHinter )
234232 throws IOException {
235- accept (configKey , null , pollingRateHinter );
233+ final String key = configKey .toString ();
234+ if (ignoredConfigKeys .remove (key )) {
235+ return ;
236+ }
237+ try {
238+ maybeInitializeDefaultConfig ();
239+ wafBuilder .removeConfig (key );
240+ } catch (UnclassifiedWafException e ) {
241+ throw new RuntimeException (e );
242+ }
236243 }
237244
238245 @ Override
@@ -375,7 +382,6 @@ public void init() {
375382 }
376383 this .mergedAsmFeatures .clear ();
377384 this .usedDDWafConfigKeys .clear ();
378- this .emptyConfigKeys .clear ();
379385 this .rulesAndDataCapabilities = buildRulesAndDataCapabilities ();
380386
381387 if (wafConfig .isEmpty ()) {
0 commit comments