Skip to content

Commit 40a95e5

Browse files
authored
avoid unhandled error on some invalid paths (#1369)
1 parent ecd5b1f commit 40a95e5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

jupyter_server/services/contents/fileio.py

+11
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ def _get_os_path(self, path):
270270
if os.path.splitdrive(path)[0]:
271271
raise HTTPError(404, "%s is not a relative API path" % path)
272272
os_path = to_os_path(ApiPath(path), root)
273+
# validate os path
274+
# e.g. "foo\0" raises ValueError: embedded null byte
275+
try:
276+
os.lstat(os_path)
277+
except OSError:
278+
# OSError could be FileNotFound, PermissionError, etc.
279+
# those should raise (or not) elsewhere
280+
pass
281+
except ValueError:
282+
raise HTTPError(404, f"{path} is not a valid path") from None
283+
273284
if not (os.path.abspath(os_path) + os.path.sep).startswith(root):
274285
raise HTTPError(404, "%s is outside root contents directory" % path)
275286
return os_path

0 commit comments

Comments
 (0)