Skip to content

Commit f172926

Browse files
committed
avoid unhandled error on some invalid paths
1 parent 9579862 commit f172926

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

jupyter_server/services/contents/fileio.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ def _get_os_path(self, path):
259259
if os.path.splitdrive(path)[0]:
260260
raise HTTPError(404, "%s is not a relative API path" % path)
261261
os_path = to_os_path(ApiPath(path), root)
262+
# validate os path
263+
# e.g. "foo\0" raises ValueError: embedded null byte
264+
try:
265+
os.lstat(os_path)
266+
except OSError:
267+
# OSError could be FileNotFound, PermissionError, etc.
268+
# those should raise (or not) elsewhere
269+
pass
270+
except ValueError:
271+
raise HTTPError(404, f"{path} is not a valid path") from None
272+
262273
if not (os.path.abspath(os_path) + os.path.sep).startswith(root):
263274
raise HTTPError(404, "%s is outside root contents directory" % path)
264275
return os_path

0 commit comments

Comments
 (0)