HTTPS and TLS
Reverse Proxy HTTPS Termination
GZCTF runs on HTTP internally (port 8080). Use a reverse proxy for HTTPS termination:Configure Forwarded Headers
When behind a reverse proxy, configure GZCTF to trust forwarded headers:Forwarded headers configuration (ForwardedOptions.cs:554) allows flexible proxy network configuration. The application processes these headers via
app.UseForwardedHeaders() middleware.Authentication and Authorization
Cookie Security
GZCTF uses cookie-based authentication with the following security features:- Cookie name:
GZCTF_Token - Sliding expiration: 7 days
- HttpOnly: Enabled by default
- Secure flag: Automatically set when using HTTPS
- SameSite: Configured based on environment
Password Policy
Default password requirements (configured in IdentityExtension.cs:29):- No special character requirement by default
- Unique email addresses required
- Username can contain any characters
Email Confirmation
Role-Based Access Control
GZCTF implements hierarchical role-based access control:- Admin (3): Full system access
- Monitor (1): Read-only access to monitoring features
- User (0): Standard user permissions
- Banned (-1): Blocked from accessing the platform
[RequireAdmin]- Admin only[RequireMonitor]- Admin or Monitor[RequireUser]- Any authenticated user[RequireAdminOrToken]- Admin or valid API token
API Token Authentication
GZCTF supports API tokens for programmatic access using Ed25519 signatures:- Tokens are signed with Ed25519 private keys
- Keys are stored encrypted in the database (XOR with machine key)
- Token verification uses public keys
API tokens provide an alternative authentication method for automation and integrations.
CAPTCHA Protection
Hash Proof-of-Work (Default)
Client-side computational challenge that doesn’t require external services:- 8-12: Very easy, minimal protection
- 16-20: Moderate, good for most cases
- 24-32: Difficult, strong protection
- 36-48: Very difficult, may impact user experience
Cloudflare Turnstile
Modern, privacy-focused CAPTCHA alternative:Rate Limiting
GZCTF includes comprehensive rate limiting (RateLimiter.cs:51) to prevent abuse:Global Rate Limits
- Authenticated users: 150 requests/minute with 60 queued
- Anonymous users: 150 requests/minute per IP with 60 queued
- Sliding window: 6 segments (10-second windows)
Endpoint-Specific Limits
- Registration: 20 requests per 150 seconds
- Database queries: Token bucket (100 tokens, +10 every 10s)
- Container operations: Token bucket (120 tokens, +30 every 10s)
- Flag submission: Token bucket (100 tokens, +50 every 5s)
- CAPTCHA challenges: Token bucket (40 tokens, +5 every 30s)
- Concurrency: 1 concurrent request for critical operations
Disable Rate Limiting
Database Security
Connection String Security
Docker Compose:PostgreSQL Security Best Practices
- Use strong passwords: Generate cryptographically secure passwords
- Restrict network access: Limit PostgreSQL to internal networks only
- Enable SSL/TLS: Encrypt database connections
- Regular backups: Automated, encrypted backups
- Update regularly: Keep PostgreSQL updated with security patches
Data Protection
GZCTF uses ASP.NET Core Data Protection for:- Authentication cookie encryption
- Email confirmation tokens
- Password reset tokens
- Anti-forgery tokens
DataProtectionKeys table in PostgreSQL (IdentityExtension.cs:12).
Container Security
Docker Socket Security
Mitigation strategies:- Use Kubernetes: Kubernetes provides better isolation and RBAC
- Dedicated Docker host: Run GZCTF on a dedicated Docker host
- Network isolation: Isolate challenge containers on separate networks
- Resource limits: Set CPU/memory limits on containers
Kubernetes RBAC
When using Kubernetes, GZCTF uses RBAC to limit permissions:- Dedicated namespace: Isolate challenge containers in
gzctf-challengesnamespace - Network policies: Restrict challenge container network access
- Resource quotas: Limit resources per namespace
- Pod security standards: Apply restricted pod security standards
Challenge Container Isolation
Network isolation:Storage Security
S3 Bucket Security
When using S3 storage:- Private buckets: Never make buckets public
- IAM policies: Use least-privilege IAM policies
- Encryption at rest: Enable S3 server-side encryption
- Encryption in transit: Always use HTTPS
- Access logging: Enable S3 access logs
- Versioning: Enable versioning for recovery
S3 Bucket Policy Example
Local File Storage Security
- Restrict permissions: Ensure only GZCTF process can access files
- Regular backups: Implement automated backup strategy
- Separate volume: Use dedicated volume/partition
- Disk encryption: Enable full-disk encryption
Redis Security
When using Redis:- Authentication: Always set a strong password
- Network isolation: Bind to internal network only
- Disable dangerous commands:
rename-command CONFIG ""in redis.conf - TLS encryption: Use Redis TLS for encryption in transit
Monitoring and Auditing
Enable Comprehensive Logging
Health Monitoring
Monitor the health endpoint:- Database connectivity
- Storage availability
- Redis connectivity (if configured)
Audit Logging
GZCTF logs security-relevant events:- User registration and login attempts
- Admin actions
- Flag submissions
- Container creation/deletion
- Configuration changes
- User ID
- IP address
- Action type
- Timestamp
- Success/failure status
Security Checklist
Before going to production:- HTTPS enabled with valid TLS certificate
- Strong, unique passwords for all services (database, Redis, email)
- Email confirmation enabled
- CAPTCHA configured and enabled
- Rate limiting enabled (DisableRateLimit not set)
- Forwarded headers properly configured
- Database connections encrypted (SSL mode)
- Storage backend secured (private bucket or restricted file permissions)
- Redis authentication enabled (if using Redis)
- Regular automated backups configured
- Monitoring and alerting configured
- Container isolation properly configured
- Resource limits set for challenge containers
- Security headers configured in reverse proxy
- HSTS enabled
- Regular security updates scheduled
Incident Response
Suspicious Activity
If you detect suspicious activity:- Review logs: Check application and access logs
- Identify affected accounts: Use admin panel or database queries
- Revoke sessions: Delete sessions from Redis or restart application
- Ban malicious users: Use role system to ban users
- Update credentials: Rotate database and service passwords if compromised
Data Breach
In case of a data breach:- Isolate the system: Take affected services offline
- Assess the damage: Determine what data was accessed
- Notify users: Inform affected users according to regulations
- Reset credentials: Force password reset for all users
- Review and patch: Identify and fix the vulnerability
- Monitor closely: Watch for further suspicious activity
Security Updates
Stay up to date with security patches:Reporting Security Issues
If you discover a security vulnerability in GZCTF:- Do not create a public GitHub issue
- Email the maintainers privately
- Provide detailed information about the vulnerability
- Allow time for a fix before public disclosure
Next Steps
- Configuration Reference - Detailed configuration options
- Docker Deployment - Deploy with Docker
- Kubernetes Deployment - Deploy on Kubernetes