From cb68d2dfad87a785cb728d8da17b5a9e070ca683 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 17 Apr 2025 23:03:12 -0400 Subject: [PATCH] Improve validation on desktop subdomain switch modal Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- app/scenes/Login/components/LoginDialog.tsx | 2 +- app/scenes/Login/urls.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/scenes/Login/components/LoginDialog.tsx b/app/scenes/Login/components/LoginDialog.tsx index c8a5b0a7f9..78767b921e 100644 --- a/app/scenes/Login/components/LoginDialog.tsx +++ b/app/scenes/Login/components/LoginDialog.tsx @@ -39,7 +39,7 @@ export function LoginDialog() { maxLength={255} autoComplete="off" placeholder={t("subdomain")} - {...register("subdomain", { required: true, pattern: /^[a-z\d-]+$/ })} + {...register("subdomain", { required: true, pattern: /^[a-z\d-]{1,63}$/ })} > .getoutline.com diff --git a/app/scenes/Login/urls.ts b/app/scenes/Login/urls.ts index fe5612453e..b63f37f27e 100644 --- a/app/scenes/Login/urls.ts +++ b/app/scenes/Login/urls.ts @@ -3,6 +3,14 @@ import { parseDomain } from "@shared/utils/domains"; import env from "~/env"; import Desktop from "~/utils/Desktop"; +function validateAndEncodeSubdomain(subdomain: string): string { + const encodedSubdomain = encodeURIComponent(subdomain); + const urlPattern = /^[a-z\d-]{1,63}$/; + if (!urlPattern.test(encodedSubdomain)) { + throw new Error("Invalid subdomain"); + } + return `https://${encodedSubdomain}.getoutline.com`; +} /** * If we're on a custom domain or a subdomain then the auth must point to the * apex (env.URL) for authentication so that the state cookie can be set and read. @@ -36,7 +44,7 @@ export async function navigateToSubdomain(subdomain: string) { .toLowerCase() .trim() .replace(/^https?:\/\//, ""); - const host = `https://${normalizedSubdomain}.getoutline.com`; + const host = validateAndEncodeSubdomain(normalizedSubdomain); await Desktop.bridge?.addCustomHost(host); window.location.href = host; }