Skip to content

Commit a9a8586

Browse files
committed
update redirect login checks
1 parent 8794be8 commit a9a8586

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

notebook/auth/login.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import os
88

9-
from urllib.parse import urlparse
9+
from urllib.parse import urlparse, urlunparse
1010

1111
import uuid
1212

@@ -42,15 +42,18 @@ def _redirect_safe(self, url, default=None):
4242
# instead of %5C, causing `\\` to behave as `//`
4343
url = url.replace("\\", "%5C")
4444
parsed = urlparse(url)
45-
if parsed.netloc or not (parsed.path + '/').startswith(self.base_url):
45+
path_only = urlunparse(parsed._replace(netloc='', scheme=''))
46+
if url != path_only or not (parsed.path + '/').startswith(self.base_url):
4647
# require that next_url be absolute path within our path
4748
allow = False
4849
# OR pass our cross-origin check
49-
if parsed.netloc:
50+
if url != path_only:
5051
# if full URL, run our cross-origin check:
5152
origin = f'{parsed.scheme}://{parsed.netloc}'
5253
origin = origin.lower()
53-
if self.allow_origin:
54+
if origin == f'{self.request.protocol}://{self.request.host}':
55+
allow = True
56+
elif self.allow_origin:
5457
allow = self.allow_origin == origin
5558
elif self.allow_origin_pat:
5659
allow = bool(self.allow_origin_pat.match(origin))

0 commit comments

Comments
 (0)