|
1 | 1 | import pytest |
2 | 2 | from pathlib import Path, PurePath |
3 | 3 | from unittest.mock import patch |
4 | | -import aikido_zen.sinks.os |
| 4 | +import aikido_zen |
| 5 | +import aikido_zen.test_utils as test_utils |
| 6 | + |
| 7 | +aikido_zen.protect() |
| 8 | +from aikido_zen.context import Context |
| 9 | +from aikido_zen.errors import AikidoPathTraversal |
5 | 10 |
|
6 | 11 | kind = "path_traversal" |
7 | 12 |
|
8 | 13 |
|
| 14 | +@pytest.fixture(autouse=True) |
| 15 | +def set_blocking_to_true(monkeypatch): |
| 16 | + monkeypatch.setenv("AIKIDO_BLOCK", "1") |
| 17 | + |
| 18 | + |
9 | 19 | def test_ospath_commands(): |
10 | 20 | with patch( |
11 | 21 | "aikido_zen.vulnerabilities.run_vulnerability_scan" |
@@ -39,6 +49,36 @@ def test_ospath_commands(): |
39 | 49 | mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args) |
40 | 50 |
|
41 | 51 |
|
| 52 | +def test_os_create_path_with_multiple_slashes(): |
| 53 | + import os |
| 54 | + |
| 55 | + file_path = "////etc/passwd" |
| 56 | + test_utils.generate_and_set_context(file_path) |
| 57 | + with pytest.raises(AikidoPathTraversal): |
| 58 | + full_path = Path("flaskr/resources/blogs/") / file_path |
| 59 | + open(full_path, "r").close() |
| 60 | + |
| 61 | + |
| 62 | +def test_os_create_path_with_multiple_double_slashes(): |
| 63 | + import os |
| 64 | + |
| 65 | + file_path = "////etc//passwd" |
| 66 | + test_utils.generate_and_set_context(file_path) |
| 67 | + with pytest.raises(AikidoPathTraversal): |
| 68 | + full_path = Path("flaskr/resources/blogs/") / file_path |
| 69 | + open(full_path, "r").close() |
| 70 | + |
| 71 | + |
| 72 | +def test_os_path_traversal_with_multiple_slashes(): |
| 73 | + import os |
| 74 | + |
| 75 | + file_path = "home///..////..////my_secret.txt" |
| 76 | + test_utils.generate_and_set_context(file_path) |
| 77 | + with pytest.raises(AikidoPathTraversal): |
| 78 | + full_path = Path("flaskr/resources/blogs/") / file_path |
| 79 | + open(full_path, "r").close() |
| 80 | + |
| 81 | + |
42 | 82 | def test_ospath_command_absolute_path(): |
43 | 83 | with patch( |
44 | 84 | "aikido_zen.vulnerabilities.run_vulnerability_scan" |
|
0 commit comments