Desktop alerts when suspicious unicode characters found in Recipe (#4080)

This commit is contained in:
Amed Rodriguez
2025-08-19 14:05:46 -07:00
committed by GitHub
parent 33bf5a44ed
commit 4f4e8ace33
11 changed files with 256 additions and 15 deletions
+4 -1
View File
@@ -389,7 +389,8 @@ impl<'__s> ToSchema<'__s> for AnnotatedSchema {
super::routes::schedule::sessions_handler,
super::routes::recipe::create_recipe,
super::routes::recipe::encode_recipe,
super::routes::recipe::decode_recipe
super::routes::recipe::decode_recipe,
super::routes::recipe::scan_recipe
),
components(schemas(
super::routes::config_management::UpsertConfigQuery,
@@ -456,6 +457,8 @@ impl<'__s> ToSchema<'__s> for AnnotatedSchema {
super::routes::recipe::EncodeRecipeResponse,
super::routes::recipe::DecodeRecipeRequest,
super::routes::recipe::DecodeRecipeResponse,
super::routes::recipe::ScanRecipeRequest,
super::routes::recipe::ScanRecipeResponse,
goose::recipe::Recipe,
goose::recipe::Author,
goose::recipe::Settings,
+30
View File
@@ -56,6 +56,16 @@ pub struct DecodeRecipeResponse {
recipe: Recipe,
}
#[derive(Debug, Deserialize, ToSchema)]
pub struct ScanRecipeRequest {
recipe: Recipe,
}
#[derive(Debug, Serialize, ToSchema)]
pub struct ScanRecipeResponse {
has_security_warnings: bool,
}
#[utoipa::path(
post,
path = "/recipes/create",
@@ -164,11 +174,31 @@ async fn decode_recipe(
}
}
#[utoipa::path(
post,
path = "/recipes/scan",
request_body = ScanRecipeRequest,
responses(
(status = 200, description = "Recipe scanned successfully", body = ScanRecipeResponse),
),
tag = "Recipe Management"
)]
async fn scan_recipe(
Json(request): Json<ScanRecipeRequest>,
) -> Result<Json<ScanRecipeResponse>, StatusCode> {
let has_security_warnings = request.recipe.check_for_security_warnings();
Ok(Json(ScanRecipeResponse {
has_security_warnings,
}))
}
pub fn routes(state: Arc<AppState>) -> Router {
Router::new()
.route("/recipes/create", post(create_recipe))
.route("/recipes/encode", post(encode_recipe))
.route("/recipes/decode", post(decode_recipe))
.route("/recipes/scan", post(scan_recipe))
.with_state(state)
}