Skip to content

Commit

Permalink
Merge pull request from GHSA-c7vm-f5p4-8fqh
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Nov 6, 2020
2 parents d8308e1 + 73bd15e commit 3cec4bb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
9 changes: 9 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ We strongly recommend that you upgrade pip to version 9+ of pip before upgrading
``pip --version``.


.. _release-6.1.5:

6.1.5
-----

6.1.5 is a security release, fixing one vulnerability:

- Fix open redirect vulnerability GHSA-c7vm-f5p4-8fqh (CVE to be assigned)

.. _release-6.1.4:

6.1.4
Expand Down
14 changes: 10 additions & 4 deletions notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,13 +854,18 @@ def get(self):

class TrailingSlashHandler(web.RequestHandler):
"""Simple redirect handler that strips trailing slashes
This should be the first, highest priority handler.
"""

def get(self):
self.redirect(self.request.uri.rstrip('/'))

path, *rest = self.request.uri.partition("?")
# trim trailing *and* leading /
# to avoid misinterpreting repeated '//'
path = "/" + path.strip("/")
new_uri = "".join([path, *rest])
self.redirect(new_uri)

post = put = get


Expand Down Expand Up @@ -911,6 +916,7 @@ def get(self):
url = sep.join([self._url, self.request.query])
self.redirect(url, permanent=self._permanent)


class PrometheusMetricsHandler(IPythonHandler):
"""
Return prometheus metrics for this notebook server
Expand Down
18 changes: 18 additions & 0 deletions notebook/tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
from nose.tools import assert_regex, assert_not_regex

from notebook.base.handlers import path_regex
from notebook.utils import url_path_join
from .launchnotebook import NotebookTestBase

# build regexps that tornado uses:
path_pat = re.compile('^' + '/x%s' % path_regex + '$')


def test_path_regex():
for path in (
'/x',
Expand All @@ -30,3 +33,18 @@ def test_path_regex_bad():
'/y/x/foo',
):
assert_not_regex(path, path_pat)


class RedirectTestCase(NotebookTestBase):
def test_trailing_slash(self):
for uri, expected in (
("/notebooks/mynotebook/", "/notebooks/mynotebook"),
("////foo///", "/foo"),
("//example.com/", "/example.com"),
("/has/param/?hasparam=true", "/has/param?hasparam=true"),
):
r = self.request("GET", uri, allow_redirects=False)
print(uri, expected)
assert r.status_code == 302
assert "Location" in r.headers
assert r.headers["Location"] == url_path_join(self.url_prefix, expected)

0 comments on commit 3cec4bb

Please sign in to comment.