@@ -188,6 +188,12 @@ def _base_model(self, path):
188
188
os_path = self ._get_os_path (path )
189
189
info = os .lstat (os_path )
190
190
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
+
191
197
try :
192
198
# size of file
193
199
size = info .st_size
@@ -365,11 +371,16 @@ def get(self, path, content=True, type=None, format=None):
365
371
of the file or directory as well.
366
372
"""
367
373
path = path .strip ("/" )
374
+ os_path = self ._get_os_path (path )
375
+ four_o_four = "file or directory does not exist: %r" % path
368
376
369
377
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 )
371
383
372
- os_path = self ._get_os_path (path )
373
384
if os .path .isdir (os_path ):
374
385
if type not in (None , "directory" ):
375
386
raise web .HTTPError (
@@ -389,7 +400,7 @@ def get(self, path, content=True, type=None, format=None):
389
400
def _save_directory (self , os_path , model , path = "" ):
390
401
"""create a directory"""
391
402
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 )
393
404
if not os .path .exists (os_path ):
394
405
with self .perm_to_403 ():
395
406
os .mkdir (os_path )
@@ -410,6 +421,10 @@ def save(self, model, path=""):
410
421
raise web .HTTPError (400 , "No file content provided" )
411
422
412
423
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
+
413
428
self .log .debug ("Saving %s" , os_path )
414
429
415
430
validation_error : dict = {}
@@ -452,8 +467,13 @@ def delete_file(self, path):
452
467
path = path .strip ("/" )
453
468
os_path = self ._get_os_path (path )
454
469
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} " )
457
477
458
478
def _check_trash (os_path ):
459
479
if sys .platform in {"win32" , "darwin" }:
@@ -518,6 +538,11 @@ def rename_file(self, old_path, new_path):
518
538
new_os_path = self ._get_os_path (new_path )
519
539
old_os_path = self ._get_os_path (old_path )
520
540
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
+
521
546
# Should we proceed with the move?
522
547
if os .path .exists (new_os_path ) and not samefile (old_os_path , new_os_path ):
523
548
raise web .HTTPError (409 , "File already exists: %s" % new_path )
0 commit comments