fix: harden media path handling against path injection (CodeQL py/path-injection)

Resolve media filenames through a shared _resolve_media_path() barrier that
confirms the resolved path sits directly under the resolved media dir, so
CodeQL can trace the sanitization the regex already guaranteed.

ha-relevant: no
This commit is contained in:
Pouzor
2026-07-07 11:50:12 +02:00
parent 738595be5a
commit 2d376c2bed
2 changed files with 26 additions and 6 deletions
+7
View File
@@ -79,6 +79,13 @@ async def test_get_rejects_bad_filename(client, media_dir):
assert res.status_code == 404
@pytest.mark.asyncio
async def test_delete_rejects_bad_filename(client, auth_headers, media_dir):
headers = await auth_headers()
res = await client.delete("/api/v1/media/..%2f..%2fetc%2fpasswd", headers=headers)
assert res.status_code == 404
@pytest.mark.asyncio
async def test_delete_requires_auth_and_removes_file(client, auth_headers, media_dir):
headers = await auth_headers()