File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
web-marketplace/src/legacy-pages/ProjectCreate Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff 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+
6979export 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 } , [ ] ) ;
You can’t perform that action at this time.
0 commit comments