Harden the API and the data layer after a security and performance audit
Security - Every route now requires a login and refuses ids outside the caller's workspace with 404: plan, leave-wishes, day-overrides and vacation-days were fully anonymous; every other router trusted client-supplied workspace/child/parent ids. Scraper sessions are bound to their owner. - Invitations can no longer be created for a foreign workspace, and a redeemer who is already a member (or a full workspace) is refused. - Production refuses the default JWT secret; API docs are hidden in production; a failed migration aborts startup instead of serving. - Login and register no longer reveal whether an email exists; inactive accounts are rejected; /auth/refresh is rate limited. - The FK scraper writes debug artefacts only when explicitly enabled, logs no scraped values or page text, clears the BankID QR as soon as it is scanned and purges finished sessions after five minutes. - Real FK page captures are removed from the tree (history rewrite follows); the parser tests use a synthetic fixture. Performance and correctness - Plan apply/sync run inside one locked transaction with batched writes instead of one commit per row, so a failure mid-batch leaves nothing half-applied and concurrent syncs no longer corrupt each other. - SQLite runs in WAL mode with a busy timeout; 14 indexes cover the filters that were full scans; argon2 hashing runs off the event loop; responses are gzipped. - Frontend: a 401 now refreshes the token once and retries, so sessions no longer die silently after 15 minutes; every data hook discards stale responses; logout clears state even when the server call fails. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CsXCCcDfmV4Sps4ZQSvNEY
This commit is contained in:
@@ -4,7 +4,7 @@ from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query, status
|
||||
|
||||
from app.dependencies import CurrentUserDep, PlanningServiceDep
|
||||
from app.dependencies import PlanningServiceDep, WorkspaceIdDep, WorkspaceScopeDep
|
||||
from app.models.planned_leave import (
|
||||
PlannedLeaveDayCreate,
|
||||
PlannedLeaveDayResponse,
|
||||
@@ -23,8 +23,11 @@ def _to_response(day) -> PlannedLeaveDayResponse:
|
||||
async def create_planned_day(
|
||||
payload: PlannedLeaveDayCreate,
|
||||
service: PlanningServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
scope: WorkspaceScopeDep,
|
||||
) -> PlannedLeaveDayResponse:
|
||||
scope.check_workspace(payload.workspace_id)
|
||||
await scope.check_child(payload.child_id)
|
||||
await scope.check_member(payload.parent_personal_data_uuid)
|
||||
try:
|
||||
day = await service.add_planned_day(
|
||||
workspace_id=payload.workspace_id,
|
||||
@@ -44,9 +47,10 @@ async def create_planned_day(
|
||||
@router.get("", response_model=list[PlannedLeaveDayResponse])
|
||||
async def list_planned_days(
|
||||
service: PlanningServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
scope: WorkspaceScopeDep,
|
||||
child_id: UUID = Query(...),
|
||||
) -> list[PlannedLeaveDayResponse]:
|
||||
await scope.check_child(child_id)
|
||||
days = await service.list_by_child(child_id)
|
||||
return [_to_response(d) for d in days]
|
||||
|
||||
@@ -55,10 +59,10 @@ async def list_planned_days(
|
||||
async def get_planned_day(
|
||||
planned_leave_day_id: UUID,
|
||||
service: PlanningServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
scope: WorkspaceScopeDep,
|
||||
) -> PlannedLeaveDayResponse:
|
||||
try:
|
||||
day = await service.get(planned_leave_day_id)
|
||||
day = await service.get(planned_leave_day_id, workspace_id=scope.workspace_id)
|
||||
return _to_response(day)
|
||||
except NotFoundError as exc:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|
||||
@@ -66,9 +70,8 @@ async def get_planned_day(
|
||||
|
||||
@router.get("/workspace/{workspace_id}", response_model=list[PlannedLeaveDayResponse])
|
||||
async def list_planned_days_by_workspace(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
service: PlanningServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
) -> list[PlannedLeaveDayResponse]:
|
||||
days = await service.list_by_workspace(workspace_id)
|
||||
return [_to_response(d) for d in days]
|
||||
@@ -79,7 +82,7 @@ async def update_planned_day(
|
||||
planned_leave_day_id: UUID,
|
||||
payload: PlannedLeaveDayUpdate,
|
||||
service: PlanningServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
scope: WorkspaceScopeDep,
|
||||
) -> PlannedLeaveDayResponse:
|
||||
try:
|
||||
day = await service.update(
|
||||
@@ -88,6 +91,7 @@ async def update_planned_day(
|
||||
is_dubbeldag=payload.is_dubbeldag,
|
||||
wish_id=payload.wish_id,
|
||||
is_pinned=payload.is_pinned,
|
||||
workspace_id=scope.workspace_id,
|
||||
)
|
||||
return _to_response(day)
|
||||
except NotFoundError as exc:
|
||||
@@ -98,9 +102,9 @@ async def update_planned_day(
|
||||
async def delete_planned_day(
|
||||
planned_leave_day_id: UUID,
|
||||
service: PlanningServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
scope: WorkspaceScopeDep,
|
||||
) -> None:
|
||||
try:
|
||||
await service.remove_planned_day(planned_leave_day_id)
|
||||
await service.remove_planned_day(planned_leave_day_id, workspace_id=scope.workspace_id)
|
||||
except NotFoundError as exc:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|
||||
|
||||
Reference in New Issue
Block a user