π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web] add URL validation and unify redirect checks
Manav Rathi958ef39afa14
diff --git a/web/apps/accounts/src/pages/passkeys/verify.tsx b/web/apps/accounts/src/pages/passkeys/verify.tsxindex b91c13a967..3d3afd6384 100644--- a/web/apps/accounts/src/pages/passkeys/verify.tsx+++ b/web/apps/accounts/src/pages/passkeys/verify.tsx@@ -13,7 +13,7 @@ import {beginPasskeyAuthentication,finishPasskeyAuthentication,isWebAuthnSupported,- isWhitelistedRedirect,+ parseRedirectURLParam,passkeyAuthenticationSuccessRedirectURL,passkeySessionAlreadyClaimedErrorMessage,redirectToPasskeyRecoverPage,@@ -82,11 +82,11 @@ const Page = () => {// Extract redirect from the query params.const redirect = nullToUndefined(searchParams.get("redirect"));- const redirectURL = redirect ? new URL(redirect) : undefined;+ const redirectURL = parseRedirectURLParam(redirect);- // Ensure that redirectURL is whitelisted, otherwise show an invalid- // "login" URL error to the user.- if (!redirectURL || !isWhitelistedRedirect(redirectURL)) {+ // Ensure that redirectURL is valid/whitelisted, otherwise show an+ // invalid "login" URL error to the user.+ if (!redirectURL) {log.error(`Redirect '${redirect}' is not whitelisted`);setStatus("unknownRedirect");return;@@ -223,7 +223,10 @@ const Page = () => {return undefined;}- return () => redirectToPasskeyRecoverPage(new URL(recover));+ const recoverURL = parseRedirectURLParam(recover);+ if (!recoverURL) return undefined;++ return () => redirectToPasskeyRecoverPage(recoverURL);})();const handleRedirectAgain = () => redirectToURL(successRedirectURL!);diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.tsindex 65c4ecd334..dee53aab86 100644--- a/web/apps/accounts/src/services/passkey.ts+++ b/web/apps/accounts/src/services/passkey.ts@@ -338,10 +338,24 @@ const authenticatorAttestationResponse = (credential: Credential) => {* Ente. So only do this check if we're running on our production servers (or* localhost).*/-export const isWhitelistedRedirect = (redirectURL: URL) =>- shouldRestrictToWhitelistedRedirect()- ? _isWhitelistedRedirect(redirectURL)- : true;+const isAllowedRedirectScheme = (url: URL) =>+ url.protocol === "http:" ||+ url.protocol === "https:" ||+ url.protocol === "ente:" ||+ url.protocol === "enteauth:" ||+ url.protocol === "ente-cli:";++export const isWhitelistedRedirect = (redirectURL: URL) => {+ if (!isAllowedRedirectScheme(redirectURL)) return false;+ if (!shouldRestrictToWhitelistedRedirect()) return true;+ // In production/local, enforce host allowlist only for http(s)+ return (+ redirectURL.protocol === "ente:" ||+ redirectURL.protocol === "enteauth:" ||+ redirectURL.protocol === "ente-cli:" ||+ _isWhitelistedRedirect(redirectURL)+ );+};export const shouldRestrictToWhitelistedRedirect = () => {// host includes port, hostname is sans port@@ -356,10 +370,19 @@ export const shouldRestrictToWhitelistedRedirect = () => {const _isWhitelistedRedirect = (redirectURL: URL) =>(isDevBuild && redirectURL.hostname.endsWith("localhost")) ||redirectURL.host.endsWith(".ente.io") ||- redirectURL.host.endsWith(".ente.sh") ||- redirectURL.protocol == "ente:" ||- redirectURL.protocol == "enteauth:" ||- redirectURL.protocol == "ente-cli:";+ redirectURL.host.endsWith(".ente.sh");++export const parseRedirectURLParam = (+ value: string | undefined,+): URL | undefined => {+ if (!value) return undefined;+ try {+ const url = new URL(value);+ return isWhitelistedRedirect(url) ? url : undefined;+ } catch {+ return undefined;+ }+};export interface BeginPasskeyAuthenticationResponse {/**