- Login-Rate-Limit (5 pro Benutzername, 20 pro IP in 15 Minuten), in SQLite gespeichert - Audit-Log für Login, Fehlversuche, Logout und alle Änderungen an Verbindungen; fremde private Einträge bleiben verborgen; API /api/audit und Ansicht im Frontend - scripts/backup.sh: konsistente Kopie per SQLite-Backup-API, Integritätsprüfung, gzip, Rechte 600, Aufräumen nach N Tagen - Tests für Rate-Limit und Audit-Log, SETUP.md ergänzt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""FastAPI-Einstieg."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from .config import PROJEKT_ROOT
|
|
from .db import init_db
|
|
from .routes import audit_routes, auth_routes, connections
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_app: FastAPI):
|
|
init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="it-connect", lifespan=lifespan, docs_url=None, redoc_url=None)
|
|
|
|
|
|
@app.middleware("http")
|
|
async def sicherheits_header(request, call_next):
|
|
response = await call_next(request)
|
|
response.headers.setdefault("X-Content-Type-Options", "nosniff")
|
|
response.headers.setdefault("X-Frame-Options", "DENY")
|
|
response.headers.setdefault("Referrer-Policy", "no-referrer")
|
|
response.headers.setdefault(
|
|
"Content-Security-Policy",
|
|
"default-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'",
|
|
)
|
|
return response
|
|
|
|
|
|
app.include_router(auth_routes.router)
|
|
app.include_router(connections.router)
|
|
app.include_router(audit_routes.router)
|
|
|
|
# Frontend zuletzt einhängen, damit /api/* Vorrang hat
|
|
app.mount("/", StaticFiles(directory=PROJEKT_ROOT / "frontend", html=True), name="frontend")
|