Skip to content

Commit 2a7c56b

Browse files
cataphractclaude
andcommitted
helper-rust: restore initial ruleset when ASM_DD config addition fails; fix racy telemetry log test
updateable_waf: when an ASM_DD config fails to be added to the builder, restore the initial ruleset if it was removed, matching the existing restore logic in remove_config. TelemetryTests: wait for the specific bad_config diagnostic log rather than any 3 RC logs, avoiding a race where leftover exception logs from the previous test satisfy the condition before the diagnostic arrives. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8c88f39 commit 2a7c56b

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

appsec/helper-rust/src/service/updateable_waf.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use libddwaf::{
66
Builder, Config, Handle,
77
};
88

9-
use crate::client::log::warning;
9+
use crate::{client::log::warning, error_once};
1010

1111
/// A WAF instance that can be shared (through clone()) and updated by any thread.
1212
///
@@ -104,14 +104,24 @@ impl UpdateableWafInstance {
104104
guard.initial_ruleset_added = false;
105105
let res = guard.builder.remove_config(Self::INITIAL_RULESET);
106106
if !res {
107-
warning!("Failed to remove initial ruleset: probably not present, but we it should have been");
107+
error_once!("Failed to remove initial ruleset: probably not present, but we it should have been");
108108
}
109109
}
110110

111111
let res = guard
112112
.builder
113113
.add_or_update_config(path, ruleset, diagnostics);
114114
if !res {
115+
if !guard.initial_ruleset_added && !Self::has_asm_dd_configs(&mut guard.builder) {
116+
guard.initial_ruleset_added = true;
117+
if !guard.builder.add_or_update_config(
118+
Self::INITIAL_RULESET,
119+
&self.inner.initial_ruleset,
120+
None,
121+
) {
122+
error_once!("Failed to restore initial ruleset after failed config addition");
123+
}
124+
}
115125
anyhow::bail!("Failed to add/update config {path}");
116126
}
117127
Ok(())

appsec/tests/integration/src/test/groovy/com/datadog/appsec/php/integration/TelemetryTests.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class TelemetryTests {
357357

358358
def messages = TelemetryHelpers.waitForLogs(CONTAINER, 30) { List<TelemetryHelpers.Logs> logs ->
359359
def relevantLogs = logs.collectMany { it.logs.findAll { it.tags.contains('log_type:rc::') } }
360-
relevantLogs.size() >= 3
360+
relevantLogs.any { it.tags.contains('rc_config_id:bad_config') }
361361
}.collectMany { it.logs }
362362

363363
assert requestSup.get() != null

0 commit comments

Comments
 (0)