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,12 @@ from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from app.dependencies import CurrentUserDep, WorkspaceServiceDep
|
||||
from app.dependencies import (
|
||||
CurrentUserDep,
|
||||
CurrentWorkspaceIdDep,
|
||||
WorkspaceIdDep,
|
||||
WorkspaceServiceDep,
|
||||
)
|
||||
from app.entities.personal_data import PersonalData
|
||||
from app.models.workspace import (
|
||||
InvitationResponse,
|
||||
@@ -62,9 +67,8 @@ async def create_workspace(
|
||||
|
||||
@router.get("/{workspace_id}", response_model=WorkspaceResponse)
|
||||
async def get_workspace(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
service: WorkspaceServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
) -> WorkspaceResponse:
|
||||
try:
|
||||
ws = await service.get_workspace(workspace_id)
|
||||
@@ -75,10 +79,9 @@ async def get_workspace(
|
||||
|
||||
@router.put("/{workspace_id}", response_model=WorkspaceResponse)
|
||||
async def update_workspace(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
payload: WorkspaceUpdate,
|
||||
service: WorkspaceServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
) -> WorkspaceResponse:
|
||||
try:
|
||||
ws = await service.update_workspace(workspace_id, payload.name, payload.planning_mode)
|
||||
@@ -94,9 +97,8 @@ async def update_workspace(
|
||||
|
||||
@router.get("/{workspace_id}/members", response_model=list[PersonalDataResponse])
|
||||
async def list_members(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
service: WorkspaceServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
) -> list[PersonalDataResponse]:
|
||||
members = await service.list_members(workspace_id)
|
||||
return [_to_response(m) for m in members]
|
||||
@@ -108,10 +110,9 @@ async def list_members(
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
)
|
||||
async def add_placeholder_parent(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
payload: PersonalDataCreate,
|
||||
service: WorkspaceServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
) -> PersonalDataResponse:
|
||||
try:
|
||||
pd = await service.add_placeholder_parent(workspace_id, payload.display_name)
|
||||
@@ -125,11 +126,10 @@ async def add_placeholder_parent(
|
||||
response_model=PersonalDataResponse,
|
||||
)
|
||||
async def rename_parent(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
personal_data_uuid: UUID,
|
||||
payload: PersonalDataCreate,
|
||||
service: WorkspaceServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
) -> PersonalDataResponse:
|
||||
try:
|
||||
pd = await service.rename_member(workspace_id, personal_data_uuid, payload.display_name)
|
||||
@@ -143,7 +143,7 @@ async def rename_parent(
|
||||
status_code=status.HTTP_204_NO_CONTENT,
|
||||
)
|
||||
async def remove_parent(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
personal_data_uuid: UUID,
|
||||
service: WorkspaceServiceDep,
|
||||
current_user: CurrentUserDep,
|
||||
@@ -162,7 +162,7 @@ async def remove_parent(
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
)
|
||||
async def create_invitation(
|
||||
workspace_id: UUID,
|
||||
workspace_id: WorkspaceIdDep,
|
||||
service: WorkspaceServiceDep,
|
||||
current_user: CurrentUserDep,
|
||||
) -> InviteResponse:
|
||||
@@ -194,10 +194,10 @@ async def redeem_invitation(
|
||||
async def revoke_invitation(
|
||||
invitation_id: UUID,
|
||||
service: WorkspaceServiceDep,
|
||||
_current_user: CurrentUserDep,
|
||||
workspace_id: CurrentWorkspaceIdDep,
|
||||
) -> None:
|
||||
try:
|
||||
await service.revoke_invitation(invitation_id)
|
||||
await service.revoke_invitation(invitation_id, workspace_id)
|
||||
except (NotFoundError, ValidationError) as exc:
|
||||
code = (
|
||||
status.HTTP_404_NOT_FOUND
|
||||
|
||||
Reference in New Issue
Block a user