-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Classifier model command injection detection in tool calls #6599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dorien-koelemeijer
merged 15 commits into
main
from
feat/command-injection-detection-tool-calls
Jan 27, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fec954d
first commit - still messy, needs to be cleaned up
dorien-koelemeijer 15cd7f2
save wip - fixes to be made, average confidence score determination i…
dorien-koelemeijer 1b29b0a
Specify 'model_type' in model mapping dict so we can distinguish betw…
dorien-koelemeijer 03632f7
formatting changes (not sure why)
dorien-koelemeijer 5da2df0
Frontend change to allow OSS users to provide endpoint and token for …
dorien-koelemeijer 700f9a6
mini cleanup
dorien-koelemeijer 88f83da
fix log levels
dorien-koelemeijer d28e74f
minor fix - copilot comments
dorien-koelemeijer d79a6bd
fmt
dorien-koelemeijer 0aa9cf4
Fix build failures
dorien-koelemeijer b28ae56
fix
dorien-koelemeijer a540bf2
Only evaluate developer__shell tool calls
dorien-koelemeijer b13dfcb
small fixes
dorien-koelemeijer 4bc98a7
revert some changes to make code review little easier
dorien-koelemeijer 028effb
more cleanup - not tested yet
dorien-koelemeijer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ type ClassificationResponse = Vec<Vec<ClassificationLabel>>; | |
| #[derive(Debug, Deserialize, Clone)] | ||
| pub struct ModelEndpointInfo { | ||
| pub endpoint: String, | ||
| pub model_type: Option<String>, | ||
| #[serde(flatten)] | ||
| pub extra_params: HashMap<String, serde_json::Value>, | ||
| } | ||
|
|
@@ -75,7 +76,7 @@ impl ClassificationClient { | |
| model_name | ||
| ))?; | ||
|
|
||
| tracing::info!( | ||
| tracing::debug!( | ||
| model_name = %model_name, | ||
| endpoint = %model_info.endpoint, | ||
| extra_params = ?model_info.extra_params, | ||
|
|
@@ -90,6 +91,30 @@ impl ClassificationClient { | |
| ) | ||
| } | ||
|
|
||
| pub fn from_model_type(model_type: &str, timeout_ms: Option<u64>) -> Result<Self> { | ||
| let mapping = serde_json::from_str::<ModelMappingConfig>( | ||
| &std::env::var("SECURITY_ML_MODEL_MAPPING") | ||
| .context("SECURITY_ML_MODEL_MAPPING environment variable not set")?, | ||
| ) | ||
| .context("Failed to parse SECURITY_ML_MODEL_MAPPING JSON")?; | ||
|
|
||
| let (_, model_info) = mapping | ||
| .models | ||
| .iter() | ||
| .find(|(_, info)| info.model_type.as_deref() == Some(model_type)) | ||
| .context(format!( | ||
| "No model with type '{}' found in SECURITY_ML_MODEL_MAPPING", | ||
| model_type | ||
| ))?; | ||
dorien-koelemeijer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Self::new( | ||
| model_info.endpoint.clone(), | ||
| timeout_ms, | ||
| None, | ||
| Some(model_info.extra_params.clone()), | ||
| ) | ||
| } | ||
|
Comment on lines
+94
to
+116
|
||
|
|
||
| pub fn from_endpoint( | ||
| endpoint_url: String, | ||
| timeout_ms: Option<u64>, | ||
|
|
@@ -104,7 +129,7 @@ impl ClassificationClient { | |
| .map(|t| t.trim().to_string()) | ||
| .filter(|t| !t.is_empty()); | ||
|
|
||
| tracing::info!( | ||
| tracing::debug!( | ||
| endpoint = %endpoint_url, | ||
| has_token = auth_token.is_some(), | ||
| "Creating classification client from endpoint" | ||
|
|
@@ -114,12 +139,6 @@ impl ClassificationClient { | |
| } | ||
|
|
||
| pub async fn classify(&self, text: &str) -> Result<f32> { | ||
| tracing::debug!( | ||
| endpoint = %self.endpoint_url, | ||
| text_length = text.len(), | ||
| "Sending classification request" | ||
| ); | ||
|
|
||
| let parameters = self | ||
| .extra_params | ||
| .as_ref() | ||
|
|
@@ -197,14 +216,6 @@ impl ClassificationClient { | |
| } | ||
| }; | ||
|
|
||
| tracing::info!( | ||
| injection_score = %injection_score, | ||
| top_label = %top_label.label, | ||
| top_score = %top_label.score, | ||
| normalized = !is_probabilities, | ||
| "Classification complete" | ||
| ); | ||
|
|
||
| Ok(injection_score) | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.