feat: block official provider switching during proxy takeover

Prevent users from switching to official providers (Anthropic/OpenAI/Google)
when proxy takeover is active, as using a proxy with official APIs may cause
account bans.

Defense-in-depth across 4 layers:
- Backend: ProviderService::switch(), hot_switch_provider(), switch_proxy_provider command
- Frontend: useProviderActions soft guard with error toast
- UI: ProviderActions button disabled with ShieldAlert icon
- Tray menu: official provider items disabled with  indicator

Also warns when enabling proxy takeover while current provider is official.
This commit is contained in:
Jason
2026-04-11 11:43:49 +08:00
parent 2937eb6766
commit a514f27937
11 changed files with 158 additions and 8 deletions
+25 -2
View File
@@ -23,7 +23,11 @@ import { openclawKeys } from "@/hooks/useOpenClaw";
* Hook for managing provider actions (add, update, delete, switch)
* Extracts business logic from App.tsx
*/
export function useProviderActions(activeApp: AppId, isProxyRunning?: boolean) {
export function useProviderActions(
activeApp: AppId,
isProxyRunning?: boolean,
isProxyTakeover?: boolean,
) {
const { t } = useTranslation();
const queryClient = useQueryClient();
@@ -185,6 +189,18 @@ export function useProviderActions(activeApp: AppId, isProxyRunning?: boolean) {
);
}
// Block official providers when proxy takeover is active
if (isProxyTakeover && provider.category === "official") {
toast.error(
t("notifications.officialBlockedByProxy", {
defaultValue:
"代理接管模式下不能切换到官方供应商,使用代理访问官方 API 可能导致账号被封禁",
}),
{ duration: 6000 },
);
return;
}
try {
const result = await switchProviderMutation.mutateAsync(provider.id);
await syncClaudePlugin(provider);
@@ -220,7 +236,14 @@ export function useProviderActions(activeApp: AppId, isProxyRunning?: boolean) {
// 错误提示由 mutation 处理
}
},
[switchProviderMutation, syncClaudePlugin, activeApp, isProxyRunning, t],
[
switchProviderMutation,
syncClaudePlugin,
activeApp,
isProxyRunning,
isProxyTakeover,
t,
],
);
// 删除供应商