Skip to content

Commit 789fed0

Browse files
dlqqqCarreau
authored andcommitted
patch open redirect in /login
1 parent 2ee51ec commit 789fed0

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

jupyter_server/auth/login.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ def _redirect_safe(self, url, default=None):
4343
# \ is not valid in urls, but some browsers treat it as /
4444
# instead of %5C, causing `\\` to behave as `//`
4545
url = url.replace("\\", "%5C")
46+
47+
# Prevent open redirect attacks by blocking URLs that start with //
48+
# These are protocol-relative URLs that can redirect to external sites
49+
if url.startswith("//"):
50+
self.log.warning("Not allowing login redirect to protocol-relative URL %r" % url)
51+
url = default
52+
self.redirect(url)
53+
return
54+
4655
# urllib and browsers interpret extra '/' in the scheme separator (`scheme:///host/path`)
4756
# differently.
4857
# urllib gives scheme=scheme, netloc='', path='/host/path', while

0 commit comments

Comments
 (0)