Skip to content

Commit 5bf8c14

Browse files
committed
chore: add safe guard for from path
1 parent bf15263 commit 5bf8c14

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

web-marketplace/src/legacy-pages/ProjectCreate/ProjectCreate.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ const defaultProjectCreateContext: ContextType = {
6666
setIsOrganizationAccount: () => void 0,
6767
};
6868

69+
/** Returns true only for same-origin relative paths, blocking open-redirect attacks. */
70+
const isSafeRelativePath = (path: string): boolean => {
71+
try {
72+
const resolved = new URL(path, window.location.origin);
73+
return resolved.origin === window.location.origin;
74+
} catch {
75+
return false;
76+
}
77+
};
78+
6979
export const ProjectCreate = (): JSX.Element => {
7080
const { _ } = useLingui();
7181
const router = useRouter();
@@ -103,7 +113,8 @@ export const ProjectCreate = (): JSX.Element => {
103113
const fromState =
104114
(location.state as { from?: string } | null)?.from ?? null;
105115
const fromParam = new URLSearchParams(location.search).get('from');
106-
originPathRef.current = fromState ?? fromParam;
116+
const safeFromParam = fromParam && isSafeRelativePath(fromParam) ? fromParam : null;
117+
originPathRef.current = fromState ?? safeFromParam;
107118
}
108119
// eslint-disable-next-line react-hooks/exhaustive-deps
109120
}, []);

0 commit comments

Comments
 (0)