|
2 | 2 | from pathlib import Path, PurePath |
3 | 3 | from unittest.mock import patch |
4 | 4 | import aikido_zen.sinks.os |
| 5 | +from aikido_zen.context import Context |
| 6 | +from aikido_zen.errors import AikidoPathTraversal |
| 7 | +from aikido_zen.sinks.tests.clickhouse_driver_test import set_blocking_to_true |
5 | 8 |
|
6 | 9 | kind = "path_traversal" |
7 | 10 |
|
8 | 11 |
|
| 12 | +def set_context(param): |
| 13 | + wsgi_request = { |
| 14 | + "REQUEST_METHOD": "GET", |
| 15 | + "HTTP_HEADER_1": "header 1 value", |
| 16 | + "HTTP_HEADER_2": "Header 2 value", |
| 17 | + "RANDOM_VALUE": "Random value", |
| 18 | + "HTTP_COOKIE": "sessionId=abc123xyz456;", |
| 19 | + "wsgi.url_scheme": "http", |
| 20 | + "HTTP_HOST": "localhost:8080", |
| 21 | + "PATH_INFO": "/hello", |
| 22 | + "QUERY_STRING": "user=JohnDoe&age=30&age=35", |
| 23 | + "CONTENT_TYPE": "application/json", |
| 24 | + "REMOTE_ADDR": "198.51.100.23", |
| 25 | + } |
| 26 | + context = Context( |
| 27 | + req=wsgi_request, |
| 28 | + body={ |
| 29 | + "param": param, |
| 30 | + }, |
| 31 | + source="flask", |
| 32 | + ) |
| 33 | + context.set_as_current_context() |
| 34 | + |
| 35 | + |
| 36 | +@pytest.fixture(autouse=True) |
| 37 | +def set_blocking_to_true(monkeypatch): |
| 38 | + monkeypatch.setenv("AIKIDO_BLOCK", "1") |
| 39 | + |
| 40 | + |
9 | 41 | def test_ospath_commands(): |
10 | 42 | with patch( |
11 | 43 | "aikido_zen.vulnerabilities.run_vulnerability_scan" |
@@ -39,6 +71,16 @@ def test_ospath_commands(): |
39 | 71 | mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args) |
40 | 72 |
|
41 | 73 |
|
| 74 | +def test_os_create_path_with_multiple_slashes(): |
| 75 | + import os |
| 76 | + |
| 77 | + file_path = "////etc/passwd" |
| 78 | + set_context(file_path) |
| 79 | + with pytest.raises(AikidoPathTraversal): |
| 80 | + full_path = Path("flaskr/resources/blogs/") / file_path |
| 81 | + open(full_path, "r").close() |
| 82 | + |
| 83 | + |
42 | 84 | def test_ospath_command_absolute_path(): |
43 | 85 | with patch( |
44 | 86 | "aikido_zen.vulnerabilities.run_vulnerability_scan" |
|
0 commit comments