Comprehensive HTTP security headers for admin interfaces and proxy operations
The security headers middleware provides comprehensive HTTP security headers to protect against common web vulnerabilities while maintaining optimal functionality for both administrative interfaces and proxy operations.
Key Features: Two-tier security model, CORS support, CSP policies, and comprehensive protection headers.
Applied to administrative endpoints with enhanced protections
Applied to proxy operations for Microsoft compatibility
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
img-src 'self' data: https:;
connect-src 'self' wss: ws:;
frame-ancestors 'none';
base-uri 'self'
default-src 'self' *.microsoft.com *.microsoftonline.com *.live.com;
script-src 'self' 'unsafe-inline' 'unsafe-eval' *.microsoft.com *.microsoftonline.com;
style-src 'self' 'unsafe-inline' *.microsoft.com *.microsoftonline.com;
img-src 'self' data: https: *.microsoft.com *.microsoftonline.com;
connect-src 'self' wss: ws: *.microsoft.com *.microsoftonline.com;
frame-ancestors 'self';
base-uri 'self'
SAMEORIGIN
Prevents clickjacking attacks
nosniff
Prevents MIME type confusion
1; mode=block
Enables XSS filtering
strict-origin-when-cross-origin
Controls referrer disclosure
max-age=31536000; includeSubDomains
Enforces HTTPS connections
camera=(), microphone=(), ...
Disables dangerous features
CORS credentials are enabled with 24-hour cache (86400 seconds) for authenticated requests.
// Applied to all requests via middleware wrapper
secureMux := http.NewServeMux()
secureMux.Handle("/", utils.SecurityHeaders(mux))
func isAdminEndpoint(path string) bool {
adminPaths := []string{"/admin/", "/ws", "/logs/", "/api/admin/",
"/fleet/", "/vps/", "/api/metrics/", "/api/security/"}
// Path prefix matching logic
}
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
Clickjacking Prevention
Frame ancestors restrictions
XSS Mitigation
Script source controls
CSRF Protection
Referrer policy and CORS controls
Microsoft Domain Support
Allows legitimate Microsoft resources
Embedding Capability
Supports iframe embedding
Resource Loading
Permits necessary external resources
curl -I https://your-domain.com/admin/