docs(security): update with custom login page and redirect validation

- Add environment table (Production/Staging URLs with TRUST_PROXY)
- Document browser form redirect with safe URL validation
- Add Open Redirect Prevention details
- Document custom admin login page (src/app/(payload)/admin/login/)
- Add file reference table for all security-related files
- Update changelog with 18.12.2025 entry

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Martin Porwoll 2025-12-18 16:06:09 +00:00
parent ba0f37a5b2
commit 624b3dc605

View file

@ -1,11 +1,18 @@
# Security-Richtlinien - Payload CMS Multi-Tenant
> Letzte Aktualisierung: 17.12.2025
> Letzte Aktualisierung: 18.12.2025
## Übersicht
Dieses Dokument beschreibt die implementierten Sicherheitsmaßnahmen für das Payload CMS Multi-Tenant-Projekt.
**Umgebungen:**
| Umgebung | URL | TRUST_PROXY |
|----------|-----|-------------|
| Production | https://cms.c2sgmbh.de | `true` (Nginx) |
| Staging | https://pl.porwoll.tech | `true` (Caddy) |
---
## Security-Module
@ -289,16 +296,48 @@ Das Admin Panel verwendet eine Custom Login Route (`src/app/(payload)/api/users/
- **Audit-Logging:** Jeder Login-Versuch wird in AuditLogs protokolliert
- **Rate-Limiting:** 5 Versuche pro 15 Minuten (authLimiter)
- **Browser-Redirect:** Sichere Weiterleitung nach erfolgreichem Login
- **Content-Type Support:**
- JSON (`application/json`)
- FormData mit `_payload` JSON-Feld (Payload Admin Panel Format)
- Standard FormData (`multipart/form-data`)
- URL-encoded (`application/x-www-form-urlencoded`)
**Browser Form Redirect:**
```
POST /api/users/login?redirect=/admin/collections/posts
Content-Type: application/x-www-form-urlencoded
email=admin@example.com&password=secret
```
**Redirect-Validierung:**
- Nur relative Pfade erlaubt (`/admin/...`)
- Externe URLs werden blockiert
- Protocol-Handler (`javascript:`, `data:`) abgelehnt
- Default: `/admin` bei fehlendem/ungültigem Redirect
**Sicherheitsaspekte:**
- Passwort wird nie in Logs/Responses exponiert
- Fehlgeschlagene Login-Versuche werden mit IP und User-Agent geloggt
- Rate-Limiting verhindert Brute-Force-Angriffe
- Open Redirect Prevention durch URL-Validierung
### Custom Admin Login Page
Eine optionale Custom Login-Seite ist verfügbar unter `src/app/(payload)/admin/login/`:
```
src/app/(payload)/admin/login/
├── page.tsx # Login-Formular mit Styling
└── page.module.scss # Custom Styles
```
**Features:**
- Styled Login-Form passend zum Admin-Theme
- Redirect-Parameter Support (`?redirect=/admin/...`)
- Fehlerbehandlung mit User-Feedback
- Kompatibel mit Payload's Session-Management
---
@ -306,8 +345,26 @@ Das Admin Panel verwendet eine Custom Login Route (`src/app/(payload)/api/users/
| Datum | Änderung |
|-------|----------|
| 18.12.2025 | **Custom Admin Login Page:** Styled Login-Formular, Browser-Redirect mit Safe-URL-Validierung, Open Redirect Prevention |
| 17.12.2025 | **Security-Audit Fixes:** TRUST_PROXY für IP-Header-Spoofing, CSRF_SECRET Pflicht in Production, IP-Allowlist Startup-Warnungen, Tests auf 177 erweitert |
| 09.12.2025 | Custom Login Route Dokumentation, multipart/form-data _payload Support |
| 08.12.2025 | Security Test Suite (143 Tests) |
| 07.12.2025 | Rate Limiter, CSRF, IP Allowlist, Data Masking |
| 07.12.2025 | Pre-Commit Hook, GitHub Actions Workflow |
---
## Dateien
| Pfad | Beschreibung |
|------|--------------|
| `src/lib/security/rate-limiter.ts` | Rate Limiting mit Redis/Memory |
| `src/lib/security/ip-allowlist.ts` | IP-basierte Zugriffskontrolle |
| `src/lib/security/csrf.ts` | CSRF Token Generation & Validation |
| `src/lib/security/data-masking.ts` | Sensitive Data Masking |
| `src/app/(payload)/api/users/login/route.ts` | Custom Login API |
| `src/app/(payload)/admin/login/page.tsx` | Custom Login Page |
| `scripts/detect-secrets.sh` | Pre-Commit Secret Detection |
| `.github/workflows/security.yml` | CI Security Scanning |
| `tests/unit/security/` | Security Unit Tests |
| `tests/int/security-api.int.spec.ts` | Security Integration Tests |