From 6cf174c5ed4fa8ae440ef651305643919f5f0290 Mon Sep 17 00:00:00 2001 From: GyDi Date: Thu, 29 Jun 2023 14:15:57 +0800 Subject: [PATCH] fix: encodeURIComponent secret --- src/components/layout/layout-traffic.tsx | 2 +- src/components/setting/mods/web-ui-viewer.tsx | 5 ++++- src/pages/connections.tsx | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/layout/layout-traffic.tsx b/src/components/layout/layout-traffic.tsx index 97caa82..f97c6cf 100644 --- a/src/components/layout/layout-traffic.tsx +++ b/src/components/layout/layout-traffic.tsx @@ -46,7 +46,7 @@ const LayoutTraffic = () => { if (document.visibilityState === "visible") { // reconnect websocket const { server = "", secret = "" } = clashInfo; - connect(`ws://${server}/traffic?token=${secret}`); + connect(`ws://${server}/traffic?token=${encodeURIComponent(secret)}`); } else { disconnect(); } diff --git a/src/components/setting/mods/web-ui-viewer.tsx b/src/components/setting/mods/web-ui-viewer.tsx index ae1bf31..8588d3d 100644 --- a/src/components/setting/mods/web-ui-viewer.tsx +++ b/src/components/setting/mods/web-ui-viewer.tsx @@ -60,7 +60,10 @@ export const WebUIViewer = forwardRef((props, ref) => { .trim(); url = url.replaceAll("%port", port || "9090"); - url = url.replaceAll("%secret", clashInfo.secret || ""); + url = url.replaceAll( + "%secret", + encodeURIComponent(clashInfo.secret || "") + ); } await openWebUrl(url); diff --git a/src/pages/connections.tsx b/src/pages/connections.tsx index 3654a61..535d3c0 100644 --- a/src/pages/connections.tsx +++ b/src/pages/connections.tsx @@ -96,7 +96,7 @@ const ConnectionsPage = () => { if (!clashInfo) return; const { server = "", secret = "" } = clashInfo; - connect(`ws://${server}/connections?token=${secret}`); + connect(`ws://${server}/connections?token=${encodeURIComponent(secret)}`); return () => { disconnect();