Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid unhandled error on some invalid paths #1369

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions jupyter_server/services/contents/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ def _get_os_path(self, path):
if os.path.splitdrive(path)[0]:
raise HTTPError(404, "%s is not a relative API path" % path)
os_path = to_os_path(ApiPath(path), root)
# validate os path
# e.g. "foo\0" raises ValueError: embedded null byte
try:
os.lstat(os_path)
except OSError:
# OSError could be FileNotFound, PermissionError, etc.
# those should raise (or not) elsewhere
pass
except ValueError:
raise HTTPError(404, f"{path} is not a valid path") from None

if not (os.path.abspath(os_path) + os.path.sep).startswith(root):
raise HTTPError(404, "%s is outside root contents directory" % path)
return os_path
Expand Down
Loading