Implement: Robust API Security Measures (Phase 1) #14

Merged
crisleo94 merged 1 commits from feature/api-security-phase-1 into main 2026-05-29 02:20:06 +00:00
Owner

Implements API Security Phase 1 (Issue #7).

Changes

Backend

  • Short-lived JWT: access 15min, refresh 7d, rotation + blacklisting via rest_framework_simplejwt.token_blacklist
  • Role-based access: is_admin property checks Django groups; ownership filtering on JobApplication/JobUpdate views
  • Rate limiting: UserRateThrottle (60/min) + AuthRateThrottle (5/min on login/register)
  • Input sanitization: SanitizedCharField strips control chars and null bytes across all serializers
  • Password validation: Django's built-in validators (min length 8, no common/numeric-only)
  • Custom exception handler: suppresses stack traces, consistent {error, code} format
  • Security middleware: HSTS, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy headers
  • User ownership: JobApplication.user FK with unique constraint on (user, company, position)
  • New endpoints: POST /api/auth/logout/, POST /api/auth/token/refresh/ (with rotation), GET /api/auth/me/

Frontend

  • Token refresh interceptor: Axios response interceptor auto-refreshes on 401
  • Protected routes: <ProtectedRoute> and <PublicRoute> components in App.tsx
  • Auth initialization: checks refresh token on mount, fetches profile
  • Backend logout: calls POST /api/auth/logout/ to blacklist refresh token
  • Logout button: Sign Out button in AppBar

Documentation

  • docs/backend/api-security-phase-1.md — full spec covering all changes
Implements API Security Phase 1 (Issue #7). ## Changes ### Backend - **Short-lived JWT**: access 15min, refresh 7d, rotation + blacklisting via `rest_framework_simplejwt.token_blacklist` - **Role-based access**: `is_admin` property checks Django groups; ownership filtering on JobApplication/JobUpdate views - **Rate limiting**: `UserRateThrottle` (60/min) + `AuthRateThrottle` (5/min on login/register) - **Input sanitization**: `SanitizedCharField` strips control chars and null bytes across all serializers - **Password validation**: Django's built-in validators (min length 8, no common/numeric-only) - **Custom exception handler**: suppresses stack traces, consistent `{error, code}` format - **Security middleware**: HSTS, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy headers - **User ownership**: `JobApplication.user` FK with unique constraint on (user, company, position) - **New endpoints**: `POST /api/auth/logout/`, `POST /api/auth/token/refresh/` (with rotation), `GET /api/auth/me/` ### Frontend - **Token refresh interceptor**: Axios response interceptor auto-refreshes on 401 - **Protected routes**: `<ProtectedRoute>` and `<PublicRoute>` components in App.tsx - **Auth initialization**: checks refresh token on mount, fetches profile - **Backend logout**: calls `POST /api/auth/logout/` to blacklist refresh token - **Logout button**: Sign Out button in AppBar ### Documentation - `docs/backend/api-security-phase-1.md` — full spec covering all changes
marko added 1 commit 2026-05-27 00:24:18 +00:00
crisleo94 merged commit 7dde10b7ec into main 2026-05-29 02:20:06 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: HermesFactory/job-tracker#14