Implemented proposals from comprehensive QA review: 1. extend-csrf-protection - Add POST to CSRF protected methods in frontend - Global CSRF middleware for all state-changing operations - Update tests with CSRF token fixtures 2. tighten-cors-websocket-security - Replace wildcard CORS with explicit method/header lists - Disable query parameter auth in production (code 4002) - Add per-user WebSocket connection limit (max 5, code 4005) 3. shorten-jwt-expiry - Reduce JWT expiry from 7 days to 60 minutes - Add refresh token support with 7-day expiry - Implement token rotation on refresh - Frontend auto-refresh when token near expiry (<5 min) 4. fix-frontend-quality - Add React.lazy() code splitting for all pages - Fix useCallback dependency arrays (Dashboard, Comments) - Add localStorage data validation in AuthContext - Complete i18n for AttachmentUpload component 5. enhance-backend-validation - Add SecurityAuditMiddleware for access denied logging - Add ErrorSanitizerMiddleware for production error messages - Protect /health/detailed with admin authentication - Add input length validation (comment 5000, desc 10000) All 521 backend tests passing. Frontend builds successfully. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
email: str = Field(..., max_length=255)
|
|
password: str = Field(..., min_length=1, max_length=128)
|
|
|
|
|
|
class LoginResponse(BaseModel):
|
|
access_token: str
|
|
refresh_token: str
|
|
token_type: str = "bearer"
|
|
expires_in: int = Field(default=3600, description="Access token expiry in seconds")
|
|
user: "UserInfo"
|
|
|
|
|
|
class RefreshTokenRequest(BaseModel):
|
|
"""Request body for refresh token endpoint."""
|
|
refresh_token: str = Field(..., description="The refresh token to use for obtaining a new access token")
|
|
|
|
|
|
class RefreshTokenResponse(BaseModel):
|
|
"""Response for refresh token endpoint."""
|
|
access_token: str
|
|
refresh_token: str # New refresh token (rotation)
|
|
token_type: str = "bearer"
|
|
expires_in: int = Field(default=3600, description="Access token expiry in seconds")
|
|
|
|
|
|
class UserInfo(BaseModel):
|
|
id: str
|
|
email: str
|
|
name: str
|
|
role: Optional[str] = None
|
|
department_id: Optional[str] = None
|
|
is_system_admin: bool = False
|
|
|
|
|
|
class TokenPayload(BaseModel):
|
|
sub: str
|
|
email: str
|
|
role: Optional[str] = None
|
|
department_id: Optional[str] = None
|
|
is_system_admin: bool = False
|
|
exp: int
|
|
iat: int
|
|
|
|
|
|
class CSRFTokenResponse(BaseModel):
|
|
"""Response containing a CSRF token for state-changing operations."""
|
|
csrf_token: str = Field(..., description="CSRF token to include in X-CSRF-Token header")
|
|
expires_in: int = Field(default=3600, description="Token expiry time in seconds")
|
|
|
|
|
|
# Update forward reference
|
|
LoginResponse.model_rebuild()
|