File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed
client/login/redirect-logged-in Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change 1
- import safeProtocolUrl from 'calypso/lib/safe-protocol-url' ;
2
1
import { isUserLoggedIn } from 'calypso/state/current-user/selectors' ;
3
2
3
+ /**
4
+ * For this context, we consider external URLs that are NOT:
5
+ * - Relative paths (`/test`)
6
+ * - Absolute URLs on https://wordpress.com/*
7
+ * @param {string } url URL to check
8
+ * @returns {boolean }
9
+ */
10
+ function isExternalUrl ( url ) {
11
+ if ( url . startsWith ( '/' ) ) {
12
+ return false ;
13
+ }
14
+
15
+ try {
16
+ const urlObject = new URL ( url ) ;
17
+ if ( urlObject . hostname === 'wordpress.com' && urlObject . protocol === 'https:' ) {
18
+ return false ;
19
+ }
20
+ } catch {
21
+ return true ;
22
+ }
23
+
24
+ return true ;
25
+ }
26
+
4
27
export default function redirectLoggedIn ( context , next ) {
5
28
const userLoggedIn = isUserLoggedIn ( context . store . getState ( ) ) ;
6
29
7
30
if ( userLoggedIn ) {
8
31
// force full page reload to avoid SSR hydration issues.
9
32
// Redirect parameters should have higher priority.
10
- let url = safeProtocolUrl ( context ?. query ?. redirect_to ) ;
11
- if ( ! url || url === 'http:' ) {
33
+ let url = context ?. query ?. redirect_to ;
34
+ if ( ! url || isExternalUrl ( url ) ) {
12
35
url = '/' ;
13
36
}
14
37
window . location = url ;
You can’t perform that action at this time.
0 commit comments