Overview
Security misconfiguration occurs when security settings are not defined, implemented, or maintained properly. In this demo, the vulnerable version lacks critical security headers, uses a hardcoded secret key, potentially runs with debug mode enabled, and misses other important security configurations that protect against various attacks.Severity Rating
MEDIUM to HIGH - CVSS Score: 7.0/10CWE Reference: CWE-16: Configuration, CWE-209: Information Exposure Through Error Messages
Vulnerable Configurations
The vulnerable version has multiple configuration issues:Security Header Vulnerabilities
1. Missing Content-Security-Policy (CSP)
1. Missing Content-Security-Policy (CSP)
Risk: Allows XSS attacks and malicious script executionMissing Header:Impact Without CSP:Allowed Attacks:
- Inline script execution
- External script loading
- eval() and similar functions
- Inline event handlers (onclick, onerror)
2. Missing X-Frame-Options
2. Missing X-Frame-Options
Risk: Enables clickjacking attacksMissing Header:Clickjacking Attack:Result: User thinks they’re clicking “FREE PRIZE” but actually clicking “Delete Account”
3. Missing X-Content-Type-Options
3. Missing X-Content-Type-Options
Risk: Allows MIME type sniffing attacksMissing Header:Attack Scenario:Exploitation:
- Attacker uploads file named
image.jpgcontaining JavaScript: - Victim visits:
/uploads/image.jpg - Without
nosniff, browser detects JavaScript and executes it - With
nosniff, browser respects Content-Type header and treats as image
4. Missing Strict-Transport-Security (HSTS)
4. Missing Strict-Transport-Security (HSTS)
Risk: Allows man-in-the-middle attacks via SSL strippingMissing Header:Attack - SSL Stripping:
- User types
auth-vulnerable.onrender.com(no https://) - Browser makes HTTP request
- Attacker intercepts and proxies connection
- Attacker downgrades to HTTP
- User sees HTTP site, no warning
- Credentials transmitted in plaintext
5. Missing X-XSS-Protection
5. Missing X-XSS-Protection
Risk: Disables browser’s built-in XSS filterMissing Header:Note: Modern browsers rely on CSP instead, but this provides defense-in-depth for older browsers
6. Missing Referrer-Policy
6. Missing Referrer-Policy
Risk: Leaks sensitive information in Referer headerMissing Header:Information Leak:
Error Information Disclosure
- Vulnerable: SQL Errors
- Vulnerable: Stack Traces
- Vulnerable: Version Disclosure
Secure Implementation
The secure version implements comprehensive security headers and configurations:Security Configuration Checklist
Testing Security Configuration
- Security Headers
- SSL/TLS Configuration
- Information Disclosure
- Automated Scanning
Production Deployment Checklist
- Secrets: All secrets in environment variables, not code
- Debug Mode: Debug disabled (
DEBUG=False) - HTTPS: SSL/TLS certificate configured, HSTS enabled
- Security Headers: All headers configured
- Error Handling: Generic error messages, detailed logging
- Rate Limiting: Implemented on sensitive endpoints
- CSRF Protection: Enabled and tested
- Session Security: Secure, HttpOnly, SameSite cookies
- Dependencies: All packages updated, no known vulnerabilities
- File Permissions: Restricted (no world-readable secrets)
- Database: Least privilege user, encrypted connections
- Logging: Centralized, no sensitive data logged
- Monitoring: Error tracking, security event monitoring
- Backups: Automated, encrypted, tested
- WAF: Web Application Firewall configured (if applicable)
Compliance & Standards
OWASP Top 10
A05:2021 – Security MisconfigurationRanked #5 most critical web application security riskIncludes:
- Missing security hardening
- Unnecessary features enabled
- Default accounts/passwords
- Error handling reveals stack traces
- Outdated software
PCI-DSS
Requirement 6.5: Secure developmentRequirement 6.6: Web application firewall or code reviewRequirement 10: Log and monitor all access
NIST Cybersecurity Framework
PR.DS-1: Data-at-rest is protectedPR.DS-2: Data-in-transit is protectedDE.CM-1: Network monitored for anomalies
CIS Controls
Control 3: Data ProtectionControl 14: Security Awareness TrainingControl 18: Application Software Security
References
- OWASP Secure Headers Project
- Mozilla Web Security Guidelines
- CWE-16: Configuration
- Flask Security Considerations
- SecurityHeaders.com
Next Steps
Related security topics:
- XSS - Content-Security-Policy helps prevent
- Session Management - Cookie security flags
- Sensitive Data Exposure - Protecting sensitive information