Skip to content

Commit

Permalink
version_info gate for is_relative_to
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed May 15, 2024
1 parent e88d993 commit 3543f99
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,17 @@ def filefind(filename: str, path_dirs: Sequence[str]) -> str:
# os.path.abspath resolves '..', but Path.absolute() doesn't
# Path.resolve() does, but traverses symlinks, which we don't want
test_path = Path(os.path.abspath(test_path))
try:
# can use is_relative_to when we require Python 3.9
test_path.relative_to(path)
except ValueError:
# points outside root, e.g. via `filename='../foo'`
continue
if sys.version_info >= (3, 9):
if not test_path.is_relative_to(path):
# points outside root, e.g. via `filename='../foo'`
continue
else:
# is_relative_to is new in 3.9
try:
test_path.relative_to(path)
except ValueError:
# points outside root, e.g. via `filename='../foo'`
continue
# make sure we don't call is_file before we know it's a file within a prefix
# GHSA-hrw6-wg82-cm62 - can leak password hash on windows.
if test_path.is_file():
Expand Down

0 comments on commit 3543f99

Please sign in to comment.