feat: implement 5 QA-driven security and quality proposals

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>
This commit is contained in:
beabigegg
2026-01-12 23:19:05 +08:00
parent df50d5e7f8
commit 35c90fe76b
48 changed files with 2132 additions and 403 deletions

View File

@@ -98,6 +98,31 @@
- **WHEN** 異常行為發生
- **THEN** 系統記錄並發送警示
### Requirement: Security Event Logging
The system SHALL record failed access attempts for security monitoring and intrusion detection.
#### Scenario: Permission denied logged
- **WHEN** server returns 403 Forbidden for a resource access attempt
- **THEN** audit log entry is created with event_type "security.access_denied"
- **AND** entry includes user_id, resource_type, and attempted_action
#### Scenario: Repeated auth failures logged
- **WHEN** same IP has 5+ failed authentication attempts in 10 minutes
- **THEN** audit log entry is created with event_type "security.suspicious_auth_pattern"
- **AND** entry includes IP address and failure count
- **AND** alert is generated for security administrators
### Requirement: Detailed Health Endpoint Security
The detailed system health endpoint SHALL require admin authentication to prevent information disclosure.
#### Scenario: Admin accesses detailed health
- **WHEN** system administrator requests GET /health/detailed
- **THEN** full system status including connection pools is returned
#### Scenario: Non-admin accesses detailed health
- **WHEN** non-admin user or unauthenticated request to GET /health/detailed
- **THEN** request is rejected with 401 Unauthorized or 403 Forbidden
## Data Model
```