-
-
Notifications
You must be signed in to change notification settings - Fork 2
HEADERS
Part of nself Sprint 17: Advanced Security
nself provides comprehensive security headers management to protect your applications from common web vulnerabilities including XSS, clickjacking, MIME-sniffing attacks, and more.
- Quick Start
- Security Headers Explained
- Content Security Policy (CSP)
- Configuration
- CLI Commands
- Testing & Validation
- Best Practices
- Troubleshooting
nself security headers shownself security headers configurenself security headers validate https://yourdomain.comnself security headers export nginx/includes/security-headers.confPurpose: Prevents Cross-Site Scripting (XSS) attacks by controlling which resources can be loaded.
Default: Moderate mode (balanced security and compatibility)
Content-Security-Policy: default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
img-src 'self' data: https:;
font-src 'self' data:;
connect-src 'self';
object-src 'none';
base-uri 'self';
form-action 'self';
upgrade-insecure-requests
OWASP Rating: A (Critical)
Purpose: Forces browsers to use HTTPS for all future requests.
Default: max-age=31536000; includeSubDomains (1 year)
Strict-Transport-Security: max-age=31536000; includeSubDomains
OWASP Rating: A (High)
Requirements:
- Only works with HTTPS
- Recommended max-age: 1 year (31536000 seconds)
- Include subdomains for full protection
Purpose: Prevents clickjacking attacks by controlling if site can be framed.
Default: DENY (most secure)
Options:
-
DENY- Never allow framing (recommended) -
SAMEORIGIN- Allow framing from same origin only
X-Frame-Options: DENY
OWASP Rating: A (High)
Purpose: Prevents MIME-sniffing attacks.
Value: nosniff (only valid value)
X-Content-Type-Options: nosniff
OWASP Rating: B (Medium)
Purpose: Legacy XSS filter for older browsers (modern browsers use CSP).
Default: 1; mode=block
X-XSS-Protection: 1; mode=block
OWASP Rating: C (Low - legacy header)
Note: Modern browsers rely on CSP instead. Kept for older browser compatibility.
Purpose: Controls how much referrer information is included with requests.
Default: strict-origin-when-cross-origin
Options:
-
no-referrer- Never send referrer -
no-referrer-when-downgrade- Send only on HTTPS→HTTPS -
same-origin- Send only to same origin -
strict-origin- Send origin only (not full URL) -
strict-origin-when-cross-origin- Full URL same-origin, origin only cross-origin (recommended)
Referrer-Policy: strict-origin-when-cross-origin
OWASP Rating: B (Medium)
Purpose: Controls which browser features can be used (formerly Feature-Policy).
Default: Deny camera, microphone, geolocation, payment, USB, interest-cohort (FLoC)
Permissions-Policy: camera=(), microphone=(), geolocation=(),
payment=(), usb=(), interest-cohort=()
OWASP Rating: B (Medium)
Common Permissions:
-
camera- Camera access -
microphone- Microphone access -
geolocation- Location access -
payment- Payment API -
usb- USB device access -
interest-cohort- FLoC (Google's tracking, disable recommended)
Purpose: Prevents Adobe Flash and PDF from loading content from this domain.
Value: none (recommended)
X-Permitted-Cross-Domain-Policies: none
OWASP Rating: C (Low)
nself provides three CSP modes:
Use Case: Production applications, static sites Trade-off: May break some features requiring inline scripts
export CSP_MODE=strictConfiguration:
- No
unsafe-inlineorunsafe-eval - Scripts/styles only from
'self' - No external CDNs (unless whitelisted)
Use Case: Most applications (default) Trade-off: Balanced security and compatibility
export CSP_MODE=moderateConfiguration:
- Allows
unsafe-inlineandunsafe-evalfor scripts/styles - Images from
'self',data:, andhttps: - Fonts from
'self'anddata: - Connects to
'self'only (unless whitelisted)
Use Case: Development, legacy applications Trade-off: Reduced security for broader compatibility
export CSP_MODE=permissiveConfiguration:
- Allows
unsafe-inline,unsafe-eval,data:, andhttps: - More lenient with external resources
- Still blocks
objecttags and enforcesbase-uri
For fine-grained control, use custom mode:
export CSP_MODE=custom
export CSP_DEFAULT_SRC="'self'"
export CSP_SCRIPT_SRC="'self' https://trusted-cdn.com"
export CSP_STYLE_SRC="'self' 'unsafe-inline' https://fonts.googleapis.com"
export CSP_IMG_SRC="'self' data: https:"
export CSP_FONT_SRC="'self' data: https://fonts.gstatic.com"
export CSP_CONNECT_SRC="'self' https://api.example.com"
export CSP_OBJECT_SRC="'none'"
export CSP_FRAME_SRC="'none'"
export CSP_BASE_URI="'self'"
export CSP_FORM_ACTION="'self'"
export CSP_FRAME_ANCESTORS="'none'"
export CSP_UPGRADE_INSECURE_REQUESTS="true"# Add CDN domain
nself security headers csp add-domain cdn.example.com
# Add API domain
nself security headers csp add-domain api.example.com
# List whitelisted domains
nself security headers csp list-domains
# Remove domain
nself security headers csp remove-domain cdn.example.comnself automatically generates optimized CSP for known services:
Hasura GraphQL:
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
connect-src 'self' ws: wss:;
Grafana:
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
connect-src 'self' https:;
img-src 'self' data: https:;
MinIO Console:
default-src 'self';
script-src 'self' 'unsafe-inline';
connect-src 'self' ws: wss:;
img-src 'self' data: blob:;
Add to .env file:
# Security Headers Mode
SECURITY_HEADERS_MODE=strict # strict, moderate, permissive
# Content Security Policy
CSP_MODE=moderate # strict, moderate, permissive, custom
CSP_CUSTOM_DOMAINS="cdn.example.com api.example.com"
# HSTS Configuration
HSTS_MAX_AGE=31536000 # 1 year in seconds
HSTS_INCLUDE_SUBDOMAINS=true
HSTS_PRELOAD=false # Only enable if submitting to HSTS preload list
# X-Frame-Options
X_FRAME_OPTIONS=DENY # DENY or SAMEORIGIN
# Referrer-Policy
REFERRER_POLICY=strict-origin-when-cross-origin
# Permissions-Policy
PERMISSIONS_POLICY_CAMERA="()" # Deny by default
PERMISSIONS_POLICY_MICROPHONE="()"
PERMISSIONS_POLICY_GEOLOCATION="()"
PERMISSIONS_POLICY_PAYMENT="()"
PERMISSIONS_POLICY_USB="()"After updating .env:
# Export headers to nginx config
nself security headers export
# Rebuild nginx configuration
nself build --force
# Restart nginx
nself restart nginx# Show current configuration
nself security headers show
# Interactive configuration wizard
nself security headers configure
# Validate headers from running server
nself security headers validate https://yourdomain.com
# Export to nginx configuration
nself security headers export [output-file]
# Generate security headers report
nself security headers report [output-file]# Show CSP configuration
nself security headers csp show
# Configure CSP interactively
nself security headers csp configure
# Add domain to CSP whitelist
nself security headers csp add-domain cdn.example.com
# Remove domain from whitelist
nself security headers csp remove-domain cdn.example.com
# List whitelisted domains
nself security headers csp list-domains
# Validate CSP syntax
nself security headers csp validate
# Export CSP to nginx format
nself security headers csp export [mode] [output-file]# Check headers
curl -I https://yourdomain.com
# Look for security headers
curl -I https://yourdomain.com | grep -E "Content-Security-Policy|Strict-Transport-Security|X-Frame-Options"# Validate all headers
nself security headers validate https://yourdomain.com
# Security checklist (includes headers)
nself security scanMozilla Observatory: https://observatory.mozilla.org/ Comprehensive security scanner including all headers
SecurityHeaders.com: https://securityheaders.com/ Quick check for security header presence and configuration
CSP Evaluator: https://csp-evaluator.withgoogle.com/ Google's CSP validator and security analyzer
SSL Labs: https://www.ssllabs.com/ssltest/ Includes HSTS and security header checks
- Open DevTools (F12)
- Go to Network tab
- Click any request
- Look at Response Headers
- Verify security headers are present
-
Always use HTTPS in production
SSL_ENABLED=true SSL_PROVIDER=letsencrypt
-
Enable strict CSP mode
CSP_MODE=strict
-
Use DENY for X-Frame-Options
X_FRAME_OPTIONS=DENY
-
Set HSTS max-age to 1 year
HSTS_MAX_AGE=31536000 HSTS_INCLUDE_SUBDOMAINS=true
-
Validate headers before deployment
nself security headers validate https://staging.yourdomain.com
-
Use moderate or permissive CSP
CSP_MODE=moderate # or permissive for development -
Allow localhost in CSP if needed
nself security headers csp add-domain localhost
-
Test headers locally
nself security headers validate http://localhost
Start permissive, gradually tighten:
# Week 1: Permissive
CSP_MODE=permissive
# Week 2: Moderate (monitor for issues)
CSP_MODE=moderate
# Week 3+: Strict (after fixing any issues)
CSP_MODE=strict- Use CSP Report-Only mode first (TODO: add to nself)
- Monitor browser console for CSP violations
- Set up CSP reporting endpoint (TODO: add to nself)
-
Run security audits regularly
nself security scan
Symptom: Scripts, styles, or images not loading
Solution:
- Check browser console for CSP violations
- Add allowed domains:
nself security headers csp add-domain cdn.example.com
- Or temporarily use permissive mode:
CSP_MODE=permissive nself build --force
Symptom: HSTS header not present
Causes:
- SSL not enabled:
SSL_ENABLED=truerequired - Not using HTTPS: HSTS only works on HTTPS
- Not rebuilt: Run
nself build --force
Solution:
# Ensure SSL is enabled
export SSL_ENABLED=true
# Rebuild configuration
nself build --force
# Restart nginx
nself restart nginx
# Test
nself security headers validate https://yourdomain.comSymptom: Inline JavaScript not executing
Causes: Strict CSP blocks unsafe-inline
Solutions:
- Best: Move scripts to external files
- Good: Use nonces (TODO: add to nself)
-
Temporary: Use moderate mode
CSP_MODE=moderate
Symptom: Analytics, chat widgets, or other third-party tools not working
Solution: Whitelist the required domains
# Example: Google Analytics
nself security headers csp add-domain www.google-analytics.com
nself security headers csp add-domain ssl.google-analytics.com
# Example: Intercom
nself security headers csp add-domain widget.intercom.io
nself security headers csp add-domain js.intercomcdn.com
# Rebuild
nself build --forceChecklist:
- ✅ Configuration generated:
ls nginx/includes/security-headers.conf - ✅ Included in nginx:
grep security-headers nginx/conf.d/default.conf - ✅ Nginx restarted:
nself restart nginx - ✅ Testing correct URL: HTTPS vs HTTP
Symptom: Site needs to be embedded in iframe
Solution: Use SAMEORIGIN instead of DENY
export X_FRAME_OPTIONS=SAMEORIGIN
nself security headers export
nself build --forceUse this checklist for production deployments:
- CSP configured and tested
- HSTS enabled with 1-year max-age
- X-Frame-Options set to DENY or SAMEORIGIN
- X-Content-Type-Options set to nosniff
- Referrer-Policy configured
- Permissions-Policy denies unused features
- All headers validated with
nself security headers validate - Online scan passed (Mozilla Observatory, SecurityHeaders.com)
- Headers present in production
- No console errors related to CSP
- Third-party integrations working
- Site functions correctly
- SSL Labs test passed (A rating)
- Monitor logs for CSP violations
- SSL/TLS Configuration
- Firewall Configuration
- Security Checklist
- Security Audit Report (see project documentation)
OWASP Secure Headers Project: https://owasp.org/www-project-secure-headers/
MDN Web Security: https://developer.mozilla.org/en-US/docs/Web/Security
Content Security Policy Reference: https://content-security-policy.com/
HSTS Preload List: https://hstspreload.org/
Version: nself v0.9.0 Sprint: 17 - Advanced Security Last Updated: January 2026
ɳSelf CLI v1.0.9. MIT licensed. Docs CC BY 4.0.
GitHub · Issues · Discussions · nself.org · nself.org/docs
Getting Started
Commands
- Commands, Overview
- Lifecycle: cmd-init · cmd-build · cmd-start · cmd-stop · cmd-restart · cmd-dev
- Monitoring: cmd-status · cmd-logs · cmd-health · cmd-urls · cmd-doctor · cmd-monitor · cmd-alerts · cmd-sentry · cmd-watchdog
- Data: cmd-db · cmd-backup · cmd-dr · cmd-queue · cmd-webhooks
- Config: cmd-config · cmd-service · cmd-env · cmd-promote
- Networking: cmd-ssl · cmd-trust · cmd-dns-setup
- Security: cmd-access · cmd-security · cmd-secrets
- Tenancy: cmd-tenant · cmd-billing
- Plugins: cmd-plugin · cmd-license · cmd-dogfood (extracted, CLI-R11) · cmd-k8s (extracted, CLI-R11) · cmd-encryption (extracted, CLI-R11) · cmd-waf (extracted, CLI-R11) · cmd-federation (extracted, CLI-R11) · cmd-mail (extracted, CLI-R11) · cmd-dlq (extracted, CLI-R11)
- AI: cmd-ai · cmd-claw · cmd-model
- Templates: cmd-template
- Utilities: cmd-exec · cmd-clean · cmd-reset · cmd-update · cmd-upgrade · cmd-version · cmd-admin · cmd-migrate · cmd-migrate-firebase · cmd-migrate-supabase · cmd-completion
Features
- Features, Overview
- Feature-Auth
- Feature-Storage
- Feature-Search
- Feature-Functions
- Feature-Email
- Feature-Monitoring
- Feature-Plugins
- Feature-nClaw, AI Assistant
- Feature-nChat, Messaging
- Feature-nTV, Media Player
- Feature-nFamily, Family Social
- Feature-nCloud, Managed Hosting
- Feature-Memory-Rooms, Knowledge Organization
- Feature-Agent-Dashboard, Agent Metrics
- Feature-Image-Generation, AI Image Generation
Configuration
- Configuration, Overview
- Config-Env-Vars
- Config-Postgres
- Config-Hasura
- Config-Auth
- Config-Nginx
- Config-Optional-Services
- Config-Custom-Services
- Config-System
Plugins (87 + 10 monitoring)
Free (25)
- plugin-backup
- plugin-content-acquisition
- plugin-content-progress
- plugin-cron
- plugin-donorbox
- plugin-feature-flags
- plugin-github
- plugin-github-runner
- plugin-invitations
- plugin-jobs
- plugin-link-preview
- plugin-mdns
- plugin-mlflow
- plugin-monitoring
- plugin-notifications
- plugin-notify
- plugin-paypal
- plugin-search
- plugin-shopify
- plugin-stripe
- plugin-subtitle-manager
- plugin-tokens
- plugin-torrent-manager
- plugin-vpn
- plugin-webhooks
Pro (62)
- plugin-access-controls
- plugin-activity-feed
- plugin-admin-api
- plugin-nself-ai-gateway
- plugin-nself-ai-mcp
- plugin-nself-ai-mcp
- plugin-analytics
- plugin-auth
- plugin-backup-pro
- plugin-bots
- plugin-browser
- plugin-calendar
- plugin-cdn
- plugin-chat
- plugin-claw
- plugin-claw-budget
- plugin-claw-news
- plugin-claw-web
- plugin-cloudflare
- plugin-cms
- plugin-compliance
- plugin-cron-pro
- plugin-ddns
- plugin-devices
- plugin-documents
- plugin-donorbox-pro
- plugin-entitlements
- plugin-epg
- plugin-file-processing
- plugin-game-metadata
- plugin-geocoding
- plugin-geolocation
- plugin-google
- plugin-home
- plugin-idme
- plugin-knowledge-base
- plugin-linkedin
- plugin-livekit
- plugin-media-processing
- plugin-meetings
- plugin-moderation
- plugin-mux
- plugin-notify-pro
- plugin-object-storage
- plugin-observability
- plugin-paypal-pro
- plugin-photos
- plugin-podcast
- plugin-post
- plugin-realtime
- plugin-recording
- plugin-retro-gaming
- plugin-rom-discovery
- plugin-shopify-pro
- plugin-social
- plugin-sports
- plugin-stream-gateway
- plugin-streaming
- plugin-stripe-pro
- plugin-support
- plugin-tmdb
- plugin-voice
- plugin-web3
- plugin-workflows
Planned (26)
plugin-auditplugin-blogplugin-checkoutplugin-commerceplugin-drmplugin-exportplugin-flowplugin-importplugin-ldapplugin-mailgunplugin-mediaplugin-oauth-providersplugin-pagesplugin-postmarkplugin-rate-limitplugin-reportsplugin-samlplugin-schedulerplugin-sendgridplugin-ssoplugin-subscriptionplugin-thumbplugin-transcoderplugin-twilioplugin-wafplugin-watermark
Guides
- Guide-Production-Deployment
- Guide-SSL-Setup
- Guide-Multi-Tenancy
- Guide-Security-Hardening
- Guide-Monitoring-Setup
- Guide-Backup-Restore
- Guide-Custom-Services
- Guide-Migration-from-v1
Architecture
Reference
- API-Reference
- error-codes, Error Codes
Licensing
Security
Brand
Operations
- operations/release-cascade, Release Cascade
- operations/self-healing, Self-Healing Schema
- operations/redis-tuning, Redis Pool Tuning
- operations/meilisearch-warmup, MeiliSearch Warm-Up
- operations/jwt-rotation, JWT Key Rotation
- operations/windows-wsl2-setup, Windows / WSL2 Setup
- operations/gemini-oauth-reauth, Gemini OAuth Reauth
Contributing
Admin
- USER-ACTION-QUEUE, Pending Admin Actions
All commands (52)
- A: cmd-access · cmd-account · cmd-admin
- B: cmd-backup · cmd-build · cmd-bundle
- C: cmd-ci · cmd-clean · cmd-completion · cmd-config
- D: cmd-db · cmd-deploy · cmd-dev · cmd-doctor
- E: cmd-env · cmd-exec
- F: cmd-functions
- G: cmd-generate
- H: cmd-health · cmd-help-topics
- I: cmd-init · cmd-install
- L: cmd-license · cmd-login · cmd-logout · cmd-logs
- M: cmd-man · cmd-mcp · cmd-migrate
- O: cmd-oauth · cmd-ops
- P: cmd-plugin · cmd-promote
- R: cmd-remove · cmd-reset · cmd-restart · cmd-runner
- S: cmd-secrets · cmd-security · cmd-self-heal · cmd-server · cmd-service · cmd-start · cmd-status · cmd-stop
- T: cmd-telemetry · cmd-template · cmd-trust
- U: cmd-update · cmd-urls
- V: cmd-verify-sbom · cmd-version