@@ -188,6 +188,12 @@ def _base_model(self, path):
188188 os_path = self ._get_os_path (path )
189189 info = os .lstat (os_path )
190190
191+ four_o_four = "file or directory does not exist: %r" % path
192+
193+ if is_hidden (os_path , self .root_dir ) and not self .allow_hidden :
194+ self .log .info ("Refusing to serve hidden file or directory %r, via 404 Error" , os_path )
195+ raise web .HTTPError (404 , four_o_four )
196+
191197 try :
192198 # size of file
193199 size = info .st_size
@@ -365,11 +371,16 @@ def get(self, path, content=True, type=None, format=None):
365371 of the file or directory as well.
366372 """
367373 path = path .strip ("/" )
374+ os_path = self ._get_os_path (path )
375+ four_o_four = "file or directory does not exist: %r" % path
368376
369377 if not self .exists (path ):
370- raise web .HTTPError (404 , "No such file or directory: %s" % path )
378+ raise web .HTTPError (404 , four_o_four )
379+
380+ if is_hidden (os_path , self .root_dir ) and not self .allow_hidden :
381+ self .log .info ("Refusing to serve hidden file or directory %r, via 404 Error" , os_path )
382+ raise web .HTTPError (404 , four_o_four )
371383
372- os_path = self ._get_os_path (path )
373384 if os .path .isdir (os_path ):
374385 if type not in (None , "directory" ):
375386 raise web .HTTPError (
@@ -389,7 +400,7 @@ def get(self, path, content=True, type=None, format=None):
389400 def _save_directory (self , os_path , model , path = "" ):
390401 """create a directory"""
391402 if is_hidden (os_path , self .root_dir ) and not self .allow_hidden :
392- raise web .HTTPError (400 , "Cannot create hidden directory %r" % os_path )
403+ raise web .HTTPError (400 , "Cannot create directory %r" % os_path )
393404 if not os .path .exists (os_path ):
394405 with self .perm_to_403 ():
395406 os .mkdir (os_path )
@@ -410,6 +421,10 @@ def save(self, model, path=""):
410421 raise web .HTTPError (400 , "No file content provided" )
411422
412423 os_path = self ._get_os_path (path )
424+
425+ if is_hidden (os_path , self .root_dir ) and not self .allow_hidden :
426+ raise web .HTTPError (400 , f"Cannot create file or directory { os_path !r} " )
427+
413428 self .log .debug ("Saving %s" , os_path )
414429
415430 validation_error : dict = {}
@@ -452,8 +467,13 @@ def delete_file(self, path):
452467 path = path .strip ("/" )
453468 os_path = self ._get_os_path (path )
454469 rm = os .unlink
455- if not os .path .exists (os_path ):
456- raise web .HTTPError (404 , "File or directory does not exist: %s" % os_path )
470+ four_o_four = "file or directory does not exist: %r" % path
471+
472+ if not self .exists (path ):
473+ raise web .HTTPError (404 , four_o_four )
474+
475+ if is_hidden (os_path , self .root_dir ) and not self .allow_hidden :
476+ raise web .HTTPError (400 , f"Cannot delete file or directory { os_path !r} " )
457477
458478 def _check_trash (os_path ):
459479 if sys .platform in {"win32" , "darwin" }:
@@ -518,6 +538,11 @@ def rename_file(self, old_path, new_path):
518538 new_os_path = self ._get_os_path (new_path )
519539 old_os_path = self ._get_os_path (old_path )
520540
541+ if (
542+ is_hidden (old_os_path , self .root_dir ) or is_hidden (new_os_path , self .root_dir )
543+ ) and not self .allow_hidden :
544+ raise web .HTTPError (400 , f"Cannot rename file or directory { old_os_path !r} " )
545+
521546 # Should we proceed with the move?
522547 if os .path .exists (new_os_path ) and not samefile (old_os_path , new_os_path ):
523548 raise web .HTTPError (409 , "File already exists: %s" % new_path )
0 commit comments