File tree Expand file tree Collapse file tree
tests/trestle/core/commands/author
trestle/core/commands/author Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -355,6 +355,12 @@ def test_jinja_docs_profile_path_traversal_protection(tmp_trestle_dir: pathlib.P
355355 PathSecurityValidator .validate_local_path (output_file , tmp_trestle_dir )
356356 assert 'Security violation' in str (exc_info .value )
357357
358- # Test 3: Valid relative path should succeed
358+ # Test 3: Directory creation path traversal should fail
359+ with pytest .raises (TrestleError ) as exc_info :
360+ group_dir = tmp_trestle_dir / '../../../etc/malicious'
361+ PathSecurityValidator .validate_local_path (group_dir , tmp_trestle_dir )
362+ assert 'Security violation' in str (exc_info .value )
363+
364+ # Test 4: Valid relative path should succeed
359365 output_file = tmp_trestle_dir / 'controls_output/ac/ac-1.md'
360366 PathSecurityValidator .validate_local_path (output_file , tmp_trestle_dir ) # Should not raise
Original file line number Diff line number Diff line change @@ -278,8 +278,11 @@ def jinja_multiple_md(
278278 control_path = catalog_interface .get_control_path (control .id )
279279 for sub_dir in control_path :
280280 group_dir = group_dir / sub_dir
281- if not group_dir .exists ():
282- group_dir .mkdir (parents = True , exist_ok = True )
281+ # Validate directory path to prevent path traversal before creating directories
282+ full_group_dir = trestle_root / group_dir
283+ PathSecurityValidator .validate_local_path (full_group_dir , trestle_root )
284+ if not full_group_dir .exists ():
285+ full_group_dir .mkdir (parents = True , exist_ok = True )
283286
284287 control_writer = DocsControlWriter ()
285288
You can’t perform that action at this time.
0 commit comments