|
25 | 25 | round_down, |
26 | 26 | round_up, |
27 | 27 | ) |
28 | | -from unblob.report import PathTraversalProblem |
| 28 | +from unblob.report import LinkExtractionProblem, PathTraversalProblem |
29 | 29 |
|
30 | 30 |
|
31 | 31 | @pytest.mark.parametrize( |
@@ -503,6 +503,30 @@ def test_create_symlink(self, sandbox: FileSystem): |
503 | 503 | assert os.readlink(output_path) == "target file" |
504 | 504 | assert sandbox.problems == [] |
505 | 505 |
|
| 506 | + def test_create_symlink_target_inside_sandbox(self, sandbox: FileSystem): |
| 507 | + # ./sbin/shell -> ../bin/sh |
| 508 | + sandbox.mkdir(Path("bin")) |
| 509 | + sandbox.write_bytes(Path("bin/sh"), b"posix shell") |
| 510 | + sandbox.mkdir(Path("sbin")) |
| 511 | + sandbox.create_symlink(Path("../bin/sh"), Path("sbin/shell")) |
| 512 | + |
| 513 | + output_path = sandbox.root / "sbin/shell" |
| 514 | + assert output_path.read_bytes() == b"posix shell" |
| 515 | + assert output_path.exists() |
| 516 | + assert os.readlink(output_path) == "../bin/sh" |
| 517 | + assert sandbox.problems == [] |
| 518 | + |
| 519 | + def test_create_symlink_target_outside_sandbox(self, sandbox: FileSystem): |
| 520 | + # /shell -> ../bin/sh |
| 521 | + sandbox.mkdir(Path("bin")) |
| 522 | + sandbox.write_bytes(Path("bin/sh"), b"posix shell") |
| 523 | + sandbox.create_symlink(Path("../bin/sh"), Path("/shell")) |
| 524 | + |
| 525 | + assert any(p for p in sandbox.problems if isinstance(p, LinkExtractionProblem)) |
| 526 | + output_path = sandbox.root / "shell" |
| 527 | + assert not output_path.exists() |
| 528 | + assert not output_path.is_symlink() |
| 529 | + |
506 | 530 | def test_create_symlink_absolute_paths(self, sandbox: FileSystem): |
507 | 531 | sandbox.write_bytes(Path("target file"), b"test content") |
508 | 532 | sandbox.create_symlink(Path("/target file"), Path("/symlink")) |
|
0 commit comments