fix: redact secrets in set_global_setting log line (#8270)

This commit is contained in:
Ruben Fiszel
2026-03-09 18:28:10 +00:00
committed by GitHub
parent 874273d0b7
commit e6bb26d0a4
2 changed files with 25 additions and 2 deletions
+5 -1
View File
@@ -316,7 +316,11 @@ pub async fn set_global_setting_internal(
)
.execute(db)
.await?;
tracing::info!("Set global setting {} to {}", key, v);
tracing::info!(
"Set global setting {} to {}",
key,
instance_config::format_setting_value(&key, &v)
);
}
};
+20 -1
View File
@@ -934,7 +934,7 @@ fn redact_string(s: &str) -> String {
}
}
fn format_setting_value(key: &str, value: &serde_json::Value) -> String {
pub fn format_setting_value(key: &str, value: &serde_json::Value) -> String {
if SENSITIVE_SETTINGS.contains(&key) {
return match value {
serde_json::Value::String(s) => format!("\"{}\"", redact_string(s)),
@@ -2219,6 +2219,25 @@ mod tests {
assert_eq!(v, *"world");
}
#[test]
fn string_or_secret_ref_debug_masks_literal() {
let v = StringOrSecretRef::Literal("super-secret-value".to_string());
let debug = format!("{v:?}");
assert_eq!(debug, "Literal(****)");
assert!(!debug.contains("super-secret-value"));
}
#[test]
fn format_setting_value_redacts_oauth_secrets() {
let val = serde_json::json!({
"google": {"id": "client-id", "secret": "my-super-secret-12345"}
});
let formatted = format_setting_value("oauths", &val);
assert!(!formatted.contains("my-super-secret-12345"));
assert!(formatted.contains("client-id"));
assert!(formatted.contains("****"));
}
#[test]
#[should_panic(expected = "literal_value() called on unresolved secret ref")]
fn string_or_secret_ref_literal_value_panics_on_ref() {