Browse Source

feat: passkeys flow redir check

httpjamesm 1 year ago
parent
commit
d62de0c193
1 changed files with 18 additions and 4 deletions
  1. 18 4
      apps/accounts/src/pages/passkeys/flow/index.tsx

+ 18 - 4
apps/accounts/src/pages/passkeys/flow/index.tsx

@@ -23,8 +23,25 @@ const PasskeysFlow = () => {
     const [loading, setLoading] = useState(true);
 
     const init = async () => {
-        // get passkeySessionID from the query params
         const searchParams = new URLSearchParams(window.location.search);
+
+        // get redirect from the query params
+        const redirect = searchParams.get('redirect');
+
+        if (!redirect) {
+            setErrored(true);
+            return;
+        }
+
+        const redirectURL = new URL(redirect);
+        if (process.env.NEXT_PUBLIC_DISABLE_REDIRECT_CHECK !== 'true') {
+            if (!redirectURL.host.endsWith('ente.io')) {
+                setErrored(true);
+                return;
+            }
+        }
+
+        // get passkeySessionID from the query params
         const passkeySessionID = searchParams.get('passkeySessionID');
 
         setLoading(true);
@@ -83,9 +100,6 @@ const PasskeysFlow = () => {
 
         const encodedResponse = _sodium.to_base64(JSON.stringify(finishData));
 
-        // get redirect from the query params
-        const redirect = searchParams.get('redirect');
-
         window.location.href = `${redirect}?response=${encodedResponse}`;
     };