From 34781a1c443ff2b247201eeb6d55072a3b3ba7db Mon Sep 17 00:00:00 2001 From: Pranav Agarkar <90404176+PranavAgarkar07@users.noreply.github.com> Date: Sun, 17 May 2026 08:50:40 +0530 Subject: [PATCH] fix(security): guard OpenhumanLinkModal against arbitrary event paths (closes #1945) (#1949) --- app/src/components/OpenhumanLinkModal.tsx | 34 ++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/components/OpenhumanLinkModal.tsx b/app/src/components/OpenhumanLinkModal.tsx index d7318b90a..f26c5890a 100644 --- a/app/src/components/OpenhumanLinkModal.tsx +++ b/app/src/components/OpenhumanLinkModal.tsx @@ -40,13 +40,27 @@ interface OpenhumanLinkEvent { export const OPENHUMAN_LINK_EVENT = 'openhuman-link'; +const ALLOWED_PATHS = [ + 'settings/notifications', + 'settings/billing', + 'settings/messaging', + 'community/discord', + 'accounts/setup', +] as const; + +type AllowedPath = (typeof ALLOWED_PATHS)[number]; + +const ALLOWED_PATHS_SET = new Set(ALLOWED_PATHS); + const OpenhumanLinkModal = () => { - const [activePath, setActivePath] = useState(null); + const [activePath, setActivePath] = useState(null); useEffect(() => { const handler = (event: Event) => { const detail = (event as CustomEvent).detail; - if (detail?.path) setActivePath(detail.path); + if (detail?.path && ALLOWED_PATHS_SET.has(detail.path)) { + setActivePath(detail.path as AllowedPath); + } }; window.addEventListener(OPENHUMAN_LINK_EVENT, handler); return () => window.removeEventListener(OPENHUMAN_LINK_EVENT, handler); @@ -143,7 +157,7 @@ const MessagingSetupBridge = ({ onClose }: { onClose: () => void }) => { return ; }; -function titleForPath(path: string): string { +function titleForPath(path: AllowedPath): string { switch (path) { case 'settings/notifications': return 'Allow notifications'; @@ -155,12 +169,10 @@ function titleForPath(path: string): string { return 'Join the community'; case 'accounts/setup': return 'Connect your apps'; - default: - return 'Settings'; } } -function renderBody(path: string, close: () => void) { +function renderBody(path: AllowedPath, close: () => void) { switch (path) { case 'settings/notifications': return ; @@ -176,16 +188,6 @@ function renderBody(path: string, close: () => void) { return ; case 'accounts/setup': return ; - default: - return ( -
-

- This setting isn't ready in the popup yet. Open the full settings page when you're - ready. -

- -
- ); } }