File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -550,7 +550,7 @@ def validate(self) -> None:
550550 self .load_memory (zipfile )
551551 self .load_components (zipfile )
552552 for name in zipfile .namelist ():
553- validate_filename (name )
553+ validate_filename (name , check_prohibited = False )
554554
555555 def restore_unit (
556556 self ,
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ def should_skip(location):
9090 )
9191
9292
93- def is_excluded (path ) :
93+ def is_excluded (path : str ) -> bool :
9494 """Whether path should be excluded from zip extraction."""
9595 return any (exclude in f"/{ path } /" for exclude in PATH_EXCLUDES ) or ".." in path
9696
Original file line number Diff line number Diff line change @@ -139,6 +139,16 @@ def test_simplification(self) -> None:
139139 def test_empty (self ) -> None :
140140 validate_filename ("" )
141141
142+ def test_prohibited (self ) -> None :
143+ with self .assertRaises (ValidationError ):
144+ validate_filename (".git/config" )
145+ validate_filename (".git/config" , check_prohibited = False )
146+
147+ def test_prohibited_subdir (self ) -> None :
148+ with self .assertRaises (ValidationError ):
149+ validate_filename ("path/.git/config" )
150+ validate_filename ("path/.git/config" , check_prohibited = False )
151+
142152
143153class RegexTest (SimpleTestCase ):
144154 def test_empty (self ) -> None :
Original file line number Diff line number Diff line change 3333from weblate .trans .util import cleanup_path
3434from weblate .utils .const import WEBHOOKS_SECRET_PREFIX
3535from weblate .utils .data import data_dir
36+ from weblate .utils .files import is_excluded
3637
3738USERNAME_MATCHER = re .compile (r"^[\w@+-][\w.@+-]*$" )
3839
@@ -238,7 +239,7 @@ def validate_plural_formula(value) -> None:
238239 ) from error
239240
240241
241- def validate_filename (value ) -> None :
242+ def validate_filename (value : str , * , check_prohibited : bool = True ) -> None :
242243 if "../" in value or "..\\ " in value :
243244 raise ValidationError (
244245 gettext ("The filename can not contain reference to a parent directory." )
@@ -254,6 +255,8 @@ def validate_filename(value) -> None:
254255 "Maybe you want to use: {}"
255256 ).format (cleaned )
256257 )
258+ if check_prohibited and is_excluded (cleaned ):
259+ raise ValidationError (gettext ("The filename contains a prohibited folder." ))
257260
258261
259262def validate_backup_path (value : str ) -> None :
You can’t perform that action at this time.
0 commit comments