Core Security Features
Framefox’s security architecture includes:- Authentication & Authorization: Multiple authentication methods with role-based access control
- CSRF Protection: Automatic token generation and validation for form submissions
- XSS Prevention: Input validation and output encoding to prevent cross-site scripting
- SQL Injection Protection: Context-aware input sanitization and validation
- Rate Limiting: Protection against DDoS and brute force attacks
- Security Headers: Automatic application of security headers based on environment
- Session Management: Secure session handling with JWT tokens
- Brute Force Protection: Progressive delays and blocking for suspicious login attempts
Security Architecture
The security system is orchestrated by theFirewallHandler which manages all incoming requests:
/home/daytona/workspace/source/framefox/core/security/handlers/firewall_handler.py:50
CSRF Protection
Framefox automatically protects against Cross-Site Request Forgery attacks:How It Works
- CSRF tokens are automatically generated for each session
- Tokens are validated on form submissions (POST, PUT, PATCH)
- Invalid tokens are rejected with a security error
In Templates
Use thecsrf_token() function in your forms:
Token Validation
TheCsrfTokenBadge class handles validation using constant-time comparison:
/home/daytona/workspace/source/framefox/core/security/passport/csrf_token_badge.py:32
XSS Prevention
Framefox provides multiple layers of XSS protection:Input Validation
TheInputValidationProtector automatically sanitizes user input:
/home/daytona/workspace/source/framefox/core/security/protector/input_validation_protector.py:71
Context-Aware Validation
The protector uses different validation rules based on context:- form: Full XSS and SQL injection checks
- json: Structured data validation
- html_content: Allows safe HTML for rich text
- search: Removes special characters
- file: Path traversal protection
Security Headers
Framefox automatically applies security headers:/home/daytona/workspace/source/framefox/core/security/protector/security_headers_protector.py:33
Access Control
Framefox implements role-based access control (RBAC):Configuring Access Rules
How It Works
TheAccessManager evaluates access rules:
/home/daytona/workspace/source/framefox/core/security/access_manager.py:56
Rate Limiting & Protection
Framefox includes multiple protection mechanisms:Rate Limiting
Protects against DDoS and excessive requests:/home/daytona/workspace/source/framefox/core/security/protector/rate_limiting_protector.py:35
Brute Force Protection
Protects login endpoints:- Progressive delays after failed attempts
- IP-based blocking (25 attempts/hour)
- Account locking (15 attempts/hour)
- Automatic cleanup of old attempts
/home/daytona/workspace/source/framefox/core/security/protector/brute_force_protector.py:39
Security Best Practices
1. Always Use CSRF Protection
2. Validate and Sanitize Input
3. Use Role-Based Access Control
4. Enable Security Headers
5. Use Strong Password Hashing
6. Implement Proper Logout
Environment-Based Security
Framefox adjusts security based on your environment:Development (APP_ENV=dev)
- Lenient CSP policies for hot-reload
- Allows localhost connections
- SAMEORIGIN frame policy
- Cross-origin resource sharing enabled
Production (APP_ENV=prod)
- Strict CSP policies
- DENY frame policy
- HTTPS enforcement with HSTS
- Same-origin resource policy
- No inline scripts or eval
/home/daytona/workspace/source/framefox/core/security/protector/security_headers_protector.py:27
Next Steps
Authentication
Learn about user authentication and session management
CSRF Protection
Detailed guide to CSRF token handling
User Management
User models, providers, and role management