Fix: Minor logging uplift for debugging of prompt injection mitigation (#7195)
This commit is contained in:
committed by
GitHub
parent
b26d7afe2e
commit
e32720fcfb
@@ -68,6 +68,20 @@ impl SecurityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let scanner = self.scanner.get_or_init(|| {
|
let scanner = self.scanner.get_or_init(|| {
|
||||||
|
let config = Config::global();
|
||||||
|
let command_classifier_enabled = config
|
||||||
|
.get_param::<bool>("SECURITY_COMMAND_CLASSIFIER_ENABLED")
|
||||||
|
.unwrap_or(false);
|
||||||
|
let prompt_classifier_enabled = config
|
||||||
|
.get_param::<bool>("SECURITY_PROMPT_CLASSIFIER_ENABLED")
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
tracing::info!(
|
||||||
|
monotonic_counter.goose.security_command_classifier_enabled = if command_classifier_enabled { 1 } else { 0 },
|
||||||
|
monotonic_counter.goose.security_prompt_classifier_enabled = if prompt_classifier_enabled { 1 } else { 0 },
|
||||||
|
"Security classifier configuration"
|
||||||
|
);
|
||||||
|
|
||||||
let ml_enabled = self.is_ml_scanning_enabled();
|
let ml_enabled = self.is_ml_scanning_enabled();
|
||||||
|
|
||||||
let scanner = if ml_enabled {
|
let scanner = if ml_enabled {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ struct DetailedScanResult {
|
|||||||
confidence: f32,
|
confidence: f32,
|
||||||
pattern_matches: Vec<PatternMatch>,
|
pattern_matches: Vec<PatternMatch>,
|
||||||
ml_confidence: Option<f32>,
|
ml_confidence: Option<f32>,
|
||||||
|
used_pattern_detection: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PromptInjectionScanner {
|
pub struct PromptInjectionScanner {
|
||||||
@@ -160,9 +161,9 @@ impl PromptInjectionScanner {
|
|||||||
tool_confidence = %tool_result.confidence,
|
tool_confidence = %tool_result.confidence,
|
||||||
context_confidence = ?context_result.ml_confidence,
|
context_confidence = ?context_result.ml_confidence,
|
||||||
final_confidence = %final_confidence,
|
final_confidence = %final_confidence,
|
||||||
has_command_ml = tool_result.ml_confidence.is_some(),
|
used_command_ml = tool_result.ml_confidence.is_some(),
|
||||||
has_prompt_ml = context_result.ml_confidence.is_some(),
|
used_prompt_ml = context_result.ml_confidence.is_some(),
|
||||||
has_patterns = !tool_result.pattern_matches.is_empty(),
|
used_pattern_detection = tool_result.used_pattern_detection,
|
||||||
threshold = %threshold,
|
threshold = %threshold,
|
||||||
malicious = final_confidence >= threshold,
|
malicious = final_confidence >= threshold,
|
||||||
"Security analysis complete"
|
"Security analysis complete"
|
||||||
@@ -172,6 +173,7 @@ impl PromptInjectionScanner {
|
|||||||
confidence: final_confidence,
|
confidence: final_confidence,
|
||||||
pattern_matches: tool_result.pattern_matches,
|
pattern_matches: tool_result.pattern_matches,
|
||||||
ml_confidence: tool_result.ml_confidence,
|
ml_confidence: tool_result.ml_confidence,
|
||||||
|
used_pattern_detection: tool_result.used_pattern_detection,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ScanResult {
|
Ok(ScanResult {
|
||||||
@@ -191,6 +193,7 @@ impl PromptInjectionScanner {
|
|||||||
confidence: ml_confidence,
|
confidence: ml_confidence,
|
||||||
pattern_matches: Vec::new(),
|
pattern_matches: Vec::new(),
|
||||||
ml_confidence: Some(ml_confidence),
|
ml_confidence: Some(ml_confidence),
|
||||||
|
used_pattern_detection: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,6 +203,7 @@ impl PromptInjectionScanner {
|
|||||||
confidence: pattern_confidence,
|
confidence: pattern_confidence,
|
||||||
pattern_matches,
|
pattern_matches,
|
||||||
ml_confidence: None,
|
ml_confidence: None,
|
||||||
|
used_pattern_detection: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +215,7 @@ impl PromptInjectionScanner {
|
|||||||
confidence: 0.0,
|
confidence: 0.0,
|
||||||
pattern_matches: Vec::new(),
|
pattern_matches: Vec::new(),
|
||||||
ml_confidence: None,
|
ml_confidence: None,
|
||||||
|
used_pattern_detection: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -219,6 +224,7 @@ impl PromptInjectionScanner {
|
|||||||
confidence: 0.0,
|
confidence: 0.0,
|
||||||
pattern_matches: Vec::new(),
|
pattern_matches: Vec::new(),
|
||||||
ml_confidence: None,
|
ml_confidence: None,
|
||||||
|
used_pattern_detection: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,6 +243,7 @@ impl PromptInjectionScanner {
|
|||||||
confidence: max_confidence,
|
confidence: max_confidence,
|
||||||
pattern_matches: Vec::new(),
|
pattern_matches: Vec::new(),
|
||||||
ml_confidence: Some(max_confidence),
|
ml_confidence: Some(max_confidence),
|
||||||
|
used_pattern_detection: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user