From e393dda68e1e863c74067daee6ed04bd268b0825 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Mon, 26 Jan 2026 15:55:58 +0800 Subject: [PATCH] fix(form): add type guard for Gemini env values Address code audit finding #10: Replace unsafe type assertion with proper type guard when extracting custom env config. Convert all values to strings explicitly using String() to prevent runtime type errors when env contains non-string values (numbers, booleans, etc). Before: envObj = customConfig as Record After: Iterate and convert each value with String(value) --- src/components/providers/forms/ProviderForm.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/providers/forms/ProviderForm.tsx b/src/components/providers/forms/ProviderForm.tsx index 0145b86f6..7fc02727d 100644 --- a/src/components/providers/forms/ProviderForm.tsx +++ b/src/components/providers/forms/ProviderForm.tsx @@ -944,7 +944,12 @@ export function ProviderForm({ const commonEnvObj = envStringToObj(geminiCommonConfigSnippet.trim()); if (isPlainObject(envObj) && isPlainObject(commonEnvObj)) { const { customConfig } = extractDifference(envObj, commonEnvObj); - envObj = customConfig as Record; + // Convert to string record with type guard to avoid type assertion issues + const stringEnvObj: Record = {}; + for (const [key, value] of Object.entries(customConfig)) { + stringEnvObj[key] = String(value); + } + envObj = stringEnvObj; } } const combined = {