Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/goose/src/agents/tool_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Agent {
// Log user decision if this was a security alert
if let Some(finding_id) = get_security_finding_id_from_results(&request.id, inspection_results) {
tracing::info!(
counter.goose.prompt_injection_user_decisions = 1,
monotonic_counter.goose.prompt_injection_user_decisions = 1,
decision = ?confirmation.permission,
finding_id = %finding_id,
tool_request_id = %request.id,
Expand Down
24 changes: 19 additions & 5 deletions crates/goose/src/security/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,34 @@ impl SecurityManager {
) -> Result<Vec<SecurityResult>> {
if !self.is_prompt_injection_detection_enabled() {
tracing::debug!(
counter.goose.prompt_injection_scanner_disabled = 1,
monotonic_counter.goose.prompt_injection_scanner_disabled = 1,
"Security scanning disabled"
);
return Ok(vec![]);
}

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 },
Comment on lines +80 to +81
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using monotonic_counter.* = if enabled { 1 } else { 0 } is likely to produce confusing metrics (a counter with value 0 is typically a no-op and the name suggests a gauge); consider logging the booleans as normal fields (e.g. command_classifier_enabled = ...) and emitting a separate monotonic_counter metric with value 1 (or separate enabled/disabled counters) so disabled configurations are still observable.

Suggested change
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 },
monotonic_counter.goose.security_classifier_configuration_logged = 1,
security_command_classifier_enabled = command_classifier_enabled,
security_prompt_classifier_enabled = prompt_classifier_enabled,

Copilot uses AI. Check for mistakes.
"Security classifier configuration"
);

let ml_enabled = self.is_ml_scanning_enabled();

let scanner = if ml_enabled {
match PromptInjectionScanner::with_ml_detection() {
Ok(s) => {
tracing::info!(
counter.goose.prompt_injection_scanner_enabled = 1,
monotonic_counter.goose.prompt_injection_scanner_enabled = 1,
"Security scanner initialized with ML-based detection"
);
s
Expand All @@ -90,7 +104,7 @@ impl SecurityManager {
}
} else {
tracing::info!(
counter.goose.prompt_injection_scanner_enabled = 1,
monotonic_counter.goose.prompt_injection_scanner_enabled = 1,
"Security scanner initialized with pattern-based detection only"
);
PromptInjectionScanner::new()
Expand Down Expand Up @@ -124,7 +138,7 @@ impl SecurityManager {
serde_json::to_string(&tool_call).unwrap_or_else(|_| "{}".to_string());

tracing::warn!(
counter.goose.prompt_injection_finding = 1,
monotonic_counter.goose.prompt_injection_finding = 1,
threat_type = "command_injection",
above_threshold = above_threshold,
tool_name = %tool_call.name,
Expand Down Expand Up @@ -164,7 +178,7 @@ impl SecurityManager {
}

tracing::info!(
counter.goose.prompt_injection_analysis_performed = 1,
monotonic_counter.goose.prompt_injection_analysis_performed = 1,
security_issues_found = results.len(),
"Prompt injection detection: Security analysis complete"
);
Expand Down
13 changes: 10 additions & 3 deletions crates/goose/src/security/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct DetailedScanResult {
confidence: f32,
pattern_matches: Vec<PatternMatch>,
ml_confidence: Option<f32>,
used_pattern_detection: bool,
}

pub struct PromptInjectionScanner {
Expand Down Expand Up @@ -160,9 +161,9 @@ impl PromptInjectionScanner {
tool_confidence = %tool_result.confidence,
context_confidence = ?context_result.ml_confidence,
final_confidence = %final_confidence,
has_command_ml = tool_result.ml_confidence.is_some(),
has_prompt_ml = context_result.ml_confidence.is_some(),
has_patterns = !tool_result.pattern_matches.is_empty(),
used_command_ml = tool_result.ml_confidence.is_some(),
used_prompt_ml = context_result.ml_confidence.is_some(),
used_pattern_detection = tool_result.used_pattern_detection,
threshold = %threshold,
malicious = final_confidence >= threshold,
"Security analysis complete"
Expand All @@ -172,6 +173,7 @@ impl PromptInjectionScanner {
confidence: final_confidence,
pattern_matches: tool_result.pattern_matches,
ml_confidence: tool_result.ml_confidence,
used_pattern_detection: tool_result.used_pattern_detection,
};

Ok(ScanResult {
Expand All @@ -191,6 +193,7 @@ impl PromptInjectionScanner {
confidence: ml_confidence,
pattern_matches: Vec::new(),
ml_confidence: Some(ml_confidence),
used_pattern_detection: false,
});
}
}
Expand All @@ -200,6 +203,7 @@ impl PromptInjectionScanner {
confidence: pattern_confidence,
pattern_matches,
ml_confidence: None,
used_pattern_detection: true,
})
}

Expand All @@ -211,6 +215,7 @@ impl PromptInjectionScanner {
confidence: 0.0,
pattern_matches: Vec::new(),
ml_confidence: None,
used_pattern_detection: false,
});
};

Expand All @@ -219,6 +224,7 @@ impl PromptInjectionScanner {
confidence: 0.0,
pattern_matches: Vec::new(),
ml_confidence: None,
used_pattern_detection: false,
});
}

Expand All @@ -237,6 +243,7 @@ impl PromptInjectionScanner {
confidence: max_confidence,
pattern_matches: Vec::new(),
ml_confidence: Some(max_confidence),
used_pattern_detection: false,
})
Comment on lines 243 to 247
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scan_conversation always sets ml_confidence: Some(max_confidence) even if every classifier call failed (all scan_with_classifier results were None), which makes downstream logic treat this as a real ML signal (and currently reduces tool_confidence by 10% when the value is 0.0). Track whether any classification succeeded (e.g., fold an Option<f32> or keep a success flag) and return ml_confidence: None when there were no successful results.

Copilot uses AI. Check for mistakes.
}

Expand Down
Loading