Skip to content

Commit cbeb41c

Browse files
fix: redirect param (#601)
1 parent 935d4a0 commit cbeb41c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/components/survey/SuccessStep.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Box, Button } from "@zenml-io/react-component-library";
1+
import ArrowRight from "@/assets/icons/arrow-right.svg?react";
22
import CheckCircle from "@/assets/icons/check-circle.svg?react";
3-
import { Link, useSearchParams } from "react-router-dom";
3+
import { urlSchema } from "@/lib/url";
44
import { routes } from "@/router/routes";
5+
import { Box, Button } from "@zenml-io/react-component-library";
56
import { ReactNode } from "react";
6-
import ArrowRight from "@/assets/icons/arrow-right.svg?react";
7+
import { Link, useSearchParams } from "react-router-dom";
78

89
type Props = {
910
username: string;
@@ -15,6 +16,8 @@ export function SuccessStep({ username, subHeader, displayBody = true }: Props)
1516
const [params] = useSearchParams();
1617

1718
const redirect = params.get("redirect");
19+
const sanitizedRedirect = redirect && `${window.location.origin}${redirect}`;
20+
const isUrl = urlSchema.safeParse(sanitizedRedirect);
1821

1922
return (
2023
<Box className="flex max-w-[540px] flex-col items-center justify-center space-y-7 px-7 py-9">
@@ -34,7 +37,7 @@ export function SuccessStep({ username, subHeader, displayBody = true }: Props)
3437
</p>
3538
)}
3639
<Button className="inline-flex" size="md" intent="primary" asChild>
37-
<Link to={redirect || routes.home}>
40+
<Link to={isUrl.success ? isUrl.data : routes.home}>
3841
<span>Go to Dashboard</span>
3942
<ArrowRight className="h-5 w-5 fill-white" />
4043
</Link>

src/lib/url.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { z } from "zod";
2+
13
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24
export function objectToSearchParams(object: Record<string, any>) {
35
return new URLSearchParams(
@@ -28,3 +30,5 @@ function _sanitizeUrl(url: string): string {
2830
export function sanitizeUrl(url = "about:blank"): string {
2931
return _sanitizeUrl(String(url).trim());
3032
}
33+
34+
export const urlSchema = z.string().url();

0 commit comments

Comments
 (0)