Skip to content

Commit d130209

Browse files
committed
Add tests to block drive-absolute path traversal on Windows
1 parent 0628a39 commit d130209

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

tests/test_server.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def test_safe_web_path_blocks_relative_traversal():
1818
assert safe_web_path("../../../../Windows/win.ini") is None
1919

2020

21+
@pytest.mark.skipif(os.name != "nt",
22+
reason="drive-absolute os.path.join discard is an "
23+
"ntpath-only quirk; on POSIX there's no drive "
24+
"letter so the path safely stays under WEB_DIR")
2125
def test_safe_web_path_blocks_windows_drive_absolute_traversal():
2226
# The bug this locks in: os.path.join(WEB_DIR, "C:/x") on Windows
2327
# discards WEB_DIR entirely because the second arg is drive-absolute.
@@ -68,6 +72,10 @@ def test_live_server_serves_data_json(live_server):
6872
assert resp.status == 200
6973

7074

75+
@pytest.mark.skipif(os.name != "nt",
76+
reason="drive-absolute os.path.join discard is an "
77+
"ntpath-only quirk; on POSIX the request just "
78+
"404s as a normal missing file under WEB_DIR")
7179
def test_live_server_rejects_drive_absolute_traversal(live_server):
7280
drive = os.path.splitdrive(WEB_DIR)[0] or "C:"
7381
with pytest.raises(urllib.error.HTTPError) as exc:

0 commit comments

Comments
 (0)