File tree Expand file tree Collapse file tree
packages/flat-pages/src/LoginPage/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,6 +36,17 @@ export function useMachine(): [any, (type: ToggleEventsType) => void] {
3636 return [ currentState , setCurrentState ] ;
3737}
3838
39+ const isJavaScriptProtocol =
40+ / ^ [ \u0000 - \u001F ] * j [ \r \n \t ] * a [ \r \n \t ] * v [ \r \n \t ] * a [ \r \n \t ] * s [ \r \n \t ] * c [ \r \n \t ] * r [ \r \n \t ] * i [ \r \n \t ] * p [ \r \n \t ] * t [ \r \n \t ] * \: / i;
41+
42+ function sanitizeURL ( url : string | null ) : string | null {
43+ if ( url && isJavaScriptProtocol . test ( url ) ) {
44+ console . warn ( "Refuse to redirect to" , url ) ;
45+ return null ;
46+ }
47+ return url ;
48+ }
49+
3950export interface LoginState {
4051 currentState : any ;
4152 setCurrentState : ( type : ToggleEventsType ) => void ;
@@ -55,7 +66,7 @@ export function useLoginState(): LoginState {
5566 const [ loginResult , setLoginResult ] = useState < LoginProcessResult | null > ( null ) ;
5667
5768 const [ redirectURL ] = useState ( ( ) =>
58- new URLSearchParams ( window . location . search ) . get ( "redirect" ) ,
69+ sanitizeURL ( new URLSearchParams ( window . location . search ) . get ( "redirect" ) ) ,
5970 ) ;
6071
6172 const [ currentState , setCurrentState ] = useMachine ( ) ;
You can’t perform that action at this time.
0 commit comments