Inventario implements multiple layers of security following Django best practices. This guide covers the security features and configuration requirements.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/margnes22/inventario-render/llms.txt
Use this file to discover all available pages before exploring further.
SECRET_KEY Management
TheSECRET_KEY is Django’s most critical security setting. It’s used for:
- Cryptographic signing of sessions
- CSRF token generation
- Password reset tokens
- Signed cookies and data
Configuration
Best Practices
- Never commit
SECRET_KEYto version control - Rotate regularly (requires re-issuing sessions)
- Store securely in environment variables only
- Use different keys for different environments
- Keep secret - anyone with the key can forge signatures
SECRET_KEY is compromised:
- Generate a new key immediately
- Update environment variables in all environments
- Restart all application instances
- All users will be logged out (sessions invalidated)
- All password reset tokens will be invalidated
CSRF Protection
Cross-Site Request Forgery (CSRF) protection is enabled by default and configured for production use.Middleware
Cookie Configuration
CSRF_COOKIE_SAMESITE = 'Lax': Allows CSRF cookie on top-level navigationCSRF_COOKIE_SECURE = True: Requires HTTPS for CSRF cookie (production only)
Trusted Origins
For HTTPS deployments, configure trusted origins:CSRF Token Usage
In templates, include CSRF token in all forms:Session Security
Session cookies are secured based on theDEBUG setting.
Session Cookie Configuration
SESSION_COOKIE_SAMESITE = 'Lax': Prevents CSRF while allowing normal navigationSESSION_COOKIE_SECURE = True: Requires HTTPS for session cookies (production)
Session Management
- Stores session data server-side (database)
- Only session ID is stored in cookie
- Session ID is cryptographically signed with
SECRET_KEY - Sessions expire on browser close by default
Custom Middleware
Password Validation
Inventario uses custom password validators for enhanced security.Custom Validators
- LongitudMinimaValidator: Enforces minimum password length
- ContraseñaComunValidator: Rejects common passwords
- ContraseñaNumericaValidator: Prevents fully numeric passwords
applications/cuentas/validators.py.
Password Storage
Django uses PBKDF2 algorithm with SHA256 hash by default:- Passwords are never stored in plain text
- Uses key stretching (320,000 iterations as of Django 5.2)
- Salted to prevent rainbow table attacks
- Automatically upgraded when algorithms improve
HTTPS Configuration
Security Middleware
HTTPS-Only Cookies
In production (DEBUG=False):
Protocol Configuration
Clickjacking Protection
X-Frame-Options: DENY header.
Authentication Security
Custom User Model
Authentication Backends
- OAuth via django-allauth: Google Sign-In
- Model backend: Traditional username/password
OAuth Configuration
Google OAuth 2.0 settings:Email Verification
Database Security
Connection String Security
DATABASE_URL environment variable:
Connection Pooling
conn_max_age=600: Keeps database connections open for 10 minutes, improving performance while limiting connection count.
API Key Security
Inventario integrates with external services requiring API keys.Secure Storage
All API keys are stored in environment variables:Rotation Strategy
- Regular rotation: Rotate API keys every 90 days
- Immediate rotation if compromised
- Monitor usage: Check for unusual API usage patterns
- Scope limits: Use minimal required permissions
Production Security Checklist
Before deploying to production:Critical Settings
-
DEBUG=False(never run production with DEBUG=True) - Strong
SECRET_KEYgenerated and secured -
ALLOWED_HOSTSconfigured with exact domains -
CSRF_TRUSTED_ORIGINSset with HTTPS URLs -
SESSION_COOKIE_SECURE=True(automatic when DEBUG=False) -
CSRF_COOKIE_SECURE=True(automatic when DEBUG=False)
Authentication
- Google OAuth credentials configured
- OAuth redirect URIs registered in Google Cloud Console
- Consider enabling email verification (
ACCOUNT_EMAIL_VERIFICATION='mandatory') - Password validators tested and documented for users
Infrastructure
- HTTPS enabled and enforced
- Database credentials secured in environment variables
- PostgreSQL configured (not SQLite)
- All API keys stored in environment variables
-
.envfile added to.gitignore
Monitoring
- Error tracking configured (Sentry, etc.)
- Log authentication failures
- Monitor API usage and rate limits
- Set up alerts for security events
Updates
- Dependencies up to date (check
requirements.txt) - Security patches applied
- Django security releases monitored
Security Headers
Consider adding these security headers viaSecurityMiddleware settings:
- Force HTTPS connections (HSTS)
- Prevent XSS attacks
- Prevent MIME type sniffing
- Redirect HTTP to HTTPS
Incident Response
If a security incident occurs:- Immediate: Rotate
SECRET_KEYand affected API keys - Investigate: Check logs for unauthorized access
- Notify: Inform affected users if data was compromised
- Patch: Fix the vulnerability
- Deploy: Push updates to production immediately
- Document: Record the incident and response
- Review: Update security practices to prevent recurrence