Skip to content

Commit 140acb2

Browse files
authored
fix: correct path security validator behaviour on mac os
fix: correct path security validator behaviour on mac os
1 parent d00a0c2 commit 140acb2

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

tests/trestle/core/remote/cache_security_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""Security tests for cache path traversal vulnerabilities."""
1717

1818
import pathlib
19+
import sys
1920

2021
import pytest
2122

@@ -207,6 +208,7 @@ def test_validate_local_file_path_outside_workspace_allowed(self, tmp_path: path
207208
# Should not raise
208209
PathSecurityValidator.validate_local_file_path(workspace, outside_file, allow_outside_workspace=True)
209210

211+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
210212
def test_validate_local_file_path_blocks_etc_passwd(self, tmp_path: pathlib.Path) -> None:
211213
"""Test that /etc/passwd is blocked even with allow_outside_workspace=True."""
212214
workspace = tmp_path / 'workspace'
@@ -217,6 +219,7 @@ def test_validate_local_file_path_blocks_etc_passwd(self, tmp_path: pathlib.Path
217219
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
218220
PathSecurityValidator.validate_local_file_path(workspace, passwd_path, allow_outside_workspace=True)
219221

222+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
220223
def test_validate_local_file_path_blocks_etc_shadow(self, tmp_path: pathlib.Path) -> None:
221224
"""Test that /etc/shadow is blocked."""
222225
workspace = tmp_path / 'workspace'
@@ -227,6 +230,7 @@ def test_validate_local_file_path_blocks_etc_shadow(self, tmp_path: pathlib.Path
227230
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
228231
PathSecurityValidator.validate_local_file_path(workspace, shadow_path, allow_outside_workspace=True)
229232

233+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
230234
def test_validate_local_file_path_blocks_etc_group(self, tmp_path: pathlib.Path) -> None:
231235
"""Test that /etc/group is blocked."""
232236
workspace = tmp_path / 'workspace'
@@ -237,6 +241,7 @@ def test_validate_local_file_path_blocks_etc_group(self, tmp_path: pathlib.Path)
237241
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
238242
PathSecurityValidator.validate_local_file_path(workspace, group_path, allow_outside_workspace=True)
239243

244+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
240245
def test_validate_local_file_path_blocks_etc_sudoers(self, tmp_path: pathlib.Path) -> None:
241246
"""Test that /etc/sudoers is blocked."""
242247
workspace = tmp_path / 'workspace'
@@ -247,6 +252,7 @@ def test_validate_local_file_path_blocks_etc_sudoers(self, tmp_path: pathlib.Pat
247252
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
248253
PathSecurityValidator.validate_local_file_path(workspace, sudoers_path, allow_outside_workspace=True)
249254

255+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
250256
def test_validate_local_file_path_blocks_ssh_directory(self, tmp_path: pathlib.Path) -> None:
251257
"""Test that .ssh directory is blocked."""
252258
workspace = tmp_path / 'workspace'
@@ -257,6 +263,7 @@ def test_validate_local_file_path_blocks_ssh_directory(self, tmp_path: pathlib.P
257263
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
258264
PathSecurityValidator.validate_local_file_path(workspace, ssh_path, allow_outside_workspace=True)
259265

266+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
260267
def test_validate_local_file_path_blocks_aws_credentials(self, tmp_path: pathlib.Path) -> None:
261268
"""Test that .aws credentials are blocked."""
262269
workspace = tmp_path / 'workspace'
@@ -267,6 +274,7 @@ def test_validate_local_file_path_blocks_aws_credentials(self, tmp_path: pathlib
267274
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
268275
PathSecurityValidator.validate_local_file_path(workspace, aws_path, allow_outside_workspace=True)
269276

277+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
270278
def test_validate_local_file_path_blocks_docker_config(self, tmp_path: pathlib.Path) -> None:
271279
"""Test that .docker config is blocked."""
272280
workspace = tmp_path / 'workspace'
@@ -277,6 +285,7 @@ def test_validate_local_file_path_blocks_docker_config(self, tmp_path: pathlib.P
277285
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
278286
PathSecurityValidator.validate_local_file_path(workspace, docker_path, allow_outside_workspace=True)
279287

288+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
280289
def test_validate_local_file_path_blocks_kube_config(self, tmp_path: pathlib.Path) -> None:
281290
"""Test that .kube config is blocked."""
282291
workspace = tmp_path / 'workspace'
@@ -287,6 +296,7 @@ def test_validate_local_file_path_blocks_kube_config(self, tmp_path: pathlib.Pat
287296
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
288297
PathSecurityValidator.validate_local_file_path(workspace, kube_path, allow_outside_workspace=True)
289298

299+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
290300
def test_validate_local_file_path_blocks_proc_environ(self, tmp_path: pathlib.Path) -> None:
291301
"""Test that /proc/self/environ is blocked."""
292302
workspace = tmp_path / 'workspace'
@@ -317,6 +327,7 @@ def test_validate_local_file_path_blocks_windows_credentials(self, tmp_path: pat
317327
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
318328
PathSecurityValidator.validate_local_file_path(workspace, cred_path, allow_outside_workspace=True)
319329

330+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
320331
def test_validate_local_file_path_blocks_var_log(self, tmp_path: pathlib.Path) -> None:
321332
"""Test that /var/log is blocked."""
322333
workspace = tmp_path / 'workspace'
@@ -327,6 +338,7 @@ def test_validate_local_file_path_blocks_var_log(self, tmp_path: pathlib.Path) -
327338
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
328339
PathSecurityValidator.validate_local_file_path(workspace, log_path, allow_outside_workspace=True)
329340

341+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
330342
def test_validate_local_file_path_blocks_mysql_data(self, tmp_path: pathlib.Path) -> None:
331343
"""Test that MySQL data directory is blocked."""
332344
workspace = tmp_path / 'workspace'
@@ -337,6 +349,7 @@ def test_validate_local_file_path_blocks_mysql_data(self, tmp_path: pathlib.Path
337349
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
338350
PathSecurityValidator.validate_local_file_path(workspace, mysql_path, allow_outside_workspace=True)
339351

352+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
340353
def test_validate_local_file_path_case_insensitive(self, tmp_path: pathlib.Path) -> None:
341354
"""Test that sensitive path checking is case-insensitive."""
342355
workspace = tmp_path / 'workspace'
@@ -348,6 +361,7 @@ def test_validate_local_file_path_case_insensitive(self, tmp_path: pathlib.Path)
348361
with pytest.raises(TrestleError, match='Attempt to access potentially sensitive system file'):
349362
PathSecurityValidator.validate_local_file_path(workspace, passwd_upper, allow_outside_workspace=True)
350363

364+
@pytest.mark.skipif(sys.platform == 'win32', reason='Unix-specific sensitive paths')
351365
def test_validate_local_file_path_checks_original_and_resolved(self, tmp_path: pathlib.Path) -> None:
352366
"""Test that both original and resolved paths are checked for sensitive patterns."""
353367
workspace = tmp_path / 'workspace'

trestle/core/remote/security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def validate_local_file_path(
228228
'/root/.gnupg',
229229
# macOS specific
230230
'/Library/Keychains',
231-
'/Users/', # Broad but catches user home directories
231+
'/Library/', # Broad but catches user home directories
232232
# Windows system directories
233233
'C:\\Windows\\System32',
234234
'C:\\Windows\\SysWOW64',

0 commit comments

Comments
 (0)