File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
jupyter_server/services/contents Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,17 @@ def _get_os_path(self, path):
259
259
if os .path .splitdrive (path )[0 ]:
260
260
raise HTTPError (404 , "%s is not a relative API path" % path )
261
261
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
+
262
273
if not (os .path .abspath (os_path ) + os .path .sep ).startswith (root ):
263
274
raise HTTPError (404 , "%s is outside root contents directory" % path )
264
275
return os_path
You can’t perform that action at this time.
0 commit comments