fix: Upload-Sanitizing, atomare Import-Reihenfolge, idempotentes UNBEKANNT-Konto

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 18:28:15 +02:00
parent 19d870cf20
commit 8ca563cec1
4 changed files with 47 additions and 10 deletions

View File

@@ -46,3 +46,28 @@ def test_upload_preview_confirm(client, fake_parse, tmp_path, monkeypatch):
assert prev2["duplicates"] == 1
client.post(f"/api/imports/{sid2}/confirm", headers=H)
assert len(client.get("/api/transactions", headers=H).json()) == 1
def test_upload_sanitizes_path_traversal_filename(client, fake_parse, tmp_path, monkeypatch):
monkeypatch.setenv("FB_INBOX_DIR", str(tmp_path / "inbox"))
monkeypatch.setenv("FB_UPLOADS_DIR", str(tmp_path / "uploads"))
from app.config import get_settings
get_settings.cache_clear()
r = client.post("/api/imports/upload", headers=H,
files={"file": ("../evil.pdf", b"%PDF-fake", "application/pdf")})
assert r.status_code == 201
# Der Dateiname darf keine Pfad-Anteile aus dem Client uebernehmen: nur
# der Basisname landet im Uploads-Verzeichnis, nichts entkommt nach oben.
assert not (tmp_path / "evil.pdf").exists()
assert (tmp_path / "uploads" / "evil.pdf").exists()
assert not (tmp_path / "inbox" / "evil.pdf").exists()
def test_upload_rejects_non_pdf(client, tmp_path, monkeypatch):
monkeypatch.setenv("FB_INBOX_DIR", str(tmp_path / "inbox"))
monkeypatch.setenv("FB_UPLOADS_DIR", str(tmp_path / "uploads"))
from app.config import get_settings
get_settings.cache_clear()
r = client.post("/api/imports/upload", headers=H,
files={"file": ("x.txt", b"not a pdf", "text/plain")})
assert r.status_code == 400