Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): validate next redirect in signup form

Richie McIlroy11ad719bf104
diff --git a/apps/web/app/(org)/signup/form.tsx b/apps/web/app/(org)/signup/form.tsx
index 1e79c9432..c64f24309 100644
--- a/apps/web/app/(org)/signup/form.tsx
+++ b/apps/web/app/(org)/signup/form.tsx
@@ -21,6 +21,7 @@ import { getOrganizationSSOData } from "@/actions/organization/get-organization-
import { trackEvent } from "@/app/utils/analytics";
import { usePublicEnv } from "@/utils/public-env";
import { getEmailCodeCooldownSeconds, requestEmailCode } from "../auth-email";
+import { getSafeNextPath } from "../safe-next";
const MotionInput = motion(Input);
const MotionLogoBadge = motion(LogoBadge);
@@ -42,6 +43,8 @@ export function SignupForm() {
null,
);
const theme = Cookies.get("theme") || "light";
+ const getNextPath = () =>
+ next ? getSafeNextPath(next, window.location.origin) : null;
useEffect(() => {
document.body.className = theme === "dark" ? "dark" : "light";
@@ -103,13 +106,14 @@ export function SignupForm() {
}, [emailSent]);
const handleGoogleSignIn = () => {
+ const nextPath = getNextPath();
trackEvent("auth_started", {
method: "google",
is_signup: true,
auth_surface: "signup",
});
signIn("google", {
- ...(next && next.length > 0 ? { callbackUrl: next } : {}),
+ ...(nextPath ? { callbackUrl: nextPath } : {}),
});
};
@@ -261,9 +265,10 @@ export function SignupForm() {
setLoading(true);
try {
+ const nextPath = getNextPath();
const normalizedEmail = await requestEmailCode({
email,
- next,
+ next: nextPath,
isSignup: true,
authSurface: "signup",
});
@@ -274,7 +279,7 @@ export function SignupForm() {
setLastEmailSentTime(sentAt);
const params = new URLSearchParams({
email: normalizedEmail,
- ...(next && { next }),
+ ...(nextPath && { next: nextPath }),
lastSent: sentAt.toString(),
});
router.push(`/verify-otp?${params.toString()}`);