Skip to content

Commit

Permalink
Frictionless Email Subscriptions: Handle relative urls for redirect_t…
Browse files Browse the repository at this point in the history
…o url query param (#92345)
  • Loading branch information
jeyip authored Jul 3, 2024
1 parent db3b560 commit f9bfdc4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions client/signup/steps/subscribe-email/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,25 @@ function sanitizeEmail( email ) {
}

function getRedirectUrl( redirect ) {
const isHttpOrHttps =
!! redirect && ( redirect.startsWith( 'https://' ) || redirect.startsWith( 'http://' ) );
const redirectUrl = isHttpOrHttps
? addQueryArgs( redirect, { subscribed: true } )
: addQueryArgs( 'https://' + redirect, { subscribed: true } );
const baseUrl = 'https://wordpress.com/';

return isRedirectAllowed( redirectUrl ) ? redirectUrl : 'https://wordpress.com/';
if ( typeof redirect !== 'string' ) {
return baseUrl;
}

if ( redirect.startsWith( '/' ) ) {
redirect = 'https://wordpress.com' + redirect;
}

if (
! redirect.startsWith( 'https://' ) &&
! redirect.startsWith( 'http://' ) &&
! redirect.startsWith( '/' )
) {
redirect = 'https://' + redirect;
}

return isRedirectAllowed( redirect ) ? addQueryArgs( redirect, { subscribed: true } ) : baseUrl;
}

/**
Expand Down

0 comments on commit f9bfdc4

Please sign in to comment.