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
+10 -5
View File
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useState, useRef } from 'react';
import { createRecipe, Recipe } from '../recipe';
import { createRecipe, Recipe, scanRecipe } from '../recipe';
import { Message, createUserMessage } from '../types/message';
import { updateSystemPromptWithParameters } from '../utils/providerUtils';
import { useChatContext } from '../contexts/ChatContext';
@@ -17,6 +17,7 @@ export const useRecipeManager = (messages: Message[], locationState?: LocationSt
const [recipeError, setRecipeError] = useState<string | null>(null);
const [isRecipeWarningModalOpen, setIsRecipeWarningModalOpen] = useState(false);
const [recipeAccepted, setRecipeAccepted] = useState(false);
const [hasSecurityWarnings, setHasSecurityWarnings] = useState(false);
// Get chat context to access persisted recipe and parameters
const chatContext = useChatContext();
@@ -78,20 +79,23 @@ export const useRecipeManager = (messages: Message[], locationState?: LocationSt
}
}, [chatContext, locationState]);
// Check if recipe has been accepted before
// Check if recipe has been accepted before and scan for security warnings
useEffect(() => {
const checkRecipeAcceptance = async () => {
if (recipeConfig) {
try {
const hasAccepted = await window.electron.hasAcceptedRecipeBefore(recipeConfig);
if (!hasAccepted) {
const securityScanResult = await scanRecipe(recipeConfig);
setHasSecurityWarnings(securityScanResult.has_security_warnings);
setIsRecipeWarningModalOpen(true);
} else {
setRecipeAccepted(true);
}
} catch (error) {
console.error('Error checking recipe acceptance:', error);
// If there's an error, assume the recipe hasn't been accepted
} catch {
setHasSecurityWarnings(false);
setIsRecipeWarningModalOpen(true);
}
}
@@ -311,5 +315,6 @@ export const useRecipeManager = (messages: Message[], locationState?: LocationSt
recipeAccepted,
handleRecipeAccept,
handleRecipeCancel,
hasSecurityWarnings,
};
};